Skip to content

Instantly share code, notes, and snippets.

@zhaomengru2015
Last active November 24, 2021 06:42
Show Gist options
  • Select an option

  • Save zhaomengru2015/a5ce6db4deea760edd7936da83651f6b to your computer and use it in GitHub Desktop.

Select an option

Save zhaomengru2015/a5ce6db4deea760edd7936da83651f6b to your computer and use it in GitHub Desktop.
Tron transaction decode
# node --experimental-modules index.mjs
import base58check from 'bs58check';
import pkg from 'tron-protocol-ts';
const { TransferContract, Transaction } = pkg;
let rawTransaction="0a80010a0201f422086f2122e8e7c533ac40c8b4d4ecd42f5a69080112650a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412340a1541adad4a46544612f9625428e36e0cf3df9a97d37e121541f10c803081f0d8e8db87efb44d233b36fe2fda8a18dda0d8ac03124152e751210fe9ef4f39e10ef64c6c826f5e99a6ebf88cc9f01f6e588b8a769c6f7718df28ea7c8dfe0c002bffc3f4895f19c46343d3769eea89b97ed78096741c01"
let transaction=Transaction.deserializeBinary(Buffer.from(rawTransaction, 'hex'));
transaction.getRawData().getContractList().forEach((contract) => {
console.log(contract.getType(),"----------")
switch (contract.getType()) {
case Transaction.Contract.ContractType.TRANSFERCONTRACT:
const param = TransferContract.deserializeBinary(contract.getParameter().getValue());
const amount = param.getAmount();
const toAddress = base58check.encode(param.getToAddress());
const ownerAddress = base58check.encode(param.getOwnerAddress());
console.log(param,amount,toAddress,ownerAddress)
// Handle other kinds of Transaction.Contract.ContractType if you need it
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment