WDK logoWDK documentation

Transfer ERC-20 Tokens

Transfer ERC-20 tokens and estimate transfer fees on EVM chains.

This guide explains how to transfer ERC-20 tokens (such as USD₮ or XAU₮), estimate fees, and validate inputs before executing.

Transfer Tokens

Use account.transfer() to send ERC-20 tokens to a recipient address.

Transfer ERC-20 Tokens
const transferResult = await account.transfer({
  token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
  recipient: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
  amount: 1000000000000000000n // 1 token in base units
})
console.log('Transfer hash:', transferResult.hash)
console.log('Transfer fee:', transferResult.fee, 'wei')

Estimate Transfer Fees

Use account.quoteTransfer() to get a fee estimate before executing the transfer.

Quote Token Transfer
const transferQuote = await account.quoteTransfer({
  token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
  recipient: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
  amount: 1000000000000000000n
})
console.log('Transfer fee estimate:', transferQuote.fee, 'wei')

Transfer with Validation

You can use transferTokenWithValidation() to validate addresses and check balances before transferring to catch errors early.

1. Validate Addresses

Address Validation
if (!tokenAddress.startsWith('0x') || tokenAddress.length !== 42) {
  throw new Error('Invalid token address')
}

if (!recipient.startsWith('0x') || recipient.length !== 42) {
  throw new Error('Invalid recipient address')
}

2. Check Balances

Use account.getTokenBalance() and account.getBalance() to verify sufficient funds:

Balance Check
const balance = await account.getTokenBalance(tokenAddress)
if (balance < amount) {
  throw new Error('Insufficient token balance')
}

const nativeBalance = await account.getBalance()
if (nativeBalance === 0n) {
  throw new Error('Need ETH for gas fees')
}

3. Quote and Execute Transfer

Use account.quoteTransfer() to estimate fees, then account.transfer() to execute:

Quote and Execute
const quote = await account.quoteTransfer({
  token: tokenAddress,
  recipient,
  amount
})
console.log('Transfer fee estimate:', quote.fee, 'wei')

const result = await account.transfer({
  token: tokenAddress,
  recipient,
  amount
})
console.log('Transfer completed:', result.hash)
console.log('Fee paid:', result.fee, 'wei')

Next Steps

Learn how to sign and verify messages with your EVM account.

On this page