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