I just learned today that you can query past events using the Web3.js 1.0.0 getPastEvents() function. That function supports filtering via the fromBlock and toBlock call parameters, so you can limit your query to a specific range of blocks:

getPastEvents("something", { fromBlock: 0, toBlock: "latest" }

Are there functions in Web3.js that can help you determine the from and to block numbers needed to cover a desired date range when calling getPastEvents()? Or is there another method/technique that works directly with dates instead of block numbers when querying for events that you can use instead of getPastEvents()?


There is no method for this in web3js 0.2x.x/1.0.0.

You can implement this by yourself, but you'll have to build-up the index for timestamps first. Alternatively, you could apply halving the interval method like when guessing numbers.

Your Answer

