1

Is it possible to identify all the events occurred within a single transaction? I just want to group events by transaction, but looks like it is not possible. e.g. all the events have different transaction_hash, log_index etc. I'm using the python bindings.

1

You can list all the event logs from a transaction by getting its receipt. For example, see the two events in the logs attribute of this receipt:

In [1]: from web3.auto import w3

In [2]: w3.eth.getTransactionReceipt(0xf12438191fe6b9d8b6a8538db019b55530eaf2c8adfd60efed5582d0b9b105f8)
Out[2]: 
AttributeDict({'blockHash': HexBytes('0x7b3f60d80b0decdd81f6c440244339dfdf55c28c333d40e228f611249941c99e'),
 'blockNumber': 5810115,
 'contractAddress': None,
 'cumulativeGasUsed': 1790581,
 'gasUsed': 457319,
 'logs': [AttributeDict({'address': '0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef',
   'blockHash': HexBytes('0x7b3f60d80b0decdd81f6c440244339dfdf55c28c333d40e228f611249941c99e'),
   'blockNumber': 5810115,
   'data': '0x000000000000000000000000000000000000000000000000000000005b2e1471',
   'logIndex': 4,
   'topics': [HexBytes('0x87e97e825a1d1fa0c54e1d36c7506c1dea8b1efd451fe68b000cf96f7cf40003'),
    HexBytes('0x1420e66a1e668e86523b1a38a679ff5881780882d2643a4636650c4cc6df7491')],
   'transactionHash': HexBytes('0xf12438191fe6b9d8b6a8538db019b55530eaf2c8adfd60efed5582d0b9b105f8'),
   'transactionIndex': 60,
   'transactionLogIndex': '0x0',
   'type': 'mined'}),
  AttributeDict({'address': '0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef',
   'blockHash': HexBytes('0x7b3f60d80b0decdd81f6c440244339dfdf55c28c333d40e228f611249941c99e'),
   'blockNumber': 5810115,
   'data': '0x0000000000000000000000000000000000000000000000003782dace9d900000',
   'logIndex': 5,
   'topics': [HexBytes('0xb556ff269c1b6714f432c36431e2041d28436a73b6c3f19c021827bbdc6bfc29'),
    HexBytes('0xa5561362dcede2db42f5e9c2be06fd01930a452a43b740e0970325bc4c993794'),
    HexBytes('0x00000000000000000000000057b76fe5ed71dd788532df2ae2ea37bf67c4ade4')],
   'transactionHash': HexBytes('0xf12438191fe6b9d8b6a8538db019b55530eaf2c8adfd60efed5582d0b9b105f8'),
   'transactionIndex': 60,
   'transactionLogIndex': '0x1',
   'type': 'mined'})],
 'logsBloom': HexBytes('0x00000000000000008000000000000000000000080000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000200000000000000000000000000000000000000000000000000002000000000000000000001000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000001000000000000000000200000000001000100000000040000000000000000000004000000000000000800000000000000000000000000100000000000000000000000000000000000000100000000001000000000000'),
 'root': None,
 'status': 1,
 'transactionHash': HexBytes('0xf12438191fe6b9d8b6a8538db019b55530eaf2c8adfd60efed5582d0b9b105f8'),
 'transactionIndex': 60})

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.