0

I am trying to see how I can subscribe to an events on the Ethereum blockchain and I can only see polling mechanism and no push mechansim

I am look at the documentation for the JSON RPC endpoints here https://ethereum.github.io/execution-apis/api-documentation/

I can see given the combination of eth_newFilter, eth_getFilterChanges, eth_getFilterLogs, it is possible to register a filter on an RPC node and poll for changes.

What if I dont want to poll but require a push mechanism? How can that be done? I dont see any endpoint with names containing things like subscribe, listen etc so not sure how to go about this.

1
  • Not sure there is one. Note this protocol isn't part of the blockchain - it's auxiliary - so someone might create one in the future. I think most people probably do it by polling the latest block number quickly, then if the block number changes then you fetch everything else.
    – user253751
    Dec 29, 2022 at 15:14

1 Answer 1

0

The blockchain has no concept of "pushing" data to clients. It simply emits data (events) withing blocks and clients can poll the blocks to see whether the newest block has some data they are interested in.

However, some service may be able to offer such functionality. So the service would do the polling and when it finds the data you are looking for it'd push the data to your listener. Unfortunately, I'm not sure if such a service exists. Furthermore, if you do find and use such a service, you a relying in the service to stay up and provide you with the data you need. But this might not be a big issue - usually you rely on some external service (such as Infura or Alchemy) anyway to provide you with blockchain data.

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.