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.
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. I'm doing that in NodeJS with ExpressJS and the Web3 version mentioned above.
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 : stringValue,
It doesn't catch the event anymore , same with c ( eg : no more 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 ?
Thank you for help & Have a nice day!
Thanks for your question, I tested it and I believe its a bug with filter
But I tried use topics
and it works
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.