WDK logoWDK documentation
StartWalletsDeFi & FiatAI & CLITools

Transfer TRC20 Tokens

Transfer TRC20 tokens gas-free and estimate transfer fees.

This guide explains how to transfer TRC20 tokens gas-free, override the fee limit, estimate transfer fees, and validate inputs before executing.

Transfer Tokens (Gas-Free)

You can send TRC20 tokens gas-free using account.transfer(). The gas-free service handles the fee payment:

Gas-Free TRC20 Transfer
const transferResult = await account.transfer({
  token: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDt
  recipient: 'TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
  amount: 1000000 // Amount in TRC20's base units
})
console.log('GasFree transfer ID:', transferResult.hash)
console.log('Submitted fee estimate:', transferResult.fee, 'token units')
console.log('Submitted activation fee estimate:', transferResult.activationFee, 'token units')

The returned hash is the GasFree transfer ID, not the on-chain TRON transaction ID. Pass it to getTransaction() or waitForTransaction(); the native receipt exposes the chain transaction after the relay publishes it.

The returned fee sums the provider's transfer and activation fee estimates in token base units. Both fields are returned as bigint. activationFee is 0n when the provider returns no activation estimate.

Override Fee Limit

You can set a maximum fee for a specific transfer by passing a second configuration object specifying a transferMaxFee to account.transfer():

Transfer with Fee Limit
const result = await account.transfer({
  token: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDt
  recipient: 'TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
  amount: 1000000
}, {
  transferMaxFee: 1000 // Maximum fee allowed in token units
})
console.log('GasFree transfer ID:', result.hash)
console.log('Submitted fee estimate:', result.fee, 'token units')
console.log('Submitted activation fee estimate:', result.activationFee, 'token units')

Set transferMaxFee in the wallet configuration for a default. A per-transfer value overrides it. The wallet rejects the transfer before signing when the estimated total fee is greater than the effective cap. A fee equal to the cap is allowed.

Estimate Transfer Fees

You can get a fee estimate before executing the transfer using account.quoteTransfer():

Quote Gas-Free Transfer
const transferQuote = await account.quoteTransfer({
  token: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDt
  recipient: 'TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
  amount: 1000000
})
console.log('Transfer fee estimate:', transferQuote.fee, 'token units')
console.log('Activation fee estimate:', transferQuote.activationFee, 'token units')

If the GasFree account is inactive, the quote includes the token's activation fee in addition to the transfer fee and exposes that portion as activationFee. The quote reports the estimate. transfer() checks the effective cap against its own estimate.

Transfer with Validation

Validate addresses and check balances before transferring:

  1. Use account.getTokenBalance() to verify sufficient funds.
  2. Use account.quoteTransfer() to confirm fees.
  3. Execute the transfer with account.transfer():
Validated Gas-Free Transfer
async function transferWithValidation(account, tokenAddress, recipient, amount) {
  if (!tokenAddress.startsWith('T') || tokenAddress.length !== 34) {
    throw new Error('Invalid TRC20 contract address')
  }

  if (!recipient.startsWith('T') || recipient.length !== 34) {
    throw new Error('Invalid recipient address')
  }

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

  const quote = await account.quoteTransfer({
    token: tokenAddress,
    recipient,
    amount
  })
  console.log('Transfer fee estimate:', quote.fee, 'token units')
  console.log('Activation fee estimate:', quote.activationFee, 'token units')

  const result = await account.transfer({
    token: tokenAddress,
    recipient,
    amount
  })
  console.log('GasFree transfer ID:', result.hash)
  console.log('Submitted fee estimate:', result.fee, 'token units')
  console.log('Submitted activation fee estimate:', result.activationFee, 'token units')

  return result
}

Next Steps

Learn how to sign and verify messages with your gas-free Tron account.

On this page