Class Provider

Builds a Provider class with an aptos client configured to connect to an Aptos node and indexer client configured to connect to Aptos Indexer.

It creates AptosClient and IndexerClient instances based on the network or custom endpoints provided.

This class holds both AptosClient and IndexerClient classes's methods and properties so we can instantiate the Provider class and use it to query full node and/or Indexer.

Example

An example of how to use this class

const provider = new Provider(Network.DEVNET)
const account = await provider.getAccount("0x123");
const accountNFTs = await provider.getAccountNFTs("0x123");

Param

enum of type Network - MAINNET | TESTNET | DEVENET or custom endpoints of type CustomEndpoints

Param

AptosClient config arg - additional configuration options for the generated Axios client.

Hierarchy

Constructors

Properties

aptosClient: AptosClient
endpoint: string
indexerClient: IndexerClient
network: NetworkWithCustom
nodeUrl: string

Methods

  • Queries an Aptos account by address

    Returns

    Core account resource, used for identifying account and transaction execution

    Example

    An example of the returned account

    {
    sequence_number: "1",
    authentication_key: "0x5307b5f4bc67829097a8ba9b43dba3b88261eeccd1f709d9bde240fc100fbb69"
    }

    Parameters

    • accountAddress: MaybeHexString

      Hex-encoded 32 byte Aptos account address

    Returns Promise<AccountData>

  • Queries module associated with given account by module name

    Note: In order to get all account resources, this function may call the API multiple times as it paginates.

    Returns

    Specified module. Module is represented by MoveModule interface. It contains module bytecode and abi, which JSON representation of a module

    Parameters

    • accountAddress: MaybeHexString

      Hex-encoded 32 byte Aptos account address

    • moduleName: string

      The name of the module

    • Optional query: {
          ledgerVersion?: AnyNumber;
      }
      • Optional ledgerVersion?: AnyNumber

        Specifies ledger version of transactions. By default latest version will be used

    Returns Promise<MoveModuleBytecode>

  • Queries modules associated with given account

    Note: In order to get all account modules, this function may call the API multiple times as it paginates.

    Returns

    Account modules array for a specific ledger version. Module is represented by MoveModule interface. It contains module bytecode and abi, which is JSON representation of a module

    Parameters

    • accountAddress: MaybeHexString

      Hex-encoded 32 byte Aptos account address

    • Optional query: {
          ledgerVersion?: AnyNumber;
      }
      • Optional ledgerVersion?: AnyNumber

        Specifies ledger version of transactions. By default latest version will be used

    Returns Promise<MoveModuleBytecode[]>

  • Queries an Aptos account's NFTs by owner address

    Returns

    GetAccountCurrentTokensQuery response type

    Parameters

    • ownerAddress: MaybeHexString

      Hex-encoded 32 byte Aptos account address

    • Optional options: PaginationArgs

    Returns Promise<GetAccountCurrentTokensQuery>

  • Queries resource associated with given account by resource type

    Returns

    Account resource of specified type and ledger version

    Example

    An example of an account resource

    {
    type: "0x1::aptos_coin::AptosCoin",
    data: { value: 6 }
    }

    Parameters

    • accountAddress: MaybeHexString

      Hex-encoded 32 byte Aptos account address

    • resourceType: string

      String representation of an on-chain Move struct type

    • Optional query: {
          ledgerVersion?: AnyNumber;
      }
      • Optional ledgerVersion?: AnyNumber

        Specifies ledger version of transactions. By default latest version will be used

    Returns Promise<MoveResource>

  • Get block by height

    Returns

    Block

    Parameters

    • blockHeight: number

      Block height to lookup. Starts at 0

    • Optional withTransactions: boolean

      If set to true, include all transactions in the block

    Returns Promise<Block>

  • Get block by block transaction version

    Returns

    Block

    Parameters

    • version: number

      Ledger version to lookup block information for

    • Optional withTransactions: boolean

      If set to true, include all transactions in the block

    Returns Promise<Block>

  • Queries a collection address.

    Returns

    the collection address

    Parameters

    • creatorAddress: MaybeHexString

      the collection creator address

    • collectionName: string

      the collection name

    • Optional extraArgs: {
          tokenStandard?: TokenStandard;
      }
      • Optional tokenStandard?: TokenStandard

    Returns Promise<string>

  • Queries data of a specific collection by the collection creator address and the collection name.

    if, for some reason, a creator account has 2 collections with the same name in v1 and v2, can pass an optional tokenStandard parameter to query a specific standard

    Returns

    GetCollectionDataQuery response type

    Parameters

    • creatorAddress: MaybeHexString

      the collection creator address

    • collectionName: string

      the collection name

    • Optional extraArgs: {
          options?: PaginationArgs;
          tokenStandard?: TokenStandard;
      }
      • Optional options?: PaginationArgs
      • Optional tokenStandard?: TokenStandard

    Returns Promise<GetCollectionDataQuery>

  • Queries for all collections that an account has tokens for.

    Returns

    GetCollectionsWithOwnedTokensQuery response type

    Parameters

    • ownerAddress: MaybeHexString

      the account address that owns the tokens

    • Optional extraArgs: {
          options?: PaginationArgs;
          tokenStandard?: TokenStandard;
      }
      • Optional options?: PaginationArgs
      • Optional tokenStandard?: TokenStandard

    Returns Promise<GetCollectionsWithOwnedTokensQuery>

  • Event types are globally identifiable by an account address and monotonically increasing creation_number, one per event type emitted to the given account. This API returns events corresponding to that that event type.

    Returns

    Array of events assotiated with the given account and creation number.

    Parameters

    • address: MaybeHexString

      Hex-encoded 32 byte Aptos account, with or without a 0x prefix, for which events are queried. This refers to the account that events were emitted to, not the account hosting the move module that emits that event type.

    • creationNumber: string | AnyNumber

      Creation number corresponding to the event type.

    • Optional query: PaginationArgs

    Returns Promise<Event[]>

  • This API uses the given account address, eventHandle, and fieldName to build a key that can globally identify an event types. It then uses this key to return events emitted to the given account matching that event type.

    Returns

    Array of events

    Parameters

    • address: MaybeHexString

      Hex-encoded 32 byte Aptos account, with or without a 0x prefix, for which events are queried. This refers to the account that events were emitted to, not the account hosting the move module that emits that event type.

    • eventHandleStruct: string

      String representation of an on-chain Move struct type. (e.g. 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>)

    • fieldName: string

      The field name of the EventHandle in the struct

    • Optional query: PaginationArgs

      Optional query object

    Returns Promise<Event[]>

  • Queries account's current owned tokens. This query returns all tokens (v1 and v2 standards) an account owns, including NFTs, fungible, soulbound, etc. If you want to get only the token from a specific standrd, you can pass an optional tokenStandard param

    Example

    An example of how to pass a specific token standard

    {
    tokenStandard:"v2"
    }

    Returns

    GetOwnedTokensQuery response type

    Parameters

    • ownerAddress: MaybeHexString

      The token owner address we want to get the tokens for

    • Optional extraArgs: {
          options?: PaginationArgs;
          tokenStandard?: TokenStandard;
      }
      • Optional options?: PaginationArgs
      • Optional tokenStandard?: TokenStandard

    Returns Promise<GetOwnedTokensQuery>

  • Gets a table item for a table identified by the handle and the key for the item. Key and value types need to be passed in to help with key serialization and value deserialization.

    Returns

    Table item value rendered in JSON

    Parameters

    • handle: string

      A pointer to where that table is stored

    • data: TableItemRequest

      Object, that describes table item

    • Optional query: {
          ledgerVersion?: AnyNumber;
      }

    Returns Promise<any>

  • Queries a token activities by token id hash

    Returns

    GetTokenActivitiesQuery response type

    Parameters

    • idHash: string

      token id hash

    • Optional options: PaginationArgs

    Returns Promise<GetTokenActivitiesQuery>

  • Gets the count of token's activities

    Returns

    GetTokenActivitiesCountQuery response type

    Parameters

    • tokenId: string

      Token ID

    Returns Promise<GetTokenActivitiesCountQuery>

  • Queries token data

    Returns

    GetTokenDataQuery response type

    Parameters

    • tokenId: string

      Token ID

    Returns Promise<GetTokenDataQuery>

  • Queries all tokens of a specific collection that an account owns by the collection address

    Returns

    GetTokenOwnedFromCollectionQuery response type

    Parameters

    • ownerAddress: MaybeHexString

      owner address that owns the tokens

    • collectionAddress: string

      the collection address

    • Optional extraArgs: {
          options?: PaginationArgs;
          tokenStandard?: TokenStandard;
      }
      • Optional options?: PaginationArgs
      • Optional tokenStandard?: TokenStandard

    Returns Promise<GetTokenOwnedFromCollectionQuery>

  • Queries all tokens of a specific collection that an account owns by the collection name and collection creator address

    Returns

    GetTokenOwnedFromCollectionQuery response type

    Parameters

    • ownerAddress: MaybeHexString

      owner address that owns the tokens

    • collectionName: string

      the collection name

    • creatorAddress: MaybeHexString

      the collection creator address

    • Optional extraArgs: {
          options?: PaginationArgs;
          tokenStandard?: TokenStandard;
      }
      • Optional options?: PaginationArgs
      • Optional tokenStandard?: TokenStandard

    Returns Promise<GetTokenOwnedFromCollectionQuery>

  • Queries token owners data

    Returns

    GetTokenOwnersDataQuery response type

    Parameters

    • tokenId: string

      Token ID

    • propertyVersion: number

      Property version

    Returns Promise<GetTokenOwnersDataQuery>

  • Queries top user transactions

    Returns

    GetTopUserTransactionsQuery response type

    Parameters

    • limit: number

    Returns Promise<GetTopUserTransactionsQuery>

  • Queries top user transactions

    Returns

    GetUserTransactionsQuery response type

    Parameters

    • Optional startVersion: number
    • Optional options: PaginationArgs

    Returns Promise<GetUserTransactionsQuery>

  • Builds a axios client call to fetch data from Aptos Indexer.

    Type Parameters

    • T

    Parameters

    • graphqlQuery: GraphqlQuery

      A GraphQL query to pass in the data axios call.

    Returns Promise<T>

  • Converts a transaction request produced by generateTransaction into a properly signed transaction, which can then be submitted to the blockchain

    Returns

    A transaction, signed with sender account

    Parameters

    • accountFrom: AptosAccount

      AptosAccount of transaction sender

    • rawTransaction: RawTransaction

      A raw transaction generated by generateTransaction method

    Returns Promise<Uint8Array>

  • Generates and submits a transaction to the transaction simulation endpoint. For this we generate a transaction with a fake signature.

    Returns

    The BCS encoded signed transaction, which you should then provide

    Parameters

    • accountOrPubkey: Ed25519PublicKey | MultiEd25519PublicKey | AptosAccount

      The sender or sender's public key. When private key is available, AptosAccount instance can be used to send the transaction for simulation. If private key is not available, sender's public key can be used to send the transaction for simulation.

    • rawTransaction: RawTransaction

      The raw transaction to be simulated, likely created by calling the generateTransaction function.

    • Optional query: {
          estimateGasUnitPrice?: boolean;
          estimateMaxGasAmount?: boolean;
          estimatePrioritizedGasUnitPrice: boolean;
      }
      • Optional estimateGasUnitPrice?: boolean

        If set to true, the gas unit price in the transaction will be ignored and the estimated value will be used.

      • Optional estimateMaxGasAmount?: boolean

        If set to true, the max gas value in the transaction will be ignored and the maximum possible gas will be used.

      • estimatePrioritizedGasUnitPrice: boolean

        If set to true, the transaction will use a higher price than the original estimate.

    Returns Promise<Types.UserTransaction[]>

  • Submits the BCS serialization of a signed transaction to the simulation endpoint.

    Returns

    Simulation result in the form of UserTransaction.

    Parameters

    • bcsBody: Uint8Array

      The output of generateBCSSimulation.

    • Optional query: {
          estimateGasUnitPrice?: boolean;
          estimateMaxGasAmount?: boolean;
          estimatePrioritizedGasUnitPrice?: boolean;
      }
      • Optional estimateGasUnitPrice?: boolean
      • Optional estimateMaxGasAmount?: boolean
      • Optional estimatePrioritizedGasUnitPrice?: boolean

    Returns Promise<Types.UserTransaction[]>

  • Defines if specified transaction is currently in pending state

    Returns

    true if transaction is in pending state and false otherwise

    Parameters

    • txnHash: string

      A hash of transaction

      To create a transaction hash:

      1. Create hash message bytes: "Aptos::Transaction" bytes + BCS bytes of Transaction.
      2. Apply hash algorithm SHA3-256 to the hash message bytes.
      3. Hex-encode the hash bytes with 0x prefix.

    Returns Promise<boolean>

  • This function works the same as waitForTransactionWithResult except it doesn't return the transaction in those cases, it returns nothing. For more information, see the documentation for waitForTransactionWithResult.

    Parameters

    • txnHash: string
    • Optional extraArgs: {
          checkSuccess?: boolean;
          timeoutSecs?: number;
      }
      • Optional checkSuccess?: boolean
      • Optional timeoutSecs?: number

    Returns Promise<void>

  • Wait for a transaction to move past pending state.

    There are 4 possible outcomes:

    1. Transaction is processed and successfully committed to the blockchain.
    2. Transaction is rejected for some reason, and is therefore not committed to the blockchain.
    3. Transaction is committed but execution failed, meaning no changes were written to the blockchain state.
    4. Transaction is not processed within the specified timeout.

    In case 1, this function resolves with the transaction response returned by the API.

    In case 2, the function will throw an ApiError, likely with an HTTP status code indicating some problem with the request (e.g. 400).

    In case 3, if checkSuccess is false (the default), this function returns the transaction response just like in case 1, in which the success field will be false. If checkSuccess is true, it will instead throw a FailedTransactionError.

    In case 4, this function throws a WaitForTransactionError.

    Returns

    See above.

    Example

    const rawTransaction = await this.generateRawTransaction(sender.address(), payload, extraArgs);
    const bcsTxn = AptosClient.generateBCSTransaction(sender, rawTransaction);
    const pendingTransaction = await this.submitSignedBCSTransaction(bcsTxn);
    const transasction = await this.aptosClient.waitForTransactionWithResult(pendingTransaction.hash);

    Parameters

    • txnHash: string

      The hash of a transaction previously submitted to the blockchain.

    • Optional extraArgs: {
          checkSuccess?: boolean;
          timeoutSecs?: number;
      }
      • Optional checkSuccess?: boolean

        See above. Defaults to false.

      • Optional timeoutSecs?: number

        Timeout in seconds. Defaults to 20 seconds.

    Returns Promise<Types.Transaction>

Generated using TypeDoc