1

As suggest in What is topics[0] in Event logs? I am trying to find out 'Event hash' but it's not matching the output for below transaction.

Input Data

Function: transfer(address _to, uint256 _value) ***

MethodID: 0xa9059cbb
[0]:0000000000000000000000000d2b2fb39b10cd50cab7aa8e834879069ab1a8d4
[1]:0000000000000000000000000000000000000000000000000000010e6a06cb00

Event Logs

Topics
[0] 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
[1] 0x0000000000000000000000004dc8f417d4eb731d179a0f08b1feaf25216cefd0
[2] 0x0000000000000000000000000d2b2fb39b10cd50cab7aa8e834879069ab1a8d4

However when I try to find the keccak hash it's showing different hash.

  from Crypto.Hash import keccak
  keccak_hash = keccak.new(digest_bits=256)
  keccak_hash.update("transfer(address,uint256)")
  print keccak_hash.hexdigest()

>>a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b
2

topics[0] is the hash of the event signature, which in your case is Transfer(address,address,uint256) for an ERC20 Transfer event. If you take the keccak hash of that you can confirm.

You've taken the hash of the transfer() function signature. Its first four bytes a9059cbb correctly give you the MethodID of the transfer() function, but that's something different and not related in any way to the Transfer EventID that is topics[0].

  • thx, it matches now, but how you got to know the Event signature given that it is not defined and input data only shows the transfer function. – garg10may Sep 19 '17 at 7:26
  • For ERC20 the event signatures are defined by the standard. For other event types you need access to the source code to calculate the EventID or to find out what the event means. – benjaminion Sep 19 '17 at 7:49
  • oh ok, so for all contracts the transfer topics will have same hashes. Actually I wanted topic signature so that can filter events bcoz event logs are huge, but still they will be huge bcoz tranfer events would be large in number. – garg10may Sep 19 '17 at 7:54
0
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

is exactly sha3 hashing of event signature Transfer(address,address,uint256) - an ERC20 token event signature. Give a try to use sha3 hashing utility of web3 to verify this. Besides, topics[1] and topics[2] are indexed params of events, in this case, they're your from address value and to address value.

Each contract may define a list of different events. However, if the contract is written based on ERC20 standard, it will contain standard events of ERC20 and these events give the same signatures for all contracts and certainly give the same event signature hashing value.

Back to this input:

MethodID: 0xa9059cbb
[0]:0000000000000000000000000d2b2fb39b10cd50cab7aa8e834879069ab1a8d4
[1]:0000000000000000000000000000000000000000000000000000010e6a06cb00

0000000000000000000000000000000000000000000000000000010e6a06cb00 is logs data as known as token amount in this transfer. and 0000000000000000000000000d2b2fb39b10cd50cab7aa8e834879069ab1a8d4 is clearly to address in this transaction.

0

Check

https://emn178.github.io/online-tools/keccak_256.html

provide input Transfer(address,address,uint256)

you will get output ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

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.