简体   繁体   English

如何按字符串参数web3 2.0.0-alpha.1 Solidity事件过滤?

[英]How to filter by string parameter , web3 2.0.0-alpha.1 Solidity events?

I'm trying to filter some events , and I noticed since I updated the web3 to version 2.0.0-alpha 1 the event catch is a little bit different. 我正在尝试过滤一些事件,并且我注意到自从将web3更新为2.0.0-alpha 1版本以来,事件捕获有些不同。

I have a Smart Contract with this event : 我与此活动有智能合约:

event catchMeIfYouCan (address indexed a, string indexed b, uint indexed c);

And I want to filter by its parameters , so far so good. 到目前为止,我想按其参数进行过滤。 But when I try to filter by b ( the string indexed ) , this is not working. 但是,当我尝试按b(索引的字符串)进行过滤时,此方法不起作用。 I'm doing that in NodeJS with ExpressJS and the Web3 version mentioned above. 我在带有ExpressJS和上面提到的Web3版本的NodeJS中这样做。

If I do that : 如果我这样做:

const event = smartContract.events.catchMeIfYouCan({ filter : {
 a : accountAddress ,
 b : web3.utils.toHex(stringValue) ,
 c : web3.utils.toWei("" + numberValue) } 
}, (error, event) => {
 // do some things
});

I get : 我得到:

Node error: {"code":-32602,"message":"invalid argument 1: hex has invalid length 96 after decoding"}

Otherwise , if I let the b parameter , in NodeJS event catch as : 否则,如果我让b参数在NodeJS事件中捕获为:

 b : stringValue,

It doesn't catch the event anymore , same with c ( eg : no more web3.utils.toWei() ). 它不再捕获事件,与c相同(例如:no web3.utils.toWei() )。

So , my question is : Do you have any idea how to filter the event by a string parameter in Web3 2.0.0-Alpha 1 version ? 因此,我的问题是:您是否知道如何在Web3 2.0.0-Alpha 1版本中通过字符串参数过滤事件?

Thank you for help & Have a nice day! 谢谢您的帮助,祝您有美好的一天!

Thanks for your question, I tested it and I believe its a bug with filter 感谢您的问题,我对其进行了测试,并相信它是带有filter的错误

But I tried use topics and it works 但是我尝试使用topics并且有效

  contract.events.CatchMeIfYouCan({
    topics: [, web3.utils.sha3(stringValue)], // first element is empty, because its place for `address` index
    fromBlock: 2000000
  }, (error, event) => {
    console.log(event)
  })

So, I created an issue in web3.js repo 因此,我在web3.js库中创建了一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM