使用 decodeparameters 函数 解析币安链的 Transaction 日志数据

比如这个地址: https://bscscan.com/tx/0xbbd747324e51f543fe9b8e83a71f7aded49c3fd76ea2ef38637de995851b6543#eventlog

查看日志的时候,你会发现数据是加密的。
在这里插入图片描述
代码:

 let ss1 = `0x00000000000000000000000000000000000000000000000093845de66b9a30fe000000000000000000000000000000000000000000000000000e35fa931a00000000000000000000000000000000000000000000000000330ca85aa35d0afe280000000000000000000000000000000000000000000000000000000000000000`;

        console.log('web3', web3.eth.abi.decodeParameters([{
    
    
            type: 'uint256',
            name: 'amount0In'
        },{
    
    
            type: 'uint256',
            name: 'amount1In'
        },{
    
    
            type: 'uint256',
            name: 'amount0Out'
        },{
    
    
            type: 'uint256',
            name: 'amount1Out'
        }], ss1 ));

他这个数据结构需要你去定义。

得到结果:

web3 Result {
  '0': '10629724264730341630',
  '1': '4000000000000000',
  '2': '941696026341416828456',
  '3': '0',
  __length__: 4,
  amount0In: '10629724264730341630',
  amount1In: '4000000000000000',
  amount0Out: '941696026341416828456',
  amount1Out: '0'
}

这里有这个函数的使用方法: https://web3js.readthedocs.io/en/v1.5.2/web3-eth-abi.html#decodeparameters

猜你喜欢

转载自blog.csdn.net/milu2003516/article/details/122505504