ERC-20 – Standard for Listening to Token Events

erc-20eventsweb3js

Hi I am a bit confused here. The official EIP documentation states that

event Transfer(address indexed _from, address indexed _to, uint256 _value)

is how the Transfer event should look like. If I am trying to listen to this event in web3, I will be looking for the keys that are mentioned in this interface namely _from, _to and _value.

I checked out a few of the top ERC20 contracts and they all have different key names in the event. From skipping the _ to completely changing value to amount. If I am listening to transfer events from multiple tokens, is there a way I can generalize this. Can I get value at a position by being key-name agnostic?

Best Answer

The order of arguments is always the same, though their names may vary. Also, you are supplying your own ABI file, so you most likely use argument names given in that ABI file. The EVM/Solidity wire protocol hashes only argument types, not their names, so the actual name is irrelevant in the raw blockchain data.

A lot of tokens were deployed before ERC-20 standard was anywhere near the final form, so there are quirks with legacy tokens.

The "hard" signature of Transfer event is 32-bit word, bytes 0-4 of:

 keccak("Transfer(address,address,uint256)")

The payload is 3x 256-bit words, as almost every value in EVM is 256-bit:

- address 1 
- address 2
- amount