Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20_DecodeTx: 限制交互合约地址, 修正合约 transfer 数值 format #172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions 20_DecodeTx/DecodeTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down