0

I want to check whether my full node has historical logs correctly stored.

How can I query historical ERC-20 transfer events, or any historical Solidity events, using UNIX curl command?

1 Answer 1

0

You can query ERC-20 logs by their topic field 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef.

Here is an example JSON-RPC query to get Transfer events between blocks 10,100,100 - 10,100,999 on any EVM compatible blockchain:

curl \
    "https://mynode.example.com"  \
    --location \
    --header 'Content-Type: application/json' \
    --request POST \
    --data-raw '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],"fromBlock": 10100100,"toBlock":10100999,"id":1}'

The correct result looks like:

{"jsonrpc":"2.0","id":1,"result":[{"address":"0xe9e7cea3dedca5984780bafc599bd69add087d56","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000f83bf708c3e3bd57f24411f6fc67f5","0x000000000000000000000000d14e0b9eba0010e97f57cbd9042215499b53bc47"],"data":"0x000000000000000000000000000000000000000000000048f769c2b768980000","blockNumber":"0x188cad2","transactionHash":"0x1df61528ae4a3c4cc0435e732597b75bf15e5aafdea1d9abfd0588f62fde1e08","transactionIndex":"0x0","blockHash":"0xf398c8b6f2ea74dc0e8fcd83acce91abd128d1ca9dc94ff4e0aabedae3079ee4","logIndex":"0x0","removed":false},{"address":"0x4136129ac3ac90cf9817548b24d35e73e9457e05","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000d14e0b9eba0010e97f57cbd9042215499b53bc47","0x0000000000000000000000000000000000f83bf708c3e3bd57f24411f6fc67f5"],"data":"0x00000000000000000000000000000000000000000000000608a52c2254c572c6","blockNumber":"0x188cad2","transactionHash":"0x1df61528ae4a3c4cc0435e732597b75bf15e5aafdea1d9abfd0588f62fde1e08","transactionIndex":"0x0","blockHash":"0xf398c8b6f2ea74dc0e8fcd83acce91abd128d1ca9dc94ff4e0aabedae3079ee4","logIndex":"0x1","removed":false},...

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.