Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (12.7k points)

What is the difference between using myContract.getPastEvents() to get past events and using myContract.events.MyEvent({ fromBlock: 0, }) ?

Also, if I pass to fromBlock a block number that has not been mined yet, does it work as expected?

1 Answer

0 votes
by (29.5k points)
edited by

 In general, MyEvent lets you specify filters within a specific event type (you can filter by parameter values), whereas getPastEvents returns all events for an event type.
 
getPastEvents will return all events that have occurred up until the block number the node you’re connected to is synced to.

MyEvent will return those same events, plus will call the callback on any new events that occur as new blocks are added to the chain.

hope this makes things little more clear 

There is a lot more to learn than this. Enroll now in Blockchain Online Course to learn more.

Browse Categories

...