4

I am building a system that monitors ERC20 token deposits to a large number of ethereum addresses (1-4 million). While I have not tried, I do not think that the parity clients would be able to support such a large amount of filters. I intend to build a customised data structure in order to achieve this task. Therefore, I would like to acquire the logs of all transactions in a block. Is there a way to do so?

This question is related to How to programmatically detect and accept ETH and ERC20 deposits

However, answers to the above post have not adequately addressed my concern about scalability.


What I have tried:

I am currently scanning the whole block for transaction hashes and then using eth_getTransactionReceipt to acquire the logs for each transaction. The pseudocode is as follows:

@parallel
for block in all blocks:
  all_tx = get_all_txs(block);
  for tx in all_tx:
    save_in_db(eth_getTransactionReceipt(tx).getlogs())

I am wondering if there is a better way to retrieve the logs, perhaps retrieving all logs at once?

2 Answers 2

1

See eth_getLogs: https://github.com/paritytech/parity/wiki/JSONRPC-eth-module#eth_getlogs

There you have possibility to filter only logs from ERC20 using topics.

1

You can use the eth_getLogs method to pull logs from blocks.

If you want to get all of the logs emitted by all of the transactions in a block, you can run the eth_getLogs, leaving only the block (fromBlock and toBlock) you need in the filter.

Here is an example in cURL:

curl 'YOUR_NODE_ENDPOINT' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "latest",
      "toBlock": "latest"
    }
  ],
  "id": 1,
  "jsonrpc": "2.0"
}'

This setup will retrieve all of the logs emitted in the specified block.

You can see more examples on the Chainstack docs | eth_getLogs, or learn more about logs in general reading Tracking some Bored Apes: The Ethereum event logs tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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