0

Is there a way to get data similar to the ones provided by web3.eth.getBlock(blockNumber) but with multiple blocks at once?

The goal is to get the timestamps for 100 blocks in a row without performing 100 http calls to Infura. Thank you.

1

Take a look the wiki with all possible calls https://github.com/ethereum/wiki/wiki/JSON-RPC

There are two ways get block:

  • eth_getBlockByHash
  • eth_getBlockByNumber

But no way to get multiple blocks. You need to implement it by yourself.

1

You have batch requests if the client you are using support them.

var batch = web3.createBatch();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(web3.eth.contract(abi).at(address).balance.request(address, callback2));
batch.execute();

From the documentation:

Batch reqests are not faster! In fact making many requests at once will in some cases be faster, as requests are processed asynchronously. Batch requests are mainly useful to ensure the serial processing of requests.

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.