2

When we invoke an event as follows :

event MyEvent(uint256 indexed _id, bytes32 _action, bytes32 _player, bytes32 _actionState,  address _owner);

emit MyEvent(uint256(_public_id), bytes32(_action), bytes32(_player), bytes32(_actionState), _owner);

In EtherScan, we see an output as follows :

EtherScan Event Log

What does Topics [0] 0x22b8025a23f25c3f52cdbc1f53a831dbd4e3b4aaeebe121d36c858abea974bc7 mean ?

In case of MyEvent, [1] 0x0000000000000000000000000000000000000000000000000000000000000001 means _public_id = 1

However, I do not know 0x22b8025a23f25c3f52cdbc1f53a831dbd4e3b4aaeebe121d36c858abea974bc7 comes from where ? and in general, the term of Topics what does it mean ?

3
  • @Ismael, Yeah u'r right, I did not see that question .... Sorry....
    – Questioner
    May 24, 2018 at 13:15
  • @Ismael However, I think the answer of user Lbrth_BoC is more related to what I expected. Thanks
    – Questioner
    May 24, 2018 at 13:30
  • @Ismael If you want to delete this question you can do it, but i think it would be better to keep answer of user Lbrth_BoC. Thanks
    – Questioner
    May 24, 2018 at 13:38

1 Answer 1

9

In a transaction receipt the fied topics correspond to your event arguments which are indexed in your smart contract. For all events you will find as first argument the hash of the event name, and then the data which are indexed in hexabytes.

So in your case, in topics you will find

'topics':[hash_event_name,// w3.sha3(text='myEvent(uint256)').hex() where Event name without input argumentsname
         0x000000...000000001//your first argument '_id' because is indexed 
         ]

All of your event arguments which are not indexed are stored in the data part of the transaction receipt

6
  • Are you sure about this part? sha('MyEvent(uint256'))
    – mesqueeb
    May 25, 2018 at 8:29
  • With web3.py the correct thing is : event_signature_hash = w3.sha3(text='MyEvent(uint256)').hex() #Event name without input arguments
    – Lbrth_BoC
    May 25, 2018 at 8:33
  • 2
    Yes because you input the name of your arguments inside the sha3 functions. So, you should get the correct hash with : web3.utils.sha3('TokenSold(uint256, uint256, uint256, address, address, string)'). Add only the type of your variable
    – Lbrth_BoC
    May 25, 2018 at 8:38
  • 1
    Thanks so much! I got the correct hash with your solution but without the spaces! Cheers mate!!
    – mesqueeb
    May 25, 2018 at 8:39
  • 1
    you welcome ! I remember than I spent a couple of hours to get the correct hash too
    – Lbrth_BoC
    May 25, 2018 at 8:42

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