6

I'm trying to get the latest block (it's height) using Ethereum Developer APIs of etherscan.

For example, I can get it from blockcypher using the following URL: https://api.blockcypher.com/v1/eth/main

(see the field "height")

Couldn't find a way to get this data from etherscan, is there and I'm missing it?

4 Answers 4

5

You can do this in two steps:

  1. Get the number of the latest block using:

    https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey=YourApiKeyToken

  2. get the block using:

    https://api.etherscan.io/api?module=block&action=getblockreward&blockno=2165403&apikey=YourApiKeyToken

    change blockno='value obtained from the previous step'

Hope this helps

0
9

Even easier:

https://api.blockcypher.com/v1/eth/main

Blockcypher is a pretty good api for this kind of stuff.

0

Or you can get the current timestamp from code (if you use python: current_timestamp = time.time()), then use the following URL:

https://api.etherscan.io/api ?module=block &action=getblocknobytime &timestamp=1578638524 &closest=before &apikey=YourApiKeyToken

replace 1578638524 with the current_timestamp you got.

0

You can get the latest block with just one call:

https://api.etherscan.io/api?module=proxy&action=eth_getBlockByNumber&tag=latest&boolean=true&apikey=YourApiKeyToken

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.