Main class that interacts with the Nevermined payments API.

Constructors

  • Initialize the payments class.

    Parameters

    Returns Payments

    An instance of Payments

    Example

    const payments = new Payments({
    returnUrl: 'https://mysite.example'
    environment: 'staging'
    appId: 'my-app-id'
    version: '1.0.0'
    })

Properties

accountAddress?: string
appId?: string
environment: EnvironmentInfo
nvmApiKey?: string
returnUrl: string
version?: string

Accessors

  • get isLoggedIn(): boolean
  • Property to check if a user logged in.

    Returns boolean

    True if the user is logged in.

    Example

    payments.isLoggedIn
    

Methods

  • Burn credits for a given DID.

    Parameters

    • did: string

      The DID (Decentralized Identifier) of the asset.

    • nftAmount: string

      The amount of NFT (Non-Fungible Token) credits to burn.

    • Optional nvmApiKey: string

      (Optional) The NVM (Nevermined Vault Manager) API key to use for authorization.

    Returns Promise<any>

    A Promise that resolves to the JSON response from the server.

    Throws

    Error if the server response is not successful.

  • Redirects the user to the subscription checkout page for the specified DID.

    Parameters

    • did: string

      The DID (Decentralized Identifier) of the item to be subscribed to.

    Returns void

  • Initiate the connect flow. The user's browser will be redirected to the Nevermined App login page.

    Returns void

    Remarks

    This is a browser only function.

    Example

    payments.connect()
    
  • Create a subscription on Nevermined.

    Parameters

    • __namedParameters: {
          amountOfCredits: number;
          description: string;
          name: string;
          nvmApiKey?: string;
          price: bigint;
          tags?: string[];
          tokenAddress: string;
      }
      • amountOfCredits: number
      • description: string
      • name: string
      • Optional nvmApiKey?: string
      • price: bigint
      • Optional tags?: string[]
      • tokenAddress: string

    Returns Promise<{
        did: string;
    }>

    The DID of the newly created subscription.

    Example

     const { did } = await payments.createSubscription({
    name: "test subscription",
    description: "test",
    price: 10000000n,
    tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
    duration: 30,
    tags: ["test"]
    }
  • Creates a file with the specified parameters.

    Parameters

    • __namedParameters: {
          amountOfCredits?: number;
          assetType: string;
          curation?: object;
          dataSchema?: string;
          description: string;
          files: object[];
          filesFormat?: string;
          fineTunable?: boolean;
          framework?: string;
          maxCreditsToCharge?: number;
          minCreditsToCharge?: number;
          name: string;
          nvmApiKey?: string;
          programmingLanguage?: string;
          sampleCode?: string;
          subscriptionDid: string;
          tags?: string[];
          task?: string;
          trainingDetails?: string;
          usageExample?: string;
          variations?: string;
      }
      • Optional amountOfCredits?: number
      • assetType: string
      • Optional curation?: object
      • Optional dataSchema?: string
      • description: string
      • files: object[]
      • Optional filesFormat?: string
      • Optional fineTunable?: boolean
      • Optional framework?: string
      • Optional maxCreditsToCharge?: number
      • Optional minCreditsToCharge?: number
      • name: string
      • Optional nvmApiKey?: string
      • Optional programmingLanguage?: string
      • Optional sampleCode?: string
      • subscriptionDid: string
      • Optional tags?: string[]
      • Optional task?: string
      • Optional trainingDetails?: string
      • Optional usageExample?: string
      • Optional variations?: string

    Returns Promise<{
        did: string;
    }>

    The promise that resolves to the created file's DID.

  • Creates a service.

    Parameters

    • __namedParameters: {
          amountOfCredits?: number;
          apiDescription?: string;
          authType: "none" | "basic" | "oauth";
          curation?: object;
          description: string;
          endpoints?: Endpoint[];
          integration?: string;
          maxCreditsToCharge?: number;
          minCreditsToCharge?: number;
          name: string;
          nvmApiKey?: string;
          openApiUrl?: string;
          openEndpoints?: string[];
          password?: string;
          sampleLink?: string;
          serviceChargeType: "fixed" | "dynamic";
          subscriptionDid: string;
          tags?: string[];
          token?: string;
          username?: string;
      }
      • Optional amountOfCredits?: number
      • Optional apiDescription?: string
      • authType: "none" | "basic" | "oauth"
      • Optional curation?: object
      • description: string
      • Optional endpoints?: Endpoint[]
      • Optional integration?: string
      • Optional maxCreditsToCharge?: number
      • Optional minCreditsToCharge?: number
      • name: string
      • Optional nvmApiKey?: string
      • Optional openApiUrl?: string
      • Optional openEndpoints?: string[]
      • Optional password?: string
      • Optional sampleLink?: string
      • serviceChargeType: "fixed" | "dynamic"
      • subscriptionDid: string
      • Optional tags?: string[]
      • Optional token?: string
      • Optional username?: string

    Returns Promise<{
        did: string;
    }>

    A promise that resolves to the created service DID.

  • Create a subscription on Nevermined.

    Parameters

    • __namedParameters: {
          description: string;
          duration?: number;
          name: string;
          nvmApiKey?: string;
          price: bigint;
          tags?: string[];
          tokenAddress: string;
      }
      • description: string
      • Optional duration?: number
      • name: string
      • Optional nvmApiKey?: string
      • price: bigint
      • Optional tags?: string[]
      • tokenAddress: string

    Returns Promise<{
        did: string;
    }>

    The DID of the newly created subscription.

    Example

     const { did } = await payments.createSubscription({
    name: "test subscription",
    description: "test",
    price: 10000000n,
    tokenAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
    duration: 30,
    tags: ["test"]
    }
  • Downloads files for a given DID asset.

    Parameters

    • did: string

      The DID of the file.

    • Optional nvmApiKey: string

      The NVM API key to use for the request.

    Returns Promise<any>

    A promise that resolves to the JSON response from the server.

  • Get the DDO for a given DID.

    Parameters

    • did: string

      The DID of the asset.

    Returns Promise<any>

    A promise that resolves to the DDO.

  • Redirects the user to the file details for the specified DID (Decentralized Identifier).

    Parameters

    • did: string

      The DID of the file.

    Returns void

  • Redirects the user to the service details for a given DID.

    Parameters

    • did: string

      The DID (Decentralized Identifier) of the service.

    Returns void

  • Get the service token for a given DID.

    Parameters

    • did: string

      The DID of the service.

    • Optional nvmApiKey: string

    Returns Promise<{
        token: {
            accessToken: string;
            neverminedProxyUri: string;
        };
    }>

    A promise that resolves to the service token.

  • Get array of files DIDs associated with a subscription.

    Parameters

    • subscriptionDid: string

    Returns Promise<any>

    A promise that resolves to array of files DIDs.

  • Get array of services DIDs associated with a subscription.

    Parameters

    • subscriptionDid: string

    Returns Promise<any>

    A promise that resolves to the array of services DIDs.

  • Get the balance of an account for a subscription.

    Parameters

    • subscriptionDid: string

      The subscription DID of the service to be published.

    • Optional accountAddress: string

      The address of the account to get the balance.

    • Optional nvmApiKey: string

      The NVM API key to use for the request.

    Returns Promise<{
        balance: bigint;
        isOwner: boolean;
        isSubscriptor: boolean;
        subscriptionType: string;
    }>

    A promise that resolves to the balance result.

  • Redirects the user to the subscription details for a given DID.

    Parameters

    • did: string

      The DID (Decentralized Identifier) of the subscription.

    Returns void

  • Method to initialize the class once the user has been logged in. This method should be called has soon as the user has been redirected back to the app (returnUrl).

    Returns void

    Remarks

    This is a browser only function.

    Example

    payments.init()
    

    Example: Using react

    You may want to use useEffect on the route that matches the passed returnUrl

    useEffect(() => {
    payments.init()
    })
  • Logout the user by removing the nvm api key.

    Returns void

    Remarks

    This is a browser only function.

    Example

    payments.logout()
    
  • Mint credits for a given DID and transfer them to a receiver.

    Parameters

    • did: string

      The DID (Decentralized Identifier) of the asset.

    • nftAmount: string

      The amount of NFT (Non-Fungible Token) credits to mint.

    • receiver: string

      The address of the receiver where the credits will be transferred.

    • Optional nvmApiKey: string

      (Optional) The NVM (Nevermined Vault Manager) API key to use for authorization.

    Returns Promise<any>

    A Promise that resolves to the JSON response from the server.

    Throws

    Error if the server response is not successful.

  • Orders a subscription.

    Parameters

    • subscriptionDid: string

      The subscription DID.

    • Optional agreementId: string

      The agreement ID.

    • Optional nvmApiKey: string

      The NVM API key to use for the request.

    Returns Promise<{
        agreementId: string;
        success: boolean;
    }>

    A promise that resolves to the agreement ID and a boolean indicating if the operation was successful.