1

I want to decode the topics in the event log of all transactions in a contract.

With Etherscan, it seems like I can see the ABI for each event.

However, the ABI is not the same for each event. These are associated with an ERC-721 token.

So how do I get the right ABI for each event to decode its topics?

committer
  • 37
  • 1
  • 6

1 Answers1

1

There are a few different ways to do this. The simplest way is by taking the abi and address to create a Web3.js Contract object, then use getPastEvents to get a more human readable, pre-decoded version of the events.

Given an ABI, you can determine which event a log maps to by looking at the first topic of the log. The following from abi->event section of the Solidity documentation details the generation of topic 0 and how you can do it yourself:

topics[0]: keccak(EVENT_NAME+"("+EVENT_ARGS.map(canonical_type_of).join(",")+")") (canonical_type_of is a function that simply returns the canonical type of a given argument, e.g. for uint indexed foo, it would return uint256). If the event is declared as anonymous the topics[0] is not generated;
natewelch_
  • 12,021
  • 1
  • 29
  • 43
  • 1
    Thanks! I think this answer clarifies how event signatures are made in a more simplified way: https://ethereum.stackexchange.com/questions/7835/what-is-topics0-in-event-logs – committer Jun 29 '21 at 12:23