1

I am trying to sign a build & sign transaction then create a hex to broadcast the transaction on TRON Network.

I have successfully done this but when i broadcast this transaction i am getting "TRON TAPOS_ERROR" error. I have searched and got the reason that i have to include last block number and hash. check this : https://github.com/tronprotocol/java-tron/issues/857

But I don't know how to do this.

I have tried this code :

const CryptoUtils = require("@tronscan/client/src/utils/crypto");
const TransactionUtils = require("@tronscan/client/src/utils/transactionBuilder");

async function transferContractTx() {
    const fromAddress = "FROM_ADDRESS";
    const toAddress = "TO_ADDRESS";
    const privateKey = "MY_PRIVATE_KEY";
    const token = "TRX";
    const amount = 1000000;

    let transaction = TransactionUtils.buildTransferTransaction(token, fromAddress, toAddress, amount);
    console.log(JSON.stringify(transaction));
    let signedTransaction = CryptoUtils.signTransaction(privateKey, transaction);
    console.log(signedTransaction);
}

transferContractTx();
SamXcodeX
  • 11
  • 1

1 Answers1

1

You done this quite perfect but you are missing the concept of publishing(pushing) to the network, the "signedTransaction" need to be sent to the chain ,

tronWeb.trx.sendRawTransaction(signedtxn).then((receipt) => {
    console.log(receipt);
}).catch((e)=>{ 
    console.log(e);
});

This will broadcast your transaction and register in chain,