Etherscan API – How to Get the Latest Block Using Etherscan API

blocksetherscan

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?

Best Answer

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

Related Topic