The ATokensClient class provides methods to interact with AToken contracts on the Aptos blockchain. It extends the AptosContractWrapperBaseClass and includes functionalities for creating tokens, retrieving metadata, and managing token balances.

This client is designed to work with the AToken contracts and provides a high-level API for common operations. The client can be instantiated in two ways:

  1. Using the constructor directly with a provider and optional signer
  2. Using the static buildWithDefaultSigner method which automatically configures the client with the provider's ATokens profile account
// Using buildWithDefaultSigner
const provider = new AptosProvider();
const client = ATokensClient.buildWithDefaultSigner(provider);

// Using constructor directly
const provider = new AptosProvider();
const signer = provider.getATokensProfileAccount();
const client = new ATokensClient(provider, signer);

// Get token balance
const balance = await client.balanceOf(ownerAddress, metadataAddress);

The AptosProvider instance used to interact with the Aptos blockchain.

Optional Ed25519Account signer for transaction signing.

Hierarchy (View Summary)

Constructors

Properties

tokensContract: TokensContract

Methods

  • Retrieves the metadata of a specific asset for a given owner and symbol.

    Parameters

    • symbol: string

      The symbol of the asset.

    Returns Promise<AccountAddress>

    A promise that resolves to the account address containing the asset metadata.

  • Retrieves the balance of a specific token for a given account.

    Parameters

    • owner: AccountAddress

      The address of the account whose token balance is being queried.

    • metadataAddress: AccountAddress

      The address of the token's metadata.

    Returns Promise<bigint>

    A promise that resolves to the balance of the token as a bigint.

  • Builds a transaction for the specified user, function, and arguments.

    Parameters

    • user: AccountAddress

      The account address of the user initiating the transaction.

    • functionId: `${string}::${string}::${string}`

      The identifier of the Move function to be called.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      An array of arguments for the entry function.

    • typeArgs: string[] = []

    Returns Promise<SimpleTransaction>

    A promise that resolves to a SimpleTransaction object.

  • Calls a view method on the Aptos blockchain.

    Type Parameters

    • T extends MoveValue[]

      The type of the return value, which extends an array of MoveValue.

    Parameters

    • functionId: `${string}::${string}::${string}`

      The identifier of the function to call.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      The arguments to pass to the function.

    • typeArgs: string[] = []

      Optional generic type arguments for the function (e.g. ["0x1::aptos_coin::AptosCoin"]).

    Returns Promise<T>

    • A promise that resolves to the result of the view method call.
  • Retrieves the number of decimals for a given token.

    Parameters

    • metadataAddress: AccountAddress

      The address of the token metadata.

    Returns Promise<bigint>

    A promise that resolves to the number of decimals as a bigint.

  • Funds an account with a specified amount.

    Parameters

    • account: AccountAddress

      The address of the account to be funded.

    • amount: bigint

      The amount to fund the account with, in bigint.

    Returns Promise<UserTransactionResponse>

    A promise that resolves to a UserTransactionResponse.

  • Retrieves the Aptos balance of a specified account.

    Parameters

    • account: Ed25519Account

      The Ed25519 account object.

    • accountAddress: AccountAddress

      The address of the account to retrieve the balance for.

    • OptionalversionToWaitFor: bigint

      (Optional) The specific version to wait for before retrieving the balance.

    Returns Promise<bigint>

    A promise that resolves to the balance of the account in bigint.

  • Retrieves the decimal precision of a token.

    Parameters

    • funcAddr: `${string}::${string}::${string}`

      The address of the Move function to call.

    • metadataAddr: AccountAddress

      The account address containing the token metadata.

    Returns Promise<bigint>

    A promise that resolves to the decimal precision of the token as a bigint.

  • Retrieves events associated with a specific account.

    Parameters

    • account: AccountAddress

      The address of the account to retrieve events for.

    • limit: number

      The maximum number of events to retrieve.

    Returns Promise<
        {
            account_address: string;
            creation_number: any;
            data: any;
            event_index: any;
            indexed_type: string;
            sequence_number: any;
            transaction_block_height: any;
            transaction_version: any;
            type: string;
        }[],
    >

    A promise that resolves to an array of event objects, each containing:

    • account_address: The address of the account.
    • creation_number: The creation number of the event.
    • data: The data associated with the event.
    • event_index: The index of the event.
    • sequence_number: The sequence number of the event.
    • transaction_block_height: The block height of the transaction.
    • transaction_version: The version of the transaction.
    • type: The type of the event.
    • indexed_type: The indexed type of the event.
  • Retrieves the metadata address for a given coin.

    Parameters

    • funcAddr: `${string}::${string}::${string}`

      The Move function identifier to call.

    • coinName: string

      The name of the coin for which to retrieve the metadata address.

    Returns Promise<AccountAddress>

    A promise that resolves to the account address containing the metadata.

  • Retrieves the metadata of an AToken by its symbol for a given account owner.

    Parameters

    • symbol: string

      The symbol of the AToken.

    Returns Promise<AccountAddress>

    A promise that resolves to the account address containing the metadata.

  • Retrieves the previous index for a given user and metadata address.

    Parameters

    • user: AccountAddress

      The account address of the user.

    • metadataAddress: AccountAddress

      The account address of the metadata.

    Returns Promise<bigint>

    A promise that resolves to the previous index as a bigint.

  • Retrieves the reserve treasury address for a given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The account address of the metadata.

    Returns Promise<AccountAddress>

    A promise that resolves to the account address of the reserve treasury.

  • Retrieves the scaled user balance and total supply for a given user and token metadata address.

    Parameters

    • owner: AccountAddress

      The account address of the user whose balance is being queried.

    • metadataAddress: AccountAddress

      The account address of the token metadata.

    Returns Promise<{ scaledUserBalance: bigint; supply: bigint }>

    A promise that resolves to an object containing the scaled user balance and the total supply.

  • Retrieves the token account address associated with the given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the metadata account.

    Returns Promise<AccountAddress>

    A promise that resolves to the token account address.

  • Retrieves the token address for a given owner and token symbol.

    Parameters

    • symbol: string

    Returns Promise<AccountAddress>

    A promise that resolves to the account address of the token.

  • Retrieves the events associated with a given transaction hash.

    Parameters

    • txHash: HexInput

      The hash of the transaction to retrieve events for.

    Returns Promise<{ data: unknown }[]>

    A promise that resolves to an array of objects containing the event data.

    This method fetches the transaction details using the provided Aptos provider. It then checks if the transaction response is of type BlockMetadataTransactionResponse or UserTransactionResponse to extract the events. The event data is parsed from JSON and returned in an array.

  • Retrieves the underlying asset address for a given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the metadata account.

    Returns Promise<AccountAddress>

    A promise that resolves to the underlying asset address.

  • Retrieves the name of the token associated with the given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the account metadata.

    Returns Promise<string>

    A promise that resolves to the name of the token as a string.

  • Rescues tokens from the contract and sends them to a specified address.

    Parameters

    • token: AccountAddress

      The address of the token to be rescued.

    • to: AccountAddress

      The address to which the rescued tokens will be sent.

    • amount: bigint

      The amount of tokens to be rescued.

    • metadataAddress: AccountAddress

      The address of the metadata associated with the token.

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to the response of the committed transaction.

  • Retrieves the scaled balance of a specific account for a given token.

    Parameters

    • owner: AccountAddress

      The address of the account whose scaled balance is being queried.

    • metadataAddress: AccountAddress

      The address of the token's metadata.

    Returns Promise<bigint>

    A promise that resolves to the scaled balance of the specified account as a bigint.

  • Retrieves the scaled total supply of a token.

    Parameters

    • metadataAddress: AccountAddress

      The address of the token's metadata.

    Returns Promise<bigint>

    A promise that resolves to the scaled total supply of the token as a bigint.

  • Sends a transaction and awaits the response.

    Parameters

    • functionId: `${string}::${string}::${string}`

      The ID of the Move function to be called.

    • funcArgs: (EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes)[]

      An array of arguments for the entry function.

    • typeArgs: string[] = []

    Returns Promise<CommittedTransactionResponse>

    A promise that resolves to the committed transaction response.

  • Retrieves the symbol of the AToken associated with the given metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the account metadata.

    Returns Promise<string>

    A promise that resolves to the symbol of the AToken as a string.

  • Retrieves the total supply of a token given its metadata address.

    Parameters

    • metadataAddress: AccountAddress

      The address of the token's metadata.

    Returns Promise<bigint>

    A promise that resolves to the total supply of the token as a bigint.