Files
Heyue_test/frontend/scripts/check-transaction-details.js

76 lines
2.7 KiB
JavaScript
Raw Normal View History

import { createPublicClient, http, getAddress } from 'viem'
import { arbitrumSepolia } from 'viem/chains'
const client = createPublicClient({
chain: arbitrumSepolia,
transport: http('https://api.zan.top/node/v1/arb/sepolia/baf84c429d284bb5b676cb8c9ca21c07')
})
const TX_HASH = '0xf38e4201b397b2e267402e2b355c811fb0d99ce2c9f67b3b0fff26028a7a4df4'
async function main() {
console.log('\n检查交易详情...\n')
console.log('交易哈希:', TX_HASH, '\n')
try {
// 获取交易详情
const tx = await client.getTransaction({ hash: TX_HASH })
console.log('=== 交易基本信息 ===')
console.log('From:', tx.from)
console.log('To:', tx.to)
console.log('区块:', tx.blockNumber)
console.log('Gas Used:', tx.gas.toString())
console.log('\n函数调用 (input):', tx.input.slice(0, 200) + '...')
console.log('函数选择器:', tx.input.slice(0, 10))
// 获取交易回执
const receipt = await client.getTransactionReceipt({ hash: TX_HASH })
console.log('\n=== 交易回执 ===')
console.log('状态:', receipt.status === 'success' ? '✓ 成功' : '✗ 失败')
console.log('Gas 实际使用:', receipt.gasUsed.toString())
console.log('事件数量:', receipt.logs.length)
console.log('\n=== 事件日志 ===')
receipt.logs.forEach((log, i) => {
console.log(`\n事件 ${i + 1}:`)
console.log(' 合约:', log.address)
console.log(' Topics[0]:', log.topics[0])
// 识别 Transfer 事件 (keccak256("Transfer(address,address,uint256)"))
if (log.topics[0] === '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') {
console.log(' 类型: Transfer 事件')
if (log.topics[1]) console.log(' From:', '0x' + log.topics[1].slice(26))
if (log.topics[2]) console.log(' To:', '0x' + log.topics[2].slice(26))
}
// 识别 SupplyCollateral 事件
else if (log.topics[0] === '0x...') { // 需要知道实际的事件签名
console.log(' 类型: SupplyCollateral 事件')
}
else {
console.log(' 类型: 未知事件')
}
console.log(' Data:', log.data.slice(0, 66) + (log.data.length > 66 ? '...' : ''))
})
// 解析函数选择器
const selector = tx.input.slice(0, 10)
console.log('\n=== 函数识别 ===')
const functionMap = {
'0x47e7ef24': 'deposit(address,uint256)',
'0xe8eda9df': 'supplyCollateral(address,uint256)',
'0x23b872dd': 'transferFrom(address,address,uint256)',
'0xf213159c': 'supply(uint256)',
'0x2e1a7d4d': 'withdraw(uint256)'
}
console.log('调用函数:', functionMap[selector] || '未知: ' + selector)
} catch (error) {
console.error('查询失败:', error.message)
}
}
main()