Skip to main content

signAndSubmitTransaction

Signs and submits an Aptos transaction to the network in a single step. This is the most common way to execute transactions on Aptos.

Usage

import { signAndSubmitTransaction, isAptosWalletAccount } from "@dynamic-labs-sdk/aptos";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isAptosWalletAccount(walletAccount)) {
  const { hash } = await signAndSubmitTransaction({
    transaction: {
      function: "0x1::aptos_account::transfer",
      functionArguments: [recipientAddress, amount],
    },
    walletAccount,
  });

  console.log("Transaction submitted:", hash);
}

Parameters

ParameterTypeDescription
transactionAptosTransactionPayloadThe transaction payload to sign and submit
walletAccountAptosWalletAccountThe wallet account to sign the transaction with
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<{ hash: string }> - A promise that resolves to an object containing the transaction hash.

Errors

ErrorDescription
NotAptosProviderErrorThrown if the wallet account’s provider is not an Aptos provider