ERC20 Transfers – How to List All Transfers to a Specific ETH Address

erc-20etherscantransactions

I'm trying to pull up a list of all incoming transfers to an ETH address. The research I've done seems to indicate this can be done via etherscan using the logs module. (https://docs.etherscan.io/api-endpoints/logs).

However I do not know how to produce the parameters the API requires.

As an example, say I want to list all MATIC transfers to an address.

The MATIC contract address is 0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0
The destination address is 0xBcef3db86DCcDa6CA1fdBba91Abd525c8D3BF363

How do I take this information and produce the topic_0 and topic_1 parameters for the API request?

Thanks,
Peter

Best Answer

Ok, after some research. topic_0 is the hash of the event signature. I used https://emn178.github.io/online-tools/keccak_256.html to generate the hash.

In this case the event I want is Transfer(address,address,uint256) and the hash is ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

topic_1 is the 1st parameter of the method, which is the from address. I don't want to specify this. Instead I want to specify the to address which is topic_2. topic_2 must be 66 chars, so I padded the destination address with zeros. So topic_2=0x000000000000000000000000Bcef3db86DCcDa6CA1fdBba91Abd525c8D3BF363

This gives me a list of all ERC20 tokens transferred to the destination address. Now I need to figure out how to tell what token and how many were transferred for each record.

Related Topic