Transfer tokens to another wallet address. This function automatically manages both native SUI and other token transfers, ensuring proper decimal adjustments.

Usage

// Transfer Stoken
const result = await agent.transferToken(
  SUI,
  0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76,
  1
);

Parameters

ParameterTypeRequiredDescription
token_symbolstringYesSymbol of the token to transfer
tostringYesWallet address to transfer to
amountnumberYesAmount to be transferred

Example Prompts

Natural Language Prompts

"Send 1 SUI to wallet 0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76"

"Transfer 100 USDC to 0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76"

LangChain Tool Prompts

 {
 "token_symbol": "SUI"
 "to": "0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76",
 "amount": 1
 }

Example Implementation

Here’s a complete example

import { SuiAgentKit } from "@getnimbus/sui-agent-kit";

async function executeTransfers(agent: SuiAgentKit) {
  // Transfer native SUI
  const suiTransfer = await agent.transferToken(
    "SUI",
    "0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76",
    1.5  // 1.5 SUI
  );
  console.log("SUI transfer:", suiTransfer);

  // Transfer USDC
  const usdcTransfer = await agent.transfer(
    "USDC",
    "0x15610fa7ee546b96cb580be4060fae1c4bb15eca87f9a0aa931512bad445fc76",
    100,  // 100 USDC
  );
  console.log("USDC transfer:", usdcTransfer);
}

Implementation Details

  • Handles decimal adjustment for tokens
  • Check wallet’s balance
  • Sign and execute transaction

Error Handling

try {
  const result = await agent.transferToken(token_symbol, to, amount);
} catch (error) {
  // throw error when insufficient balance, execute transfer failed
  throw error;
}

Best Practices

  1. Amount Validation
  • Always verify token decimals
  • Check balances before transfer
  • Account for transaction fees
  1. Address Validation
  • Validate recipient addresses
  1. Transaction Management
  • Monitor transaction status
  • Implement retry logic
  • Handle timeouts appropriately
  1. Security
  • Verify recipient addresses carefully
  • Implement confirmation dialogs
  • Consider using transaction previews

Common Token Symbol

  • SUI
  • USDC