0

I need to monitor contract events and perform off-chain processing. How do I uniquely identify a contract event? Can I use a combination of these fields? - transactionHash - transactionIndex - logIndex

I supposed I cannot use transactionHash alone because 1 transaction may emit multiple events. IMO, the documentation https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events doesn't describe the fields transactionIndex and logIndex well.

3

If two events are logged in one transaction, transactionIndex is going to be the same.

In my opinion, using transactionHash and logIndex should enable you to identify unique event logs.

  • Thanks. Can you also explain the meaning of these 2 fields transactionIndex and logIndex? – Thomas Jul 26 '18 at 13:58
  • The transactionIndex is the index of the transaction in the block. The logIndex is the index of the log in the block logs – Henk Jul 26 '18 at 15:47
  • Came here looking to verify that `${transactionhash}-${logIndex}` is unique to each log, thanks for nailing it down! – ohsully Jun 5 at 19:59
0

You can only uniquely identify an event within the context of a block. As per https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges, the logIndex refers to position within a block, so you'll probably have to go with blockHash+txHash+logIndex combo. If not, a reorg can happen, and the same combination of txHash+logIndex can refer to a different event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.