'Newbie- API to get Ethereum's latest blocks
I am looking for an ethereum api to get the N latest blocks. I will use javascript (react) to make the requests.
I have looked into https://etherscan.io/apis#blocks but it has nothing to do with what I need (at least what I see there).
Also https://github.com/ethereum/wiki/wiki/JSON-RPC seems complicated to use as I will have CORS issues (?). And I don't see what I need there either
Thank you
Solution 1:[1]
I believe this might be something you're looking for?
This returns latest-n blocks of the ethereum network. It's currently limited to 100 blocks.
Solution 2:[2]
With Amberdata.io it's really easy you just:
curl -X GET \
'https://web3api.io/api/v2/blocks?size=10' \
-H 'x-api-key: '
And it will give you the last 10 blocks. You can try it out here.
Solution 3:[3]
You can use this one from The Graph and change first 10 to value of N.
API Endpoint: https://gateway.thegraph.com/api/[api-key]/subgraphs/id/4oZC8eETdHshzyMySbvaXmH8p44E6wCbEYsKaFuijhRK
query last10Blocks { blocks(first: 10, orderBy: BlockNum, orderDirection: desc) { BlockNum } }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Qkyrie |
Solution 2 | foba |
Solution 3 | kraphty23 |