I need a complete in-order list of every event emitted by a specific contract, the list needs to be updated as each block is mined and it needs to be able to handle a chain reorganization gracefully (waiting for N confirmations isn't acceptable). The list is persisted to disk and needs to support resuming where it left off.

The part I'm having the most trouble with is how to detect when a reorg has occurred and determining which events needs to be rollback'd.


2 Answers 2


You can use Alchemy's subscription to listen to events on chain, here.

This should return a JSON object, easy enough to work with in deducing whichever logs/events you are looking for :)

  • Can Alchemy listen to changes in Twitter statistics, i.e. follower count or engagement from specific user, and convert that into input data to an Ethereum smart contract?
    – user610620
    Dec 16, 2022 at 23:40

From what I know you can't handle reorg events/blocks just by using web3.js or web3.py. You will need to monitor the blocks and their difficulty using an RPC node and filter the events to update your database according to reorg.

I personally use 3rd party API services like Morlais to get the historic and real-time events. And Moralis auto-corrects the historic API data based on the reorgs.

In case you want to try Moralis Events API to get historic events you can refer to the below API reference docs: https://docs.moralis.io/web3-data-api/reference/get-contract-events

For real-time events, you can use Streams API. When using streams API you will know if a block is dropped due to reorg after waiting for N block confirmations.

To know more about using streams API for getting real-time events refer to the below docs: https://docs.moralis.io/streams-api

I hope this helps.

Your Answer

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

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