I'm trying to understand how .getPastEvents function works. When given block range to search is {fromBlock:0, toBlock: 'latest'} it finds my events almost instantaneously. Shouldn't filtering all 7M blocks (using Ropsten testnet) take more than a second? Code snippet if it's of any use.

myContract.getPastEvents("EventName", {fromBlock:0, toBlock: 'latest'}).then( 
  function(event) {
    event.forEach(element => {
      //doing some logic here
  • 1
    Without really knowing how it works I can just say that if it's "too quick" it probably means that the data is stored in an efficient way and it's not just simply looping through all blocks and checking each event. Although that might also work as 7M records is really not much when you can do all the looping locally. – Lauri Peltonen Jan 6 '20 at 18:14
  • 1
    Ethereum uses bloom filters for searching events ethereum.stackexchange.com/questions/3418/… – Ismael Jan 6 '20 at 19:16
  • 1
    You should check if it's really getting all your events. Sometimes the event queries only check the last X blocks, but it won't actually tell you. – wtk219 Jan 6 '20 at 19:55
  • @Ismael thanks. Seems like that's it, thanks. Still surprised how efficient it is then – JuztBe Jan 6 '20 at 20:26
  • @wtk219 Thanks for heads up, will have to do some extensive testing. Currently there's not that many events to miss – JuztBe Jan 6 '20 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.