5 web3js订阅solidity的event无法按照索引来检索

solidity中的event:

event OperationExecuted(string indexed _operationType);

其中_operationType取值为"AddRecord"或者"DeleteRecord" 我的目标是要检索indexed为"AddRecord"的事件

web3js的代码: 因为string作为索引时会转换为keccak(256)存储,所以我直接在filter中输入"AddRecord"的kecaak(256)的值。

myContract.getPastEvents('OperationExecuted',{
             filter:{_operationType:["0xe4e7eec3ca43ab41950c4cc5242bf7f9938f3d814419a7654ca8fdaa352dc4ca"]},
             fromBlock: 0,
             toBlock:'latest'}).then((res)=>{
                 console.log(res);
         })
         })

为什么检索好像失效了,得到的是包括了"AddRecord"和"DeleteRecord"的结果?

任何帮助都会被感谢,真心的!

请先 登录 后评论

最佳答案 2022-05-09 16:39

你试试用 Topic 来过滤, 因为加索引的数据实际是转为tipic的。

请先 登录 后评论

其它 0 个回答

  • 0 关注
  • 1 收藏,1281 浏览
  • 随心随行 提出于 2022-05-09 13:37

相似问题