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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)