@nevermined-io/sdk - v3.0.44 / NvmApp
Represents the NvmApp class which is the main entry point for interacting with the Nevermined SDK.
• new NvmApp(config
): NvmApp
Represents the NvmApp class.
Name | Type | Description |
---|---|---|
config |
NeverminedAppOptions |
The configuration options for the Nevermined App. |
• assetProviders: NeverminedNodeInfo
[] = []
• Private
configNVM: NeverminedAppOptions
• Private
fullSDK: undefined
| Nevermined
• Private
loginCredentials: undefined
| string
• Private
networkFee: undefined
| bigint
• Private
networkFeeReceiver: undefined
| string
• Private
searchSDK: Nevermined
• Private
userAccount: undefined
| NvmAccount
• Private
zeroDevSignerAccount: undefined
| SmartAccountSigner
<"custom"
, `0x${string}`>
▪ Static
Readonly
defaultAppInitializationOptions: NeverminedInitializationOptions
Default initialization options for the Nevermined application.
• get
config(): NeverminedOptions
Gets the configuration options for the Nevermined application.
The configuration options for the Nevermined application.
• get
networkFees(): Object
Gets the network fees.
Object
An object containing the receiver and fee.
Name | Type |
---|---|
fee |
bigint |
receiver |
string |
• get
sdk(): Nevermined
Gets the Nevermined SDK instance.
The Nevermined SDK instance.
Throws
If Web3 is not connected, try calling the connect method first.
• get
search(): SearchApi
Gets the SearchApi instance.
The SearchApi instance.
• get
services(): ServicesApi
Gets the Services API instance.
The Services API instance.
▸ addNetworkFee(price
): AssetPrice
Adds the network fee to the given asset price. If the network fee is not already included in the price, it adjusts the price to include the network fees.
Name | Type | Description |
---|---|---|
price |
AssetPrice |
The asset price to which the network fee will be added. |
The updated asset price with the network fee included, or the original price if the network fee is already included.
▸ claimSubscription(agreementId
, subscriptionDid
, numberCredits
, serviceIndex?
): Promise
<boolean
>
Claims a subscription by transferring the specified number of credits from the subscription owner to the user’s account.
Name | Type | Description |
---|---|---|
agreementId |
string |
The ID of the agreement associated with the subscription. |
subscriptionDid |
string |
The DID (Decentralized Identifier) of the subscription. |
numberCredits |
bigint |
The number of credits to be claimed. |
serviceIndex? |
number |
(Optional) The index of the service within the subscription. |
Promise
<boolean
>
A Promise that resolves to a boolean indicating whether the claim was successful.
Throws
If Web3 is not connected or if there is an error claiming the NFT of the subscription.
▸ connect(account
, message?
, config?
, initOptions?
): Promise
<{ marketplaceAuthToken
: string
; userAccount
: NvmAccount
; zeroDevSignerAccount
: undefined
| SmartAccountSigner
<"custom"
, `0x${string}`> }>
Connects to the Nevermined network and initializes the NvmApp instance.
Name | Type | Description |
---|---|---|
account |
string | NvmAccount | SmartAccountSigner <"custom" , `0x${string}`> |
The account to connect with. It can be either a string representing the account address or an instance of the Account class. |
message? |
string |
An optional message to include in the client assertion for authentication. |
config? |
NeverminedOptions |
Optional configuration options for the Nevermined instance. |
initOptions? |
NeverminedInitializationOptions |
Optional initialization options for the Nevermined instance. |
Promise
<{ marketplaceAuthToken
: string
; userAccount
: NvmAccount
; zeroDevSignerAccount
: undefined
| SmartAccountSigner
<"custom"
, `0x${string}`> }>
An object containing the marketplace authentication token, user account, and zeroDev signer account (if applicable).
▸ createCreditsSubscription(susbcriptionMetadata
, subscriptionPrice
, numberCredits
, subscriptionNFTContractCreditsAddress?
): SubscribablePromise
<CreateProgressStep
, DDO
>
Creates a credits subscription.
Name | Type | Description |
---|---|---|
susbcriptionMetadata |
MetaData |
The metadata for the subscription. |
subscriptionPrice |
AssetPrice |
The price of the subscription. |
numberCredits |
bigint |
The number of credits for the subscription. |
subscriptionNFTContractCreditsAddress? |
string |
- |
SubscribablePromise
<CreateProgressStep
, DDO
>
A SubscribablePromise
that resolves to a DDO
object representing the created subscription.
Throws
If Web3 is not connected.
Throws
If the validation of the subscription fails.
▸ createCreditsSubscriptionAsync(susbcriptionMetadata
, subscriptionPrice
, numberCredits
): Promise
<DDO
>
Creates a credits subscription asynchronously.
Name | Type | Description |
---|---|---|
susbcriptionMetadata |
MetaData |
The metadata for the subscription. |
subscriptionPrice |
AssetPrice |
The price of the subscription. |
numberCredits |
bigint |
The number of credits for the subscription. |
Promise
<DDO
>
A Promise that resolves to a DDO (Decentralized Data Object).
▸ createTimeSubscription(susbcriptionMetadata
, subscriptionPrice
, duration
, subscriptionNFTContractTimeAddress?
): SubscribablePromise
<CreateProgressStep
, DDO
>
Creates a time-based subscription for a given asset.
Name | Type | Description |
---|---|---|
susbcriptionMetadata |
MetaData |
The metadata of the subscription. |
subscriptionPrice |
AssetPrice |
The price of the subscription. |
duration |
number |
The duration of the subscription in seconds. |
subscriptionNFTContractTimeAddress? |
string |
- |
SubscribablePromise
<CreateProgressStep
, DDO
>
A promise that resolves to the progress steps and the resulting DDO (Decentralized Data Object).
Throws
If Web3 is not connected.
Throws
If the validation of the subscription fails.
▸ createTimeSubscriptionAsync(susbcriptionMetadata
, subscriptionPrice
, duration
): Promise
<DDO
>
Creates a time-based subscription asynchronously.
Name | Type | Description |
---|---|---|
susbcriptionMetadata |
MetaData |
The metadata for the subscription. |
subscriptionPrice |
AssetPrice |
The price of the subscription. |
duration |
number |
The duration of the subscription in seconds. |
Promise
<DDO
>
A Promise that resolves to the DDO (Decentralized Data Object) of the created subscription.
▸ disconnect(): Promise
<void
>
Disconnects the NvmApp from the current web3 provider. Clears the fullSDK instance and resets the user account, zeroDevSigner settings, and login credentials.
Promise
<void
>
▸ downloadFiles(fileAssetDid
, fileIndex?
, destinationPath?
, agreementId?
): Promise
<OperationResult
>
Downloads files associated with a given file asset DID.
Name | Type | Description |
---|---|---|
fileAssetDid |
string |
The DID of the file asset. |
fileIndex? |
number |
(Optional) The index of the file to download if the file asset contains multiple files. |
destinationPath? |
string |
(Optional) The path where the downloaded files will be saved. |
agreementId? |
string |
(Optional) The ID of the agreement associated with the file asset. |
Promise
<OperationResult
>
A Promise that resolves to an OperationResult object containing the agreement ID and the success status of the download operation.
Throws
If there is an error downloading the files.
▸ getBalance(subscriptionDid
, accountAddress?
): Promise
<SubscriptionBalance
>
Retrieves the balance and subscription information for a given subscription DID and account address. If no account address is provided, the user’s account ID will be used.
Name | Type | Description |
---|---|---|
subscriptionDid |
string |
The DID (Decentralized Identifier) of the subscription. |
accountAddress? |
string |
(Optional) The Ethereum address of the account. If not provided, the user’s account ID will be used. |
Promise
<SubscriptionBalance
>
A Promise that resolves to a SubscriptionBalance object containing the subscription type, balance, and access information.
Throws
If the Web3 provider is not connected.
Throws
If there is an error retrieving the subscription information.
▸ getEncryptedAPIKey(sessionKey
): Promise
<string
>
It gets an encrypted Nevermined API Key that can be used to interact with the Nevermined. The generation of the API Key requires to have a ZeroDev Session Key that is given as parameter to this method.
Name | Type | Description |
---|---|---|
sessionKey |
string |
The Zero Dev Session Key. |
Promise
<string
>
A encrypted Nevermined API Key.
Throws
If Web3 is not connected. Call the connect method first.
▸ getLoginCredentials(): undefined
| string
Retrieves the login credentials.
undefined
| string
The login credentials as a string, or undefined if not set.
▸ getProviderAddresses(): string
[]
string
[]
▸ getServiceAccessToken(serviceDid
): Promise
<SubscriptionToken
>
Retrieves the service access token for a given service DID.
Name | Type | Description |
---|---|---|
serviceDid |
string |
The service DID for which to retrieve the access token. |
Promise
<SubscriptionToken
>
A promise that resolves to the subscription token.
Throws
If Web3 is not connected. Call the connect method first.
▸ initializeSearch(config?
): Promise
<void
>
Initializes the search functionality of the Nevermined App.
Name | Type | Description |
---|---|---|
config? |
NeverminedAppOptions |
Optional configuration options for the Nevermined App. |
Promise
<void
>
A Promise that resolves to void.
▸ isNetworkFeeIncluded(price
): boolean
Checks if the network fee is included in the given asset price.
Name | Type | Description |
---|---|---|
price |
AssetPrice |
The asset price to check. |
boolean
A boolean indicating whether the network fee is included.
▸ isWeb3Connected(): boolean
Checks if the web3 provider is connected.
boolean
True if the web3 provider is connected, false otherwise.
▸ orderSubscription(subscriptionDid
, numberCredits
, serviceIndex?
): SubscribablePromise
<OrderProgressStep
, string
>
Orders a subscription for a given NFT.
Name | Type | Description |
---|---|---|
subscriptionDid |
string |
The DID of the subscription NFT. |
numberCredits |
bigint |
The number of credits to be used for the subscription. |
serviceIndex? |
number |
(Optional) The index of the service to be used for the subscription. |
SubscribablePromise
<OrderProgressStep
, string
>
A SubscribablePromise
that resolves to the progress of the order or rejects with an error message.
Throws
If Web3 is not connected.
Throws
If there is an error ordering the subscription.
▸ orderSubscriptionAsync(subscriptionDid
, agreementId?
): Promise
<OperationResult
>
Orders a subscription and claim asynchronously.
Name | Type | Description |
---|---|---|
subscriptionDid |
string |
The DID of the subscription. |
agreementId? |
string |
The ID of the agreement (optional). |
Promise
<OperationResult
>
A Promise that resolves to an OperationResult object.
Throws
If Web3 is not connected.
Throws
If there is an error ordering the subscription.
▸ registerFileAsset(metadata
, subscriptionDid
, costInCredits?
, nftContractAddress
): SubscribablePromise
<CreateProgressStep
, DDO
>
Registers a file asset by creating a new DDO (Decentralized Data Object) on the network.
Name | Type | Description |
---|---|---|
metadata |
MetaData |
The metadata of the file asset. |
subscriptionDid |
string |
The subscription DID (Decentralized Identifier) associated with the file asset. |
costInCredits |
bigint |
The cost of the file asset in credits (default is 1). |
nftContractAddress |
string |
The address of the NFT contract associated with the file asset. |
SubscribablePromise
<CreateProgressStep
, DDO
>
A SubscribablePromise
that resolves to a DDO
(Decentralized Data Object) representing the registered file asset.
Throws
If the Web3 connection is not established.
Throws
If the file asset metadata is not valid.
▸ registerFileAssetAsync(metadata
, subscriptionDid
, costInCredits?
, nftContractAddress
): Promise
<DDO
>
Registers a file asset asynchronously.
Name | Type | Description |
---|---|---|
metadata |
MetaData |
The metadata of the file asset. |
subscriptionDid |
string |
The subscription DID. |
costInCredits |
bigint |
The cost in credits (default: 1n). |
nftContractAddress |
string |
- |
Promise
<DDO
>
A Promise that resolves to the registered DDO (Decentralized Data Object).
▸ registerServiceAsset(metadata
, subscriptionDid
, costInCredits?
, minCreditsToCharge?
, maxCreditsToCharge?
, nftContractAddress
): SubscribablePromise
<CreateProgressStep
, DDO
>
Registers a service asset.
Name | Type | Description |
---|---|---|
metadata |
MetaData |
The metadata of the asset. |
subscriptionDid |
string |
The subscription DID. |
costInCredits |
bigint |
The cost in credits (default: 1). |
minCreditsToCharge |
bigint |
The minimum credits required to charge (default: 1). |
maxCreditsToCharge |
bigint |
The maximum credits to charge (default: 1). |
nftContractAddress |
string |
The address of the NFT contract associated with the file asset. |
SubscribablePromise
<CreateProgressStep
, DDO
>
A promise that resolves to the progress steps and the registered DDO.
Throws
If Web3 is not connected.
Throws
If the metadata validation fails.
▸ registerServiceAssetAsync(metadata
, subscriptionDid
, costInCredits?
, minCreditsToCharge?
, maxCreditsToCharge?
, nftContractAddress
): Promise
<DDO
>
Name | Type |
---|---|
metadata |
MetaData |
subscriptionDid |
string |
costInCredits |
bigint |
minCreditsToCharge |
bigint |
maxCreditsToCharge |
bigint |
nftContractAddress |
string |
Promise
<DDO
>
▸ updateAsset(did
, metadata
): SubscribablePromise
<UpdateProgressStep
, DDO
>
Updates the metadata of an asset.
Name | Type | Description |
---|---|---|
did |
string |
The decentralized identifier (DID) of the asset. |
metadata |
MetaData |
The updated metadata for the asset. |
SubscribablePromise
<UpdateProgressStep
, DDO
>
A SubscribablePromise
that resolves to the updated DDO
(Decentralized Data Object).
Throws
If Web3 is not connected. Call the connect
method first.
▸ updateAssetAsync(did
, metadata
): Promise
<DDO
>
Updates the asset with the specified DID using the provided metadata.
Name | Type | Description |
---|---|---|
did |
string |
The DID (Decentralized Identifier) of the asset to update. |
metadata |
MetaData |
The updated metadata for the asset. |
Promise
<DDO
>
A Promise that resolves to the updated DDO (Decentralized Data Object) of the asset.
▸ validateFileAssetMetadata(_susbcriptionMetadata
): MetadataValidationResults
Name | Type |
---|---|
_susbcriptionMetadata |
MetaData |
▸ validateServiceAssetMetadata(_susbcriptionMetadata
): MetadataValidationResults
Name | Type |
---|---|
_susbcriptionMetadata |
MetaData |
▸ validateSubscription(metadata
, price
, subscriptionType
): MetadataValidationResults
Name | Type |
---|---|
metadata |
MetaData |
price |
AssetPrice |
subscriptionType |
SubscriptionType |
▸ getConfigFromTagName(appEnv
): NeverminedOptions
Name | Type |
---|---|
appEnv |
NVMAppEnvironments |
▸ getInstance(appEnv
, config?
): Promise
<NvmApp
>
Returns an instance of the NvmApp class.
Name | Type | Description |
---|---|---|
appEnv |
NVMAppEnvironments |
The environment for the NvmApp instance. |
config? |
Partial <NeverminedOptions | NeverminedAppOptions > |
Optional configuration options for the NvmApp instance. |
Promise
<NvmApp
>
A Promise that resolves to an instance of the NvmApp class.
▸ switchConfigBetweenEnvs(appEnv
): NeverminedOptions
Name | Type |
---|---|
appEnv |
NVMAppEnvironments |