Options
All
  • Public
  • Public/Protected
  • All
Menu

Describes the basic data and the utility functions for an Algorand Standard Asset.

Typically you don't create instances of this class manually. Use PactClient.fetchAsset instead. Also, when instantiating the pool e.g. by using PactClient.fetchPoolById the missing pool assets are fetched automatically.

Hierarchy

  • Asset

Index

Constructors

  • new Asset(algod: default, index: number): Asset
  • Creates an Asset class setting the index and Algorand client.

    Note that clients would not usually call this constructor themselves.

    Parameters

    • algod: default

      the Algorand sdk client to use for extracting asset details.

    • index: number

      the ID of the asset.

    Returns Asset

Properties

algod: default

The Algorand sdk client to use for extracting asset details.

decimals: number = 0

The number of decimal places that the Asset supports.

index: number

The ID of the asset.

name?: string = ""

The name of the Asset if there is one. This may be empty.

ratio: number = 1

The ratio between a base unit and the unit of the asset. This is used to convert between an integer and floating point representation of the asset without loss of precision.

unitName?: string = ""

The name of a unit of the asset if there is one. This may be empty.

assetsCache: Record<number, Asset> = {}

A cache of the asset index to Asset to reduce the time for looking up basic details about the asset.

Methods

  • buildOptInTx(address: string, suggestedParams: SuggestedParams): Transaction
  • Creates the actual transaction for the account to opt-in to holding the asset.

    Parameters

    • address: string

      Address of the account to opt in to the asset.

    • suggestedParams: SuggestedParams

      Algorand suggested parameters for transactions.

    Returns Transaction

    A transaction to opt-in into asset.

  • buildOptOutTx(address: string, closeTo: string, suggestedParams: SuggestedParams): Transaction
  • Parameters

    • address: string
    • closeTo: string
    • suggestedParams: SuggestedParams

    Returns Transaction

  • buildTransferTx(sender: string, receiver: string, amount: number, suggestedParams: SuggestedParams, note?: string): Transaction
  • Parameters

    • sender: string
    • receiver: string
    • amount: number
    • suggestedParams: SuggestedParams
    • note: string = ""

    Returns Transaction

  • getHolding(address: string): Promise<null | number>
  • Returns the amount of holding of this asset the account has.

    Note that this function may return null if the account has not opted in for this asset.

    Parameters

    • address: string

      The account to check the current holding.

    Returns Promise<null | number>

    The amount of this asset the account is holding, or None if the account is not opted into the asset.

  • getHoldingFromAccountInformation(accountInformation: any): null | number
  • Parameters

    • accountInformation: any

      The account information to extract the asset holding from.

    Returns null | number

    The amount of asset or null if the account is not opted into the asset.

  • isOptedIn(address: string): Promise<boolean>
  • Checks if the account is already able to hold this asset, that is it has already opted in.

    This functions should be called to check if the opt-in transaction needs to be created. See prepareOptInTx.

    Parameters

    • address: string

      The account to check if the asset is opted in on.

    Returns Promise<boolean>

    True if the account is already opted in, false otherwise.

  • prepareOptInTx(address: string): Promise<Transaction>
  • This creates a transaction that will allow the account to "opt in" to the asset.

    In Algorand, every account has to explicitly opt-in for an asset before receiving it.

    Needed if you want to receive an asset from a swap or to manage liquidity tokens.

    Parameters

    • address: string

      Account to opt in to this asset.

    Returns Promise<Transaction>

    Transaction for opting in to this asset.

  • prepareOptOutTx(address: string, closeTo: string): Promise<Transaction>
  • Parameters

    • address: string
    • closeTo: string

    Returns Promise<Transaction>

Generated using TypeDoc