Extension Wallet
Integration
APTOS Network
Sign & Submit Transaction

Sign and Submit Transaction

Cosmostation supports transaction signing and submission through the Aptos Wallet Adapter, fully compliant with the Aptos Wallet Standard.

Depending on your use case, you can either:

  • sign and submit a transaction in a single step, or
  • sign the transaction only and submit it yourself later

This section explains both approaches.


SignAndSubmitTransaction

Overview

signAndSubmitTransaction is the most common transaction flow for dApps.

In this flow:

  1. The dApp constructs a transaction payload
  2. The wallet asks the user to approve the transaction
  3. The wallet signs the transaction with the selected account
  4. The wallet submits the transaction to the connected Aptos network
  5. The dApp receives a transaction hash and can wait for confirmation

This approach is recommended when your app does not require custom submission logic or relayers.


Using Aptos Wallet Adapter

import { useWallet } from '@aptos-labs/wallet-adapter-react';
 
const { account, connected, signAndSubmitTransaction, network } = useWallet();
 
const APTOS_COIN = '0x1::aptos_coin::AptosCoin';
const recipientAddress = '0x...';
 
const onSignAndSubmitTransaction = async () => {
  if (!connected || !account) return;
 
  const transaction = {
    data: {
      function: '0x1::coin::transfer',
      typeArguments: [APTOS_COIN],
      // Amount is expressed in Octas
      functionArguments: [recipientAddress, 1],
    },
  };
 
  try {
    const response = await signAndSubmitTransaction(transaction);
 
    // Wait until the transaction is finalized on-chain
    await aptosClient(network).waitForTransaction({
      transactionHash: response.hash,
    });
 
    console.log('Transaction confirmed:', response.hash);
  } catch (error) {
    console.error('Transaction failed:', error);
  }
};

SignTransaction

Overview

signTransaction only signs the transaction and returns an AccountAuthenticator.

The transaction is not submitted automatically.

This method is useful when:

  • you want to submit transactions manually
  • you are using relayers or sponsored transactions
  • you need to inspect or simulate transactions before submission
  • you are building multi-step or batched flows

Using Aptos Wallet Adapter

import { useWallet } from '@aptos-labs/wallet-adapter-react';
 
const { account, connected, signTransaction } = useWallet();
 
const APTOS_COIN = '0x1::aptos_coin::AptosCoin';
 
const onSignTransaction = async () => {
  if (!connected || !account) {
    throw new Error('Wallet not connected');
  }
 
  const payload = {
    data: {
      function: '0x1::coin::transfer',
      typeArguments: [APTOS_COIN],
      functionArguments: [account.address, 1],
    },
  };
 
  try {
    const authenticator = await signTransaction({
      transactionOrPayload: payload,
    });
 
    console.log('Signed authenticator:', authenticator);
    // Submit manually using your Aptos client if needed
  } catch (error) {
    console.error(error);
  }
};

Vanilla Code

Cosmostation also supports transaction signing without any adapter library.

The injected provider follows the Aptos Wallet Standard AptosSignTransactionMethod.


Example

const provider = aptos();
 
const payload: AnyRawTransaction = {
  // raw transaction or transaction payload
};
 
const asFeePayer = false;
 
try {
  const authenticator = await provider.signTransaction(payload, asFeePayer);
 
  console.log('Signed transaction:', authenticator);
} catch (e: any) {
  if (e?.code === 4001) {
    console.log('User rejected the request');
  } else {
    console.error(e);
  }
}

Notes

  • signTransaction only produces a signature
  • You are responsible for submitting the transaction
  • User rejection may surface as an exception or error code depending on wallet behavior

Reference

For full API details and advanced options, see the official Aptos documentation: