Sending Transactions

Sending Transactions

After your dApp is connected to Petra, you can prompt the user to sign and submit transactions to the Aptos blockchain.

For more on Aptos transactions, see the Aptos SDKs (opens in a new tab) and the Transactions guide (opens in a new tab).

Sign and Submit

Use signAndSubmitTransaction from the useWallet hook to sign a transaction and submit it to the blockchain in one step:

import { useWallet, InputTransactionData } from "@aptos-labs/wallet-adapter-react";
 
function TransferButton() {
  const { signAndSubmitTransaction } = useWallet();
 
  const handleTransfer = async () => {
    const transaction: InputTransactionData = {
      data: {
        function: "0x1::coin::transfer",
        typeArguments: ["0x1::aptos_coin::AptosCoin"],
        functionArguments: [recipientAddress, amount],
      },
    };
 
    try {
      const pendingTransaction = await signAndSubmitTransaction(transaction);
      // pendingTransaction.hash contains the transaction hash
      console.log("Submitted:", pendingTransaction.hash);
    } catch (error) {
      // See "Error Codes" for possible errors
    }
  };
 
  return <button onClick={handleTransfer}>Transfer</button>;
}

The Wallet Adapter handles transaction serialization and submission — there is no need to manually construct an AptosClient.

Sign Only

If you need to sign a transaction without submitting it (e.g., for multi-sig workflows or deferred submission), use signTransaction:

import { useWallet, InputTransactionData } from "@aptos-labs/wallet-adapter-react";
 
function SignOnlyExample() {
  const { signTransaction } = useWallet();
 
  const handleSign = async () => {
    const transaction: InputTransactionData = {
      data: {
        function: "0x1::coin::transfer",
        typeArguments: ["0x1::aptos_coin::AptosCoin"],
        functionArguments: [recipientAddress, amount],
      },
    };
 
    try {
      const signedTransaction = await signTransaction(transaction);
      // Submit the signed transaction yourself later
    } catch (error) {
      // See "Error Codes" for possible errors
    }
  };
 
  return <button onClick={handleSign}>Sign</button>;
}

Sign-only is intended for advanced use cases. For most dApps, signAndSubmitTransaction is the right choice.