200 web3js如何解析V3路由的exactInput参数详情

exactInput(0xb858183f) 输入参数是一个params参数,tuple类型的,如图

332.png 该功能在合约代码 IV3SwapRouter.sol 文件中有定义,如图

image.png 目标交易哈希:0x7f4e5546584485c785d4b2068d093d5b594c3383f17d45ad5b4c1401260c443f 从muticall中解析到的0xb858183f开头的原始数据如下: 0xb858183f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000005f8a8d77c5fe0894de0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002be9e7cea3dedca5984780bafc599bd69add087d560001f4bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000000000000000000000

解析代码: let raw = '0xb858183f开头的原始数据' let params = web3.eth.abi.decodeParameters([ { type: 'bytes', name: 'path' }, { type: 'address', name: 'recipient' }, { type: 'uint256', name: 'amountIn' }, { type: 'uint256', name: 'amountOutMinimum' } ], raw.substr(10)) console.log(params)

打印结果 Result { '0': '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000005f8a8d77c5fe0894de0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b', '1': '0x0000000000000000000000000000000000000080', '2': '2', '3': '1762424454643611899102', length: 4, path: '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000005f8a8d77c5fe0894de0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b', recipient: '0x0000000000000000000000000000000000000080', amountIn: '2', amountOutMinimum: '1762424454643611899102' } 输出的结果明显是不对的。

有哪个大牛知道这个参数的详情如何用web3js解析出来?除了自己手写解析代码,因为不稳定,容易出现意外情况出错。

请先 登录 后评论

最佳答案 2023-06-10 15:21

你贴的data, 看起来有问题,不然你解析出来的应该也正确 从muticall中解析到的0xb858183f开头的原始数据如下

请先 登录 后评论

其它 1 个回答

zen
请先 登录 后评论
  • 0 关注
  • 0 收藏,1867 浏览
  • halashaoge 提出于 2023-05-25 21:25