3

I'm currently developing a Java application which communicates with Geth using JSON-RPC.

I managed to implement something like @rustyx suggested on this thread using an HTTP connection, but it's too slow.
On my machine, the time to retrieve all the transactions for an account in a 1000 blocks range is approximately 100 seconds.

I know Etherscan's API is able to return the last 10'000 transactions made by an account, but you will need a API key and you have limited requests per day. Using an indexer could do the trick, but it's heavy and quite complex to implement.

So, i was wondering, is there any efficient way to retrieve all the transactions for a given account through a series of JSON-RPC requests? Is it possible to implement by myself a eth_listTransactions method? Could using a lower level programming language (like C) reduce the processing time?

Note: With 'addresses' I'm referring to wallet addresses, not contracts addresses.

2 Answers 2

0

you can use getPastEvents for the Transfer event and also specify block range from first block to latest

js version:

      const latest = await web3.eth.getBlockNumber(),
      contract = new web3.eth.Contract(abi, contractAddress),
      logs = await contract.getPastEvents(
                "Transfer", 
                {
                  fromBlock: 0,
                  toBlock: latest,
                  filter:
                     eventType === EventType.send ?
                                { from: address } : { to: address },
                 }
              );
2
0

This is not a "native" RPC method but Alchemy does the job with the endpoint alchemy_getAssetTransfers. If you want the raw transactions (logs) you can get the txn hashes from that endpoint and later call eth_getTransactionByHash and/or eth_getTransactionReceipt for each txn hash. You will need to register but the free account is still pretty good and you won't need to iterate over blocks. The speed will depend on your internet connection and if you use concurrent requests. It's not CPU/memmory intensive so I don't think that using C will improve the performance.

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.