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?
1 Answer
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.
-
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 BMar 1, 2016 at 17:49
-
1
-
-
Is it going to impact geth server performance if I attach millions of watchers for an event? Jun 7, 2016 at 12:00