Does a contract address have to specified to watch for an event? Or, can I register an event handler for every time contracts of a certain type are transacted?


Events are stored in the transaction log associated with the address of the deployed contract instance. You need to know the addresses of the contracts you want to listen to and cannot simply listen to the whole blockchain looking for an event of some class produced by a contract of some class. Indeed, even if it were possible, you probably wouldn't want to do this since multiple Dapps may be using contracts with identical signatures for completely different purposes, so there the events would not have the same meaning.

You could however work around it by:

  • A register contract - holds the addresses of all contracts of a specific type within your Dapp. You then register event handlers to watch all registered contracts.
  • A common logging contract - sub contracts call a function on this singleton service in order to raise events. Your event handler just needs to watch this contract.
| improve this answer | |
  • thanks for the answer that's very helpful. I'm working on a POC to store blockchain transactions in a graph database - I wonder if the contract should fire the event, and then I monitor the log file output to generate my inserts? – James B Mar 1 '16 at 17:49
  • 1
    Have you looked at just parsing the blockchain into mongo – JackWinters Mar 1 '16 at 20:08
  • that looks much more like what I want to do - thank you very much! – James B Mar 2 '16 at 7:46
  • Is it going to impact geth server performance if I attach millions of watchers for an event? – Narayan Prusty Jun 7 '16 at 12:00

Your Answer

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

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