javascriptblockchaintrontronweb

Sending USDT in testnet -- always "out of energy"


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);
}

===>

https://shasta.tronscan.org/#/transaction/64b190a7064926a62a19c28ecef0454d50b2c38af4711093a111e845e9488664

The USDT contract I use is:

TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs

How can it be?


Solution

  • 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

    1. 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.

    2. Set higher fee limit so it can burn TRX.