Class SubtopiaClient

The SubtopiaClient class is responsible for interacting with a Subtopia Product contracts on the Algorand blockchain. It provides methods for initializing the client, managing the lifecycle of the application, creating and managing subscriptions, and retrieving information about the application and subscriptions.

Constructors

  • Parameters

    • __namedParameters: {
          algodClient: AlgodClient;
          appAddress: string;
          appID: number;
          appSpec: ApplicationSpec;
          coin: AssetMetadata;
          creator: TransactionSignerAccount;
          oracleID: number;
          price: number;
          productName: string;
          registryID: number;
          subscriptionName: string;
          timeout: number;
          version: string;
      }
      • algodClient: AlgodClient
      • appAddress: string
      • appID: number
      • appSpec: ApplicationSpec
      • coin: AssetMetadata
      • creator: TransactionSignerAccount
      • oracleID: number
      • price: number
      • productName: string
      • registryID: number
      • subscriptionName: string
      • timeout: number
      • version: string

    Returns SubtopiaClient

Properties

algodClient: AlgodClient
appAddress: string
appID: number
creator: TransactionSignerAccount
oracleID: number
price: number
productName: string
registryID: number
subscriptionName: string
timeout: number
version: string

Methods

  • Claims a subscription for a given subscriber.

    Parameters

    Returns Promise<{
        txID: string;
    }>

    • The transaction ID of the executed transaction.
  • This function creates a discount for a subscription and returns the transaction ID.

    Parameters

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID.

  • This method is utilized to initiate a subscription. It accepts a subscriber as an argument and returns a promise that resolves to an object containing the transaction ID and subscription ID.

    Parameters

    Returns Promise<{
        subscriptionID: number;
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID and subscription ID.

  • This method is used to delete a discount. Removes active discount from a product contract if exists.

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID.

  • This method is utilized to deactivate the application by updating the lifecycle. It should be invoked prior to the deletion of the application. Once deactivated, the product will cease to allow new subscriptions to be purchased, and existing subscribers will only have the option to cancel their subscriptions. The product can be deleted once all subscriptions have been cancelled or have expired. The method returns the transaction ID.

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID.

  • This method is used to enable the application (updates the lifecycle). The method returns the transaction ID.

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID.

  • Retrieves the current state of the application. Returns an object containing various details about the product such as product name, subscription name, manager, price, total subscriptions, maximum subscriptions, coin ID, subscription type, lifecycle, creation time, oracle ID, unit name, image URL, and discount.

    Parameters

    • parseWholeUnits: boolean = true

      Specifies whether to parse the whole units (default is true).

    Returns Promise<ProductState>

    A promise that resolves to an object representing the current state of the application.

  • This method retrieves the discount based on a given duration. It accepts a duration object as an argument and returns a promise that resolves to a DiscountRecord.

    Returns Promise<undefined | DiscountRecord>

    A promise that resolves to the discount record.

  • This method calculates the locker creation fee. It requires the creator's address as an input and returns a promise that resolves to the calculated fee amount.

    Parameters

    • creatorAddress: string

      The address of the locker's creator.

    Returns Promise<number>

    A promise that resolves to the calculated locker creation fee.

  • This method calculates the platform fee for a subscription. It returns the platform fee as a number.

    Returns Promise<number>

    A promise that resolves to the platform fee.

  • Checks if a given address is a subscriber.

    Parameters

    Returns Promise<boolean>

    • A promise that resolves to a boolean indicating whether the address is a subscriber.
  • Transfers a subscription from one subscriber to another.

    Parameters

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID of the transfer operation.

  • This method is used to update the lifecycle state of the application. The method returns the transaction ID.

    Parameters

    Returns Promise<{
        txID: string;
    }>

    A promise that resolves to an object containing the transaction ID.

  • Initializes a SubtopiaClient instance. Retrieves the product's global state, validates it, and creates a new SubtopiaClient.

    Parameters

    Returns Promise<SubtopiaClient>

    Promise resolving to a SubtopiaClient instance.

    import { SubtopiaClient } from "@algorand/subtopia";

    const subtopiaClient = await SubtopiaClient.init({
    algodClient: algodClient,
    productID: productID,
    creator: creator
    });