Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

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);
}

React

import { signAndSubmitTransaction, isAptosWalletAccount } from '@dynamic-labs-sdk/aptos';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function AptosTransferButton({ recipientAddress, amount }) {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isAptosWalletAccount);
  const [hash, setHash] = useState('');

  const handleSubmit = async () => {
    if (!walletAccount) return;
    const { hash } = await signAndSubmitTransaction({
      walletAccount,
      transaction: {
        function: '0x1::aptos_account::transfer',
        functionArguments: [recipientAddress, amount],
      },
    });
    setHash(hash);
  };

  return (
    <div>
      <button onClick={handleSubmit} disabled={!walletAccount}>Send APT</button>
      {hash && <p>Hash: {hash}</p>}
    </div>
  );
}

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