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?

1 Answer 1

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;
1

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.