DEV Community

VIKASKO
VIKASKO

Posted on

TRC20 transfer.How to get the transfered amout from transaction hash ?

HI. I am trying to get TRC20 transaction details using the transaction hash.I'm trying to retrieve transaction details such as the to_address and amount for a specific transaction using getTransaction method. However, I'm only able to retrieve the from_address correctly, while the to_address is returning undefined and the amount is NaN. Please help me. I want to save the transaction details after the the user made the transaction.

async function getTransactionDetails(tronWeb, txid) {
return new Promise(async (resolve, reject) => {
const checkTransaction = async () => {
try {
const transaction = await tronWeb.trx.getTransaction(txid);
if (transaction && transaction.ret && transaction.ret.length > 0) {
resolve(transaction);
} else {
setTimeout(checkTransaction, 1000);
}
} catch (error) {
reject(error);
}
};

checkTransaction();
Enter fullscreen mode Exit fullscreen mode

});
}

const tronWeb = window.tronWeb;

const transaction = await getTransactionDetails(tronWeb, txid);

const fromAddress = transaction.raw_data.contract[0].parameter.value.owner_address;
const toAddress = transaction.raw_data.contract[0].parameter.value.to_address;
const amount = parseInt(transaction.raw_data.contract[0].parameter.value.amount);

Top comments (0)