A class to handle all Simulate transaction operations.

Implementation

Properties

Implementation

  • Initializes a new instance of the Aptos client with the specified configuration. This allows you 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 Simulate

    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 your desired network

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

    console.log("Aptos client initialized:", aptos);
    }
    runExample().catch(console.error);
  • Simulates a multi-agent transaction by generating a signed transaction and posting it to the Aptos full node. This function helps in understanding the outcome of a transaction involving multiple signers before it is executed.

    Parameters

    • args: {
          feePayerPublicKey?: PublicKey;
          options?: InputSimulateTransactionOptions;
          secondarySignersPublicKeys?: (undefined | PublicKey)[];
          signerPublicKey?: PublicKey;
          transaction: AnyRawTransaction;
      }

      The parameters for simulating the transaction.

      • OptionalfeePayerPublicKey?: PublicKey

        The public key of the fee payer (optional).

      • Optionaloptions?: InputSimulateTransactionOptions

        Options for simulating the transaction (optional).

      • OptionalsecondarySignersPublicKeys?: (undefined | PublicKey)[]

        An array of public keys for secondary signers (optional). Each element of the array can be optional, allowing the corresponding key check to be skipped.

      • OptionalsignerPublicKey?: PublicKey

        The public key of the primary signer (optional).

      • transaction: AnyRawTransaction

        The raw transaction to be simulated.

    Returns Promise<UserTransactionResponse[]>

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

    async function example() {
    let sender1 = Account.generate();
    let sender2 = Account.generate();
    let receiver = Account.generate();

    // 0. Set up the client and test accounts
    const config = new AptosConfig({ network: Network.DEVNET });
    const aptos = new Aptos(config);

    await aptos.fundAccount({
    accountAddress: sender.accountAddress,
    amount: 100_000_000,
    });

    // 1. Build
    console.log("\n=== 1. Building the transaction ===\n");
    const transaction = await aptos.transaction.build.multiAgent({
    sender: sender1.accountAddress,
    secondarySignerAddresses: [sender2.accountAddress],
    data: {
    // REPLACE WITH YOUR MULTI-AGENT FUNCTION HERE
    function:
    "<REPLACE WITH YOUR MULTI AGENT MOVE ENTRY FUNCTION> (Syntax {address}::{module}::{function})",
    functionArguments: [],
    },
    });
    console.log("Transaction:", transaction);

    // 2. Simulate (Optional)
    console.log("\n === 2. Simulating Response (Optional) === \n");
    const [userTransactionResponse] = await aptos.transaction.simulate.multiAgent(
    {
    signerPublicKey: sender1.publicKey,
    secondarySignersPublicKeys: [sender2.publicKey],
    transaction,
    },
    );
    console.log(userTransactionResponse);

    // If the fee looks ok, continue to signing!
    // ...
    }

    example();
  • Simulates a transaction based on the provided parameters and returns the result. This function helps you understand the outcome of a transaction before executing it on the blockchain.

    Parameters

    Returns Promise<UserTransactionResponse[]>

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

    async function example() {
    let sender = Account.generate();
    let receiver = Account.generate();

    // 0. Set up the client and test accounts
    const config = new AptosConfig({ network: Network.DEVNET });
    const aptos = new Aptos(config);

    await aptos.fundAccount({
    accountAddress: sender.accountAddress,
    amount: 100_000_000,
    });

    // 1. Build the transaction to preview the impact of it
    const transaction = await aptos.transaction.build.simple({
    sender: sender.accountAddress,
    data: {
    // All transactions on Aptos are implemented via smart contracts.
    function: "0x1::aptos_account::transfer",
    functionArguments: [receiver.accountAddress, 100],
    },
    });

    // 2. Simulate to see what would happen if we execute this transaction
    const [userTransactionResponse] = await aptos.transaction.simulate.simple({
    signerPublicKey: sender.publicKey,
    transaction,
    });
    console.log(userTransactionResponse);

    // If the fee looks ok, continue to signing!
    // ...
    }

    example();

Properties

config: AptosConfig
MMNEPVFCICPMFPCPTTAAATR