I am trying to get the list of all ERC20 token transfers made in a block including contract address, from, to, and value.
The list should be something like this:
{
blockNumber: 15000000
contracts: [
{
contractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7",
transfers: [
{
from: "0x2aea2358a1e596380d80e17359acfa0c75f94c9e",
to: "0x80e17359acfa0c75f94c9e2aea2358a1e596380d",
value: "0x997fa227"
}
...
]
}
...
]
}
Is this possible? If so, how?
What I Have Tried
There are many ways to transfer tokens in Ethereum. The simplest way is to use the "transfer" method almost all of the ERC20 contracts include.
If this was the only way, it would have been easy. Simply scan for all transfer method calls for every contract among the transfer list in the block. However, that doesn't work because some contracts have other methods that make token transfers such as "transferFrom". There is no unified way that ERC20 contracts change their balance collection.
If only the same contract had the power to change its balance list, this would be tedious but still possible. However, there are many ways to make token transfers such as calling transfer methods of contracts from other contracts or using decentralized exchanges. Therefore scanning all method calls of a contract fails to capture all token transfers.
What am I missing?
Transfer
of ERC20 token. Scan eventTransfer
in one block to get all tx transfer token. Here it is: docs.openzeppelin.com/contracts/4.x/api/token/…Transfer
s in a block?getPastLogs
with args:from: your_block_number
,to: your_block_number
, topic:converted_Transfer_event