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()?

1 Answer 1


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

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.