Skip to content

Get logs based on event name #1368

Answered by ricmoo
sshmaxime asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the Contract API which understands how to build the ABI encoded structures you need. Then you can just use contract.queryFilter("ContertUpgrade", fromBlock, toBlock) to get a list of the events, which will also include all the values parsed and decoded for you.

But if you just want to do things like this, the way Solidity emits an event is by using the hash of the normalized event name as the first topic. So, for example, if your method was function foo(address bar) you would use the hash ethers.utils.id("foo(address)"). You can look through here to learn more about how events are processed internally, but I highly recommend you just use the Contract API. :)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1351 on March 15, 2021 23:50.