NvmApp
@nevermined-io/sdk - v3.0.41 / NvmApp
Class: NvmApp
Represents the NvmApp class which is the main entry point for interacting with the Nevermined SDK.
Table of contents
Constructors
Properties
- assetProviders
- configNVM
- fullSDK
- loginCredentials
- networkFee
- networkFeeReceiver
- searchSDK
- userAccount
- zeroDevSignerAccount
- defaultAppInitializationOptions
Accessors
Methods
- addNetworkFee
- claimSubscription
- connect
- createCreditsSubscription
- createCreditsSubscriptionAsync
- createTimeSubscription
- createTimeSubscriptionAsync
- disconnect
- downloadFiles
- getBalance
- getEncryptedAPIKey
- getLoginCredentials
- getProviderAddresses
- getServiceAccessToken
- initializeSearch
- isNetworkFeeIncluded
- isWeb3Connected
- orderSubscription
- orderSubscriptionAsync
- registerFileAsset
- registerFileAssetAsync
- registerServiceAsset
- registerServiceAssetAsync
- updateAsset
- updateAssetAsync
- validateFileAssetMetadata
- validateServiceAssetMetadata
- validateSubscription
- getConfigFromTagName
- getInstance
- switchConfigBetweenEnvs
Constructors
constructor
• new NvmApp(config
): NvmApp
Represents the NvmApp class.
Parameters
Name | Type | Description |
---|---|---|
config | NeverminedAppOptions | The configuration options for the Nevermined App. |
Returns
Defined in
Properties
assetProviders
• assetProviders: NeverminedNodeInfo
[] = []
Defined in
configNVM
• Private
configNVM: NeverminedAppOptions
Defined in
fullSDK
• Private
fullSDK: undefined
| Nevermined
Defined in
loginCredentials
• Private
loginCredentials: undefined
| string
Defined in
networkFee
• Private
networkFee: undefined
| bigint
Defined in
networkFeeReceiver
• Private
networkFeeReceiver: undefined
| string
Defined in
searchSDK
• Private
searchSDK: Nevermined
Defined in
userAccount
• Private
userAccount: undefined
| NvmAccount
Defined in
zeroDevSignerAccount
• Private
zeroDevSignerAccount: undefined
| SmartAccountSigner
\<"custom"
, `0x${string}`>
Defined in
defaultAppInitializationOptions
▪ Static
Readonly
defaultAppInitializationOptions: NeverminedInitializationOptions
Default initialization options for the Nevermined application.
Defined in
Accessors
config
• get
config(): NeverminedOptions
Gets the configuration options for the Nevermined application.
Returns
The configuration options for the Nevermined application.
Defined in
networkFees
• get
networkFees(): Object
Gets the network fees.
Returns
Object
An object containing the receiver and fee.
Name | Type |
---|---|
fee | bigint |
receiver | string |
Defined in
sdk
• get
sdk(): Nevermined
Gets the Nevermined SDK instance.
Returns
The Nevermined SDK instance.
Throws
If Web3 is not connected, try calling the connect method first.
Defined in
search
• get
search(): SearchApi
Gets the SearchApi instance.
Returns
The SearchApi instance.
Defined in
services
• get
services(): ServicesApi
Gets the Services API instance.
Returns
The Services API instance.
Defined in
Methods
addNetworkFee
▸ 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.
Parameters
Name | Type | Description |
---|---|---|
price | AssetPrice | The asset price to which the network fee will be added. |
Returns
The updated asset price with the network fee included, or the original price if the network fee is already included.
Defined in
claimSubscription
▸ 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.
Parameters
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. |
Returns
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.
Defined in
connect
▸ 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.
Parameters
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. |
Returns
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).
Defined in
createCreditsSubscription
▸ createCreditsSubscription(susbcriptionMetadata
, subscriptionPrice
, numberCredits
, subscriptionNFTContractCreditsAddress?
): SubscribablePromise
\<CreateProgressStep
, DDO
>
Creates a credits subscription.
Parameters
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 | - |
Returns
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.
Defined in
createCreditsSubscriptionAsync
▸ createCreditsSubscriptionAsync(susbcriptionMetadata
, subscriptionPrice
, numberCredits
): Promise
\<DDO
>
Creates a credits subscription asynchronously.
Parameters
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. |
Returns
Promise
\<DDO
>
A Promise that resolves to a DDO (Decentralized Data Object).
Defined in
createTimeSubscription
▸ createTimeSubscription(susbcriptionMetadata
, subscriptionPrice
, duration
, subscriptionNFTContractTimeAddress?
): SubscribablePromise
\<CreateProgressStep
, DDO
>
Creates a time-based subscription for a given asset.
Parameters
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 | - |
Returns
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.
Defined in
createTimeSubscriptionAsync
▸ createTimeSubscriptionAsync(susbcriptionMetadata
, subscriptionPrice
, duration
): Promise
\<DDO
>
Creates a time-based subscription asynchronously.
Parameters
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. |
Returns
Promise
\<DDO
>
A Promise that resolves to the DDO (Decentralized Data Object) of the created subscription.
Defined in
disconnect
▸ 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.
Returns
Promise
\<void
>
Defined in
downloadFiles
▸ downloadFiles(fileAssetDid
, fileIndex?
, destinationPath?
, agreementId?
): Promise
\<OperationResult
>
Downloads files associated with a given file asset DID.
Parameters
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. |
Returns
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.
Defined in
getBalance
▸ 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.
Parameters
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. |
Returns
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.
Defined in
getEncryptedAPIKey
▸ 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.
Parameters
Name | Type | Description |
---|---|---|
sessionKey | string | The Zero Dev Session Key. |
Returns
Promise
\<string
>
A encrypted Nevermined API Key.
Throws
If Web3 is not connected. Call the connect method first.
Defined in
getLoginCredentials
▸ getLoginCredentials(): undefined
| string
Retrieves the login credentials.
Returns
undefined
| string
The login credentials as a string, or undefined if not set.
Defined in
getProviderAddresses
▸ getProviderAddresses(): string
[]
Returns
string
[]
Defined in
getServiceAccessToken
▸ getServiceAccessToken(serviceDid
): Promise
\<SubscriptionToken
>
Retrieves the service access token for a given service DID.
Parameters
Name | Type | Description |
---|---|---|
serviceDid | string | The service DID for which to retrieve the access token. |
Returns
Promise
\<SubscriptionToken
>
A promise that resolves to the subscription token.
Throws
If Web3 is not connected. Call the connect method first.
Defined in
initializeSearch
▸ initializeSearch(config?
): Promise
\<void
>
Initializes the search functionality of the Nevermined App.
Parameters
Name | Type | Description |
---|---|---|
config? | NeverminedAppOptions | Optional configuration options for the Nevermined App. |
Returns
Promise
\<void
>
A Promise that resolves to void.
Defined in
isNetworkFeeIncluded
▸ isNetworkFeeIncluded(price
): boolean
Checks if the network fee is included in the given asset price.
Parameters
Name | Type | Description |
---|---|---|
price | AssetPrice | The asset price to check. |
Returns
boolean
A boolean indicating whether the network fee is included.
Defined in
isWeb3Connected
▸ isWeb3Connected(): boolean
Checks if the web3 provider is connected.
Returns
boolean
True if the web3 provider is connected, false otherwise.
Defined in
orderSubscription
▸ orderSubscription(subscriptionDid
, numberCredits
, serviceIndex?
): SubscribablePromise
\<OrderProgressStep
, string
>
Orders a subscription for a given NFT.
Parameters
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. |
Returns
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.
Defined in
orderSubscriptionAsync
▸ orderSubscriptionAsync(subscriptionDid
, agreementId?
): Promise
\<OperationResult
>
Orders a subscription and claim asynchronously.
Parameters
Name | Type | Description |
---|---|---|
subscriptionDid | string | The DID of the subscription. |
agreementId? | string | The ID of the agreement (optional). |
Returns
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.
Defined in
registerFileAsset
▸ registerFileAsset(metadata
, subscriptionDid
, costInCredits?
, nftContractAddress
): SubscribablePromise
\<CreateProgressStep
, DDO
>
Registers a file asset by creating a new DDO (Decentralized Data Object) on the network.
Parameters
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. |
Returns
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.
Defined in
registerFileAssetAsync
▸ registerFileAssetAsync(metadata
, subscriptionDid
, costInCredits?
, nftContractAddress
): Promise
\<DDO
>
Registers a file asset asynchronously.
Parameters
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 | - |
Returns
Promise
\<DDO
>
A Promise that resolves to the registered DDO (Decentralized Data Object).
Defined in
registerServiceAsset
▸ registerServiceAsset(metadata
, subscriptionDid
, costInCredits?
, minCreditsToCharge?
, maxCreditsToCharge?
, nftContractAddress
): SubscribablePromise
\<CreateProgressStep
, DDO
>
Registers a service asset.
Parameters
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. |
Returns
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.
Defined in
registerServiceAssetAsync
▸ registerServiceAssetAsync(metadata
, subscriptionDid
, costInCredits?
, minCreditsToCharge?
, maxCreditsToCharge?
, nftContractAddress
): Promise
\<DDO
>
Parameters
Name | Type |
---|---|
metadata | MetaData |
subscriptionDid | string |
costInCredits | bigint |
minCreditsToCharge | bigint |
maxCreditsToCharge | bigint |
nftContractAddress | string |
Returns
Promise
\<DDO
>
Defined in
updateAsset
▸ updateAsset(did
, metadata
): SubscribablePromise
\<UpdateProgressStep
, DDO
>
Updates the metadata of an asset.
Parameters
Name | Type | Description |
---|---|---|
did | string | The decentralized identifier (DID) of the asset. |
metadata | MetaData | The updated metadata for the asset. |
Returns
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.
Defined in
updateAssetAsync
▸ updateAssetAsync(did
, metadata
): Promise
\<DDO
>
Updates the asset with the specified DID using the provided metadata.
Parameters
Name | Type | Description |
---|---|---|
did | string | The DID (Decentralized Identifier) of the asset to update. |
metadata | MetaData | The updated metadata for the asset. |
Returns
Promise
\<DDO
>
A Promise that resolves to the updated DDO (Decentralized Data Object) of the asset.
Defined in
validateFileAssetMetadata
▸ validateFileAssetMetadata(_susbcriptionMetadata
): MetadataValidationResults
Parameters
Name | Type |
---|---|
_susbcriptionMetadata | MetaData |
Returns
Defined in
validateServiceAssetMetadata
▸ validateServiceAssetMetadata(_susbcriptionMetadata
): MetadataValidationResults
Parameters
Name | Type |
---|---|
_susbcriptionMetadata | MetaData |
Returns
Defined in
validateSubscription
▸ validateSubscription(metadata
, price
, subscriptionType
): MetadataValidationResults
Parameters
Name | Type |
---|---|
metadata | MetaData |
price | AssetPrice |
subscriptionType | SubscriptionType |
Returns
Defined in
getConfigFromTagName
▸ getConfigFromTagName(appEnv
): NeverminedOptions
Parameters
Name | Type |
---|---|
appEnv | NVMAppEnvironments |
Returns
Defined in
getInstance
▸ getInstance(appEnv
, config?
): Promise
\<NvmApp
>
Returns an instance of the NvmApp class.
Parameters
Name | Type | Description |
---|---|---|
appEnv | NVMAppEnvironments | The environment for the NvmApp instance. |
config? | Partial \<NeverminedOptions | NeverminedAppOptions > | Optional configuration options for the NvmApp instance. |
Returns
Promise
\<NvmApp
>
A Promise that resolves to an instance of the NvmApp class.
Defined in
switchConfigBetweenEnvs
▸ switchConfigBetweenEnvs(appEnv
): NeverminedOptions
Parameters
Name | Type |
---|---|
appEnv | NVMAppEnvironments |