从tx返回的logs中获取数据

图1 image.png

图2

image.png

问题描述:从一笔交易tx中,需要从tx返回的hex数据中,抽取出amountIn和amountOut,请问要怎么处理啊? 使用ethers.js

请先 登录 后评论

最佳答案 2021-12-25 19:27

像这样:

const SwapABI = ["event Swap(address indexed sender,uint amount0In,uint amount1In,uint amount0Out,uint amount1Out,address indexed to)"];

  const swapEvent = new ethers.utils.Interface(SwapABI);

  swapData = swapEvent.parseLog(logs)     

 swapData.args.amount0In.toString()
 swapData.args.amount1Out.toString()
请先 登录 后评论

其它 1 个回答

Priest
请先 登录 后评论