SuperAPI AI Directory

transfer

General & other

View repository

Updated 10-30 07:59

About this skill

Transfer Skill

Purpose

This skill enables Claude to help users transfer native tokens and ERC20 tokens across EVM-compatible blockchain networks.

Security Warnings

BEFORE ANY TRANSFER:

  1. ALWAYS confirm the recipient address with the user
  2. ALWAYS show the estimated gas fees
  3. ALWAYS warn about irreversible transactions
  4. RECOMMEND starting with a small test amount for new addresses
  5. NEVER proceed without explicit user confirmation

Supported Networks

  • Ethereum Mainnet (ETH)
  • BNB Smart Chain (BNB)
  • Polygon (MATIC)
  • Arbitrum (ETH)
  • Optimism (ETH)
  • Base (ETH)
  • Testnets: Sepolia, BSC Testnet

Quick Start

Transfer Native Token (ETH/BNB/MATIC)

import { createWalletClient, createPublicClient, http, parseEther } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { bsc } from 'viem/chains'

// Setup account
const account = privateKeyToAccount('0x...')

// Create clients
const publicClient = createPublicClient({
  chain: bsc,
  transport: http()
})

const walletClient = createWalletClient({
  account,
  chain: bsc,
  transport: http()
})

// Send transaction
const hash = await walletClient.sendTransaction({
  to: '0xRecipientAddress...',
  value: parseEther('0.1') // 0.1 BNB
})

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

// Wait for confirmation
const receipt = await publicClient.waitForTransactionReceipt({ hash })
console.log('Confirmed in block:', receipt.blockNumber)

Transfer ERC20 Token

import { createWalletClient, createPublicClient, http, parseUnits } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { bsc } from 'viem/chains'

const ERC20_ABI = [
  {
    name: 'transfer',
    type: 'function',
    inputs: [
      { name: 'to', type: 'address' },
      { name: 'amount', type: 'uint256' }
    ],
    outputs: [{ name: '', type: 'bool' }]
  },
  {
    name: 'decimals',
    type: 'function',
    inputs: [],
    outputs: [{ name: '', type: 'uint8' }]
  },
  {
    name: 'balanceOf',
    type: 'function',
    inputs: [{ name: 'account', type: 'address' }],
    outputs: [{ name: '', type: 'uint256' }]
  }
]

const account = privateKeyToAccount('0x...')
const tokenAddress = '0xTokenContract...'
const recipientAddress = '0xRecipient...'
const amount = '100' // Amount in token units

const publicClient = createPublicClient({
  chain: bsc,
  transport: http()
})

const walletClient = createWalletClient({
  account,
  chain: bsc,
  transport: http()
})

// Get token decimals
const decimals = await publicClient.readContract({
  address: tokenAddress,
  abi: ERC20_ABI,
  functionName: 'decimals'
})

// Execute transfer
const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: ERC20_ABI,
  functionName: 'transfer',
  args: [recipientAddress, parseUnits(amount, decimals)]
})

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

Common Operations

1. Estimate Gas Before Transfer

Always estimate gas to show users the expected cost:

import { createPublicClient, http, parseEther, formatEther } from 'viem'
import { bsc } from 'viem/chains'

const publicClient = createPublicClient({
  chain: bsc,
  transport: http()
})

// Get current gas price
const gasPrice = await publicClient.getGasPrice()

// Estimate gas for the transaction
const gasEstimate = await publicClient.estimateGas({
  account: '0xSenderAddress...',
  to: '0xRecipientAddress...',
  value: parseEther('0.1')
})

// Calculate total cost
const totalGasCost = gasEstimate * gasPrice

console.log('Estimated gas:', gasEstimate.toString())
console.log('Gas price:', formatEther(gasPrice), 'BNB')
console.log('Total gas cost:', formatEther(totalGasCost), 'BNB')

2. Check Transaction Status

import { createPublicClient, http } from 'viem'
import { bsc } from 'viem/chains'

const publicClient = createPublicClient({
  chain: bsc,
  transport: http()
})

const txHash = '0x...'

// Get transaction details
const tx = await publicClient.getTransaction({ hash: txHash })
console.log('Transaction:', tx)

// Get transaction receipt (after confirmation)
const receipt = await publicClient.getTransactionReceipt({ hash: txHash })
console.log('Status:', receipt.status === 'success' ? 'Success' : 'Failed')
console.log('Block:', receipt.blockNumber)
console.log('Gas used:', receipt.gasUsed.toString())

3. Token Approval (Required for some operations)

Before transferring tokens via a contract (like DEX), you need to approve:

