10

Attaching a watcher for every instance of a contract is not a good idea in terms of memory and CPU. So is there a way to watch for events from all instances of a contract i.e., by registering a single watcher for all instances of the contract.

Note that I don't want to provide the address of the contract instances because that will force whole DB lookup.

I need to display the changes on the contract in real-time on the client and also update the DB in real-time.

3
  • 2
    cant you put in the event an indexed parameter that identifies the type of contract and then listen for events filtering on that indexed parameter ?
    – dragosb
    Jul 29, 2016 at 11:04
  • @dragosb you can at present only filter on addresses or arrays of addresses, so even if you broadcast the type of contract or address of contract on events, you couldn't find that event unless you were watching the address of that instance anyway.
    – bozzle
    Aug 23, 2016 at 3:00
  • That is just not true. You can filter events based on topics which are the indexed parameters...or maybe i am misunderstanding what you are saying
    – dragosb
    Aug 23, 2016 at 6:22

4 Answers 4

3

One possibility is that the contract could call a central "watcher" contract any time they wish to make a log, and then you need only watch the logs of that one contract.

1

To answer your question - no, unfortunately you can't capture events based on a class/contract - only on instances (addresses).

1

You can put in the event an indexed parameter that identifies the type of contract and then listen for events filtering on that indexed parameter.

Another way is to specify in the event as an indexed parameter your address so you can get all your contracts and then as a simple event data parameter specify the type of contract and the you can filter off chain by parsing the data part of the event.

0

A programmable monitoring system that ran off-chain, such as QuickBlocks can do this. QuickBlocks allows you to watch every block coming off your local node and do anything you want with it, including filter based on whatever C++ code you write to complete the filter.

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.