Token Operations

Learn how to transfer SOL and SPL tokens to other wallets

Transfer SOL or any SPL token to another wallet address. The function automatically handles both native SOL transfers and SPL token transfers with proper decimal adjustment.

Copy

// Transfer SOL
const signature = await agent.methods.transfer(
  new PublicKey("recipient-address"),
  1.5  // amount in SOL
);

// Transfer SPL token
const signature = await agent.methods.transfer(
  new PublicKey("recipient-address"),
  100,  // amount in token units
  new PublicKey("token-mint-address")
);

Parameter
Type
Required
Description

to

PublicKey

Yes

Recipient’s wallet address

amount

number

Yes

Amount to transfer

mint

PublicKey

No

Token mint address (omit for SOL)

Copy

Copy

Here’s a complete example showing different types of transfers:

Copy

  • Automatically detects SOL vs SPL token transfers

  • Handles decimal adjustment for SPL tokens

  • Creates Associated Token Accounts if needed

  • Uses single-instruction transactions for efficiency

Copy

  1. Amount Validation

    • Always verify token decimals

    • Check balances before transfer

    • Account for transaction fees

  2. Address Validation

    • Validate recipient addresses

    • Double-check mint addresses

    • Use address checksums

  3. Transaction Management

    • Monitor transaction status

    • Implement retry logic

    • Handle timeouts appropriately

  4. Security

    • Verify recipient addresses carefully

    • Implement confirmation dialogs

    • Consider using transaction previews

  • SOL: Native token (no mint address needed)

  • USDC: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

  • USDT: Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB

  • BONK: DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263

Last updated