0

I'm looking to get my hands on a historical block -> timestamp mapping. Although it's possible to get this data using web3.eth.getBlock it's rather costly to do it for all individual blocks.

Since this was likely done thousands of times before, there must (hopium) likely be some open source csv, 3rd party api, or something that supplies this data in an easier way.

Anyone?

0

You could use Infura's API. Specifically, you should look into the "getBlockByNumber" section. You will need to register a new free account and get an API key to be able to use the endpoint.

Example query from the docs:

curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params": ["0x5BAD55",false],"id":1}'

Note: block number param is given in hex format in example above.

Then, you could batch the API requests in JavaScript by following the steps detailed in the top answer here.

3
  • Does 'params' take more than 1 blockNumber? It's not clear from the docs
    – Geert-Jan
    Jun 14 at 7:08
  • I don't think it does. You'll need to multiple queries (each with a block number) and batch them all in parallel for minimal latency. Jun 14 at 8:35
  • Yeah ok, but that's still 1 req / block unfortunately. I'm running an archive blockchain, so could do the same locally, but was looking for something like getBlocks(from, to) or something.
    – Geert-Jan
    Jun 14 at 16:09

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.