Skip to main content

Transactions

The SDK simplifies transaction building, signing, and submission. All complexity is handled automatically.

Send Native Token Transfer

Send a simple native token (ETH, SOL, etc.) transfer:
const txHash = await wallet.sendTransaction({
  to: '0x1234567890123456789012345678901234567890',
  amount: '1000000000000000000', // 1 ETH in wei (as string)
  chainId: 'eip155:8453' // Base
});

console.log('Transaction hash:', txHash);

Send ERC-20 Token Transfer

Transfer ERC-20 tokens:
const txHash = await wallet.sendToken({
  tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  to: '0x1234567890123456789012345678901234567890',
  amount: '1000000', // 1 USDC (6 decimals) as string
  chainId: 'eip155:1' // Ethereum
});

console.log('Token transfer hash:', txHash);

Send Custom Transaction

For more complex transactions, use the custom transaction builder:
const txHash = await wallet.sendCustomTransaction({
  to: '0xContractAddress...',
  data: '0x...', // Contract call data
  value: '0', // ETH amount (0 for contract calls)
  chainId: 'eip155:1',
  gasLimit: '200000', // Optional
  maxFeePerGas: '30000000000', // Optional (EIP-1559)
  maxPriorityFeePerGas: '2000000000' // Optional (EIP-1559)
});

Sign Message

Sign a message (EIP-191):
const signature = await wallet.signMessage({
  message: 'Hello, AxonVault!',
  chainId: 'eip155:1'
});

console.log('Signature:', signature);

Sign Typed Data

Sign EIP-712 typed data:
const signature = await wallet.signTypedData({
  domain: {
    name: 'MyApp',
    version: '1',
    chainId: 1,
    verifyingContract: '0x...'
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' }
    ]
  },
  message: {
    name: 'Alice',
    wallet: '0x...'
  },
  chainId: 'eip155:1'
});

console.log('Typed data signature:', signature);

Get Transaction Status

Check transaction status:
const tx = await wallet.getTransaction('tx_abc123');

console.log('Status:', tx.status); // 'pending', 'submitted', 'confirmed', 'failed'
console.log('Hash:', tx.txHash);
console.log('Block:', tx.blockNumber);
console.log('Confirmations:', tx.confirmations);

List Transactions

Get transaction history:
// Get all transactions
const transactions = await wallet.listTransactions({
  limit: 20,
  chainId: 'eip155:8453' // Optional filter
});

// Get transactions with pagination
const { transactions, nextCursor } = await wallet.listTransactions({
  limit: 20,
  cursor: previousCursor
});

Transaction Events

Listen for transaction status updates:
// Transaction pending
wallet.on('transaction:pending', (tx) => {
  console.log('Transaction pending:', tx.txHash);
  // Show loading state
});

// Transaction submitted
wallet.on('transaction:submitted', (tx) => {
  console.log('Transaction submitted:', tx.txHash);
  // Show "submitted" state
});

// Transaction confirmed
wallet.on('transaction:confirmed', (tx) => {
  console.log('Transaction confirmed:', tx.txHash);
  console.log('Block:', tx.blockNumber);
  // Update UI, show success
});

// Transaction failed
wallet.on('transaction:failed', (tx) => {
  console.log('Transaction failed:', tx.error);
  // Show error message
});

Wait for Confirmation

Wait for a transaction to be confirmed:
// Wait for confirmation (with timeout)
const confirmedTx = await wallet.waitForConfirmation('tx_abc123', {
  timeout: 60000, // 60 seconds
  confirmations: 1 // Number of confirmations required
});

console.log('Confirmed in block:', confirmedTx.blockNumber);

Estimate Gas

Estimate gas for a transaction before sending:
const gasEstimate = await wallet.estimateGas({
  to: '0x1234...',
  amount: '1000000000000000000',
  chainId: 'eip155:8453'
});

console.log('Estimated gas:', gasEstimate.gasLimit);
console.log('Estimated cost:', gasEstimate.totalCost);

Error Handling

import { TransactionError } from '@axonvault/embedded-wallet-sdk';

try {
  const txHash = await wallet.sendTransaction({ ... });
} catch (error) {
  if (error instanceof TransactionError) {
    switch (error.code) {
      case 'INSUFFICIENT_BALANCE':
        console.error('Not enough balance');
        break;
      case 'INVALID_ADDRESS':
        console.error('Invalid recipient address');
        break;
      case 'GAS_ESTIMATION_FAILED':
        console.error('Gas estimation failed');
        break;
      case 'TRANSACTION_REVERTED':
        console.error('Transaction reverted:', error.revertReason);
        break;
      default:
        console.error('Transaction error:', error.message);
    }
  }
}

Best Practices

  • Show loading states during transaction submission
  • Display transaction hash for user reference
  • Provide clear error messages
  • Show transaction status updates in real-time
  • Let SDK handle gas estimation (default)
  • Only override gas if you have specific requirements
  • Use EIP-1559 for better fee management
  • Handle insufficient balance errors gracefully
  • Retry failed transactions if appropriate
  • Show user-friendly error messages