On my account in Shasta I have 5k TRX and the same amount of USDT. I'm trying to send USDT. So far it's failed with a result Failed -Out of Energy
. For instance:
async function transferTronTRC20Token(amount, privateKey, contractAddress) {
let url = TRON_API_URL;
const tronWeb = new TronWeb({
fullHost: url,
headers: {},
privateKey: privateKey,
});
const options = {
feeLimit: 10_000_000,
callValue: 0
};
const tx = await tronWeb.transactionBuilder.triggerSmartContract(
contractAddress,
'transfer(address,uint256)',
options,
[{
type: 'address',
value: toWallet
}, {
type: 'uint256',
value: amount * 1_000_000
}]
);
if (!tx.result || !tx.result.result) {
return console.error(`triggerSmartContract: ${tx}`);
}
const signedTx = await tronWeb.trx.sign(tx.transaction);
if (!signedTx.signature) {
return console.error(`trx.sign: ${signedTx}`);
}
return await tronWeb.trx.sendRawTransaction(signedTx);
}
===>
The USDT contract I use is:
TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
How can it be?
Your transaction failed due to your fee limit
...
feeLimit: 10_000_000, <-- 10 TRX
...
Tron uses energy to run smart contract transactions. If there is no energy in the account, it will then burn TRX.
You can either
Stake (freeze) TRX to get energy and use the energy for your smart contract transaction. You can unfreeze your TRX to get back your TRX.
Set higher fee limit so it can burn TRX.