A class to query various Aptos-related information and perform operations on the Aptos blockchain.

Hierarchy (View Summary)

General

  • Initializes a new instance of the Aptos client with the specified configuration. This allows users to interact with the Aptos blockchain using the provided settings.

    Parameters

    • config: AptosConfig

      The configuration settings for the Aptos client.

      Represents the configuration settings for an Aptos SDK client instance. This class allows customization of various endpoints and client settings.

      • constructor:function
        • Initializes an instance of the Aptos client with the specified settings. This allows users to configure various aspects of the client, such as network and endpoints.

          Parameters

          • Optionalsettings: AptosSettings

            Optional configuration settings for the Aptos client.

            • Optional Readonlyclient?: Client
            • Optional ReadonlyclientConfig?: ClientConfig
            • Optional Readonlyfaucet?: string
            • Optional ReadonlyfaucetConfig?: FaucetConfig
            • Optional Readonlyfullnode?: string
            • Optional ReadonlyfullnodeConfig?: FullNodeConfig
            • Optional Readonlyindexer?: string
            • Optional ReadonlyindexerConfig?: IndexerConfig
            • Optional Readonlynetwork?: Network
            • Optional Readonlypepper?: string
            • Optional Readonlyprover?: string

          Returns AptosConfig

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          async function runExample() {
          // Create a new Aptos client with default settings
          const config = new AptosConfig({ network: Network.TESTNET }); // Specify the network
          const aptos = new Aptos(config);

          console.log("Aptos client initialized:", aptos);
          }
          runExample().catch(console.error);
      • Readonlyclient: Client

        The client instance the SDK uses. Defaults to `@aptos-labs/aptos-client

      • Optional ReadonlyclientConfig?: ClientConfig

        Optional client configurations

      • Optional Readonlyfaucet?: string

        The optional hardcoded faucet URL to send requests to instead of using the network

      • Optional ReadonlyfaucetConfig?: FaucetConfig

        Optional specific Faucet configurations

      • Optional Readonlyfullnode?: string

        The optional hardcoded fullnode URL to send requests to instead of using the network

      • Optional ReadonlyfullnodeConfig?: ClientHeadersType

        Optional specific Fullnode configurations

      • Optional Readonlyindexer?: string

        The optional hardcoded indexer URL to send requests to instead of using the network

      • Optional ReadonlyindexerConfig?: ClientHeadersType

        Optional specific Indexer configurations

      • Readonlynetwork: Network

        The Network that this SDK is associated with. Defaults to DEVNET

      • Optional Readonlypepper?: string

        The optional hardcoded pepper service URL to send requests to instead of using the network

      • Optional Readonlyprover?: string

        The optional hardcoded prover service URL to send requests to instead of using the network

      • getRequestUrl:function
        • Returns the URL endpoint to send the request to based on the specified API type. If a custom URL was provided in the configuration, that URL is returned. Otherwise, the URL endpoint is derived from the network.

          Parameters

          • apiType: AptosApiType

            The type of Aptos API to get the URL for. This can be one of the following: FULLNODE, FAUCET, INDEXER, PEPPER, PROVER.

          Returns string

          import { Aptos, AptosConfig, Network, AptosApiType } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          async function runExample() {
          // Getting the request URL for the FULLNODE API
          const url = config.getRequestUrl(AptosApiType.FULLNODE);
          console.log("Request URL for FULLNODE:", url);
          }
          runExample().catch(console.error);
      • isPepperServiceRequest:function
        • Checks if the provided URL is a known pepper service endpoint.

          Parameters

          • url: string

            The URL to check against the known pepper service endpoints.

          Returns boolean

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          async function runExample() {
          const url = "https://example.pepper.service"; // replace with a real pepper service URL

          // Check if the URL is a known pepper service endpoint
          const isPepperService = config.isPepperServiceRequest(url);

          console.log(`Is the URL a known pepper service? ${isPepperService}`);
          }
          runExample().catch(console.error);
      • isProverServiceRequest:function
        • Checks if the provided URL is a known prover service endpoint.

          Parameters

          • url: string

            The URL to check against known prover service endpoints.

          Returns boolean

          A boolean indicating whether the URL is a known prover service endpoint.

          import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

          const config = new AptosConfig({ network: Network.TESTNET });
          const aptos = new Aptos(config);

          // Check if the URL is a known prover service endpoint
          const url = "https://prover.testnet.aptos.dev"; // replace with a real URL if needed
          const isProver = config.isProverServiceRequest(url);

          console.log(`Is the URL a known prover service? ${isProver}`);

    Returns General

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    async function runExample() {
    // Create a configuration for the Aptos client
    const config = new AptosConfig({
    network: Network.TESTNET, // specify the network
    nodeUrl: "https://testnet.aptos.dev" // specify the node URL
    });

    // Initialize the Aptos client with the configuration
    const aptos = new Aptos(config);

    console.log("Aptos client initialized:", aptos);
    }
    runExample().catch(console.error);
  • Retrieve a block by its height, allowing for the inclusion of transactions if specified.

    Parameters

    • args: { blockHeight: AnyNumber; options?: { withTransactions?: boolean } }

      The parameters for the block retrieval.

      • blockHeight: AnyNumber

        The block height to look up, starting at 0.

      • Optionaloptions?: { withTransactions?: boolean }

        Optional settings for the retrieval.

        • OptionalwithTransactions?: boolean

          If set to true, includes all transactions in the block.

    Returns Promise<Block>

    The block with optional transactions included.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Retrieve the block at height 5, including transactions
    const block = await aptos.getBlockByHeight({ blockHeight: 5, options: { withTransactions: true } });
    console.log(block);
    }
    runExample().catch(console.error);
  • Retrieves block information by the specified ledger version.

    Parameters

    • args: { ledgerVersion: AnyNumber; options?: { withTransactions?: boolean } }

      The arguments for retrieving the block.

      • ledgerVersion: AnyNumber

        The ledger version to lookup block information for.

      • Optionaloptions?: { withTransactions?: boolean }

        Optional parameters for the request.

        • OptionalwithTransactions?: boolean

          If set to true, include all transactions in the block.

    Returns Promise<Block>

    Block information with optional transactions.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Retrieve block information for a specific ledger version
    const block = await aptos.getBlockByVersion({ ledgerVersion: 5 });
    console.log(block);
    }
    runExample().catch(console.error);
  • Retrieves the chain ID of the Aptos blockchain.

    Returns Promise<number>

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching the chain ID
    const chainId = await aptos.getChainId();
    console.log("Chain ID:", chainId);
    }
    runExample().catch(console.error);

    @returns The chain ID of the Aptos blockchain.
  • Queries the top user transactions based on the specified limit.

    Parameters

    • args: { limit: number }

      The arguments for querying top user transactions.

      • limit: number

        The number of transactions to return.

    Returns Promise<{ version: any }[]>

    GetChainTopUserTransactionsResponse

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetch the top user transactions with a limit of 5
    const topUserTransactions = await aptos.getChainTopUserTransactions({ limit: 5 });

    console.log(topUserTransactions);
    }
    runExample().catch(console.error);
  • Queries for the last successful indexer version, providing insight into the ledger version the indexer is updated to, which may lag behind the full nodes.

    Returns Promise<bigint>

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Get the last successful indexer version
    const version = await aptos.getIndexerLastSuccessVersion();
    console.log(`Last successful indexer version: ${version}`);
    }
    runExample().catch(console.error);
  • Queries for the Aptos ledger information.

    Returns Promise<LedgerInfo>

    The Aptos Ledger Info, which includes details such as chain ID, epoch, and ledger version.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Fetching the ledger information
    const ledgerInfo = await aptos.getLedgerInfo();

    console.log(ledgerInfo);
    }
    runExample().catch(console.error);
  • Query the processor status for a specific processor type.

    Parameters

    Returns Promise<{ last_success_version: any; last_updated: any; processor: string }>

    The status of the specified processor type.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Get the processor status for the account transactions processor
    const status = await aptos.getProcessorStatus("account_transactions_processor");
    console.log(status);
    }
    runExample().catch(console.error);
  • Retrieves data from the Aptos Indexer using a GraphQL query. This function allows you to execute complex queries to fetch specific data from the Aptos blockchain.

    Type Parameters

    • T extends {}

    Parameters

    Returns Promise<T>

    The provided T type.

    import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

    const config = new AptosConfig({ network: Network.TESTNET });
    const aptos = new Aptos(config);

    async function runExample() {
    // Querying the Aptos Indexer for ledger information
    const topUserTransactions = await aptos.queryIndexer({
    query: { query: `query MyQuery {
    ledger_infos {
    chain_id
    }
    }`}
    });

    console.log(topUserTransactions);
    }
    runExample().catch(console.error);

Properties

config: AptosConfig
MMNEPVFCICPMFPCPTTAAATR