import { createWalletClient, http, maxUint256 } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { bsc } from 'viem/chains'

const ERC20_ABI = [
  {
    name: 'approve',
    type: 'function',
    inputs: [
      { name: 'spender', type: 'address' },
      { name: 'amount', type: 'uint256' }
    ],
    outputs: [{ name: '', type: 'bool' }]
  }
]

const account = privateKeyToAccount('0x...')
const tokenAddress = '0xTokenContract...'
const spenderAddress = '0xDEXRouter...' // Contract that will spend tokens

const walletClient = createWalletClient({
  account,
  chain: bsc,
  transport: http()
})

// Approve unlimited (common pattern, but be cautious)
const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: ERC20_ABI,
  functionName: 'approve',
  args: [spenderAddress, maxUint256]
})

console.log('Approval transaction:', hash)

4. Batch Check Balances Before Transfer

import { createPublicClient, http, formatEther, formatUnits } from 'viem'
import { bsc } from 'viem/chains'

const publicClient = createPublicClient({
  chain: bsc,
  transport: http()
})

const walletAddress = '0x...'
const tokenAddress = '0x...'

const ERC20_ABI = [
  {
    name: 'balanceOf',
    inputs: [{ name: 'account', type: 'address' }],
    outputs: [{ name: '', type: 'uint256' }],
    type: 'function'
  },
  {
    name: 'decimals',
    inputs: [],
    outputs: [{ name: '', type: 'uint8' }],
    type: 'function'
  }
]

// Check native balance
const nativeBalance = await publicClient.getBalance({
  address: walletAddress
})

// Check token balance
const [tokenBalance, decimals] = await Promise.all([
  publicClient.readContract({
    address: tokenAddress,
    abi: ERC20_ABI,
    functionName: 'balanceOf',
    args: [walletAddress]
  }),
  publicClient.readContract({
    address: tokenAddress,
    abi: ERC20_ABI,
    functionName: 'decimals'
  })
])

console.log('Native balance:', formatEther(nativeBalance), 'BNB')
console.log('Token balance:', formatUnits(tokenBalance, decimals))

Transfer Workflow

When a user requests a transfer, follow this workflow:

Step 1: Gather Information

Please provide:
1. Network (e.g., Ethereum, BNB Chain, Polygon)
2. Token to send (Native token or ERC20 address)
3. Recipient address
4. Amount to send

Step 2: Validate and Preview

📤 Transfer Preview
═══════════════════
Network: BNB Smart Chain
Token: BNB (Native)
From: 0x742d...6E47
To: 0x8ba1...3f29
Amount: 0.1 BNB

💰 Your Balance: 1.5 BNB
⛽ Estimated Gas: 0.0001 BNB
📊 Total Cost: 0.1001 BNB

⚠️ Please verify the recipient address carefully!
   Transactions cannot be reversed.

Proceed with transfer? (yes/no)

Step 3: Execute and Confirm

✅ Transfer Initiated!

Transaction Hash: 0x7d8f...a3b2
Status: Pending...

[Waiting for confirmation...]

✅ Transfer Confirmed!
Block: 31234567
Gas Used: 21000
Explorer: https://bscscan.com/tx/0x7d8f...a3b2

Error Handling

Common Errors

Error Cause Solution
Insufficient funds Not enough balance Check balance, reduce amount
Gas estimation failed Invalid params or contract Verify addresses and amounts
Nonce too low Pending transaction exists Wait or speed up pending tx
Transaction reverted Contract rejected Check token allowance, balance

Example Error Handling

try {
  const hash = await walletClient.sendTransaction({
    to: recipientAddress,
    value: parseEther(amount)
  })
  console.log('Success:', hash)
} catch (error) {
  if (error.message.includes('insufficient funds')) {
    console.log('Error: Insufficient balance for transfer + gas')
    console.log('Please reduce the amount or add more funds')
  } else if (error.message.includes('nonce')) {
    console.log('Error: Transaction nonce conflict')
    console.log('A previous transaction may be pending')
  } else {
    console.log('Transfer failed:', error.message)
  }
}

Popular Token Addresses

BNB Smart Chain

Token Address
USDT 0x55d398326f99059fF775485246999027B3197955
USDC 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d
BUSD 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56
WBNB 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

Ethereum

Token Address
USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7
USDC 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
WETH 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

Best Practices

  1. Always verify addresses - Double-check recipient address
  2. Start small - Test with small amounts first
  3. Check gas prices - During high congestion, wait for lower gas
  4. Keep some native tokens - Always keep some for gas fees
  5. Use block explorers - Verify transactions on chain

References