Transfer TRC20 Tokens
Transfer TRC20 tokens and estimate transfer fees on Tron.
This guide explains how to transfer TRC20 tokens, estimate transfer fees, and validate inputs before executing.
Transfer Tokens
You can send TRC20 tokens to a recipient address using account.transfer():
const transferResult = await account.transfer({
token: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDT
recipient: 'TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
amount: 1000000 // Amount in TRC20's base units
})
console.log('Transfer hash:', transferResult.hash)
console.log('Transfer fee:', transferResult.fee, 'sun')Estimate Transfer Fees
You can get a fee estimate before executing the transfer using account.quoteTransfer():
const transferQuote = await account.quoteTransfer({
token: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDT
recipient: 'TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
amount: 1000000
})
console.log('Transfer fee estimate:', transferQuote.fee, 'sun')Transfer with Validation
Validate addresses and check balances before transferring to catch errors early:
- Use
account.getTokenBalance()to verify sufficient funds. - Use
account.quoteTransfer()to confirm fees. - Execute the transfer with
account.transfer():
async function transferTRC20WithValidation(account, trc20Address, recipient, amount) {
if (!trc20Address.startsWith('T') || trc20Address.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(trc20Address)
if (balance < amount) {
throw new Error('Insufficient TRC20 token balance')
}
const quote = await account.quoteTransfer({
token: trc20Address,
recipient,
amount
})
console.log('Transfer fee estimate (sun):', quote.fee)
const result = await account.transfer({
token: trc20Address,
recipient,
amount
})
console.log('Transfer completed:', result.hash)
console.log('Fee paid (sun):', result.fee)
return result
}Next Steps
Learn how to sign and verify messages with your Tron account.