6

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?

0

1 Answer 1

5

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.
4
  • 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, 2016 at 17:49
  • 1
    Have you looked at just parsing the blockchain into mongo Mar 1, 2016 at 20:08
  • that looks much more like what I want to do - thank you very much!
    – James B
    Mar 2, 2016 at 7:46
  • Is it going to impact geth server performance if I attach millions of watchers for an event? Jun 7, 2016 at 12:00

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.