solidity – How to Recognize Anonymous Events in Logs

eventslogssolidity

Is there any way to recognize if a log contains an anonymous topic? From what I can tell is that anonymous events are represented in a log without the signature on the first index. Giving the option to include 4 instead of 3 topics. That would be a way to recognize them, however what if an anonymous event generates a log with less than 4 topics?

I need to find a couple of logs with anonymous events so that I can study them.

Best Answer

In a non-anonymous event, topics[0] will be the signature of the event name. In an anonymous event, the signature of the event name is not a topic.

If you have access to the ABI or the source code of the contract, here is what you could do:

  1. Find the signature hash of the event name.
  2. Check if topics[0] is equal to this signature. If not, you have an anonymous event.

If you don't have access to the ABI or the source code, I don't think that it is possible because there is no way to know if topics[0] is the event name signature or a bytes32 indexed argument.

On a side-note, the JSON ABI would indicate if an event is anonymous (see the docs).

Related Topic