From 5a9b056dfebe3edaae778ef59d7d5578e3261ef8 Mon Sep 17 00:00:00 2001 From: superggn <939401399@qq.com> Date: Wed, 26 Jun 2024 18:13:08 +0800 Subject: [PATCH] fix-format-and-contract --- 20_DecodeTx/DecodeTx.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/20_DecodeTx/DecodeTx.js b/20_DecodeTx/DecodeTx.js index 6e5fe36..6bd4da1 100644 --- a/20_DecodeTx/DecodeTx.js +++ b/20_DecodeTx/DecodeTx.js @@ -25,16 +25,21 @@ function handleBigInt(key, value) { return value; } +// 处理 USDT decimals +function format_usdt(amount_int) { + return Number(amount_int) / 10 ** 6; +} + let j = 0 provider.on('pending', async (txHash) => { if (txHash) { const tx = await provider.getTransaction(txHash) j++ - if (tx !== null && tx.data.indexOf(selector) !== -1) { + if (tx !== null && tx.data.indexOf(selector) !== -1 && tx.to == "0xdAC17F958D2ee523a2206206994597C13D831ec7") { console.log(`[${(new Date).toLocaleTimeString()}]监听到第${j + 1}个pending交易:${txHash}`) console.log(`打印解码交易详情:${JSON.stringify(iface.parseTransaction(tx), handleBigInt, 2)}`) console.log(`转账目标地址:${iface.parseTransaction(tx).args[0]}`) - console.log(`转账金额:${ethers.formatEther(iface.parseTransaction(tx).args[1])}`) + console.log(`转账金额:${format_usdt(iface.parseTransaction(tx).args[1])}`) provider.removeListener('pending', this) } }