I am developing an ethereum block explorer in PHP and have established an JSON-RPC communication with my server geth node successfully. Nevertheless, I am kind of stuck when trying to find out the last block in ethereum. I have read the great info at https://ethereum.gitbooks.io/frontier-guide/content/rpc.html but I don't find there any way to ask the ethereum node which one is the last block. Once I had the block hash I see there are endpoints to retrieve full information about the block, but I don't know how to find the latest block hash.
The API endpoint eth_blockNumber is supposed to return the latest block number, but how do I get the hash?
Any help? Thanks in advance!
Best Answer
request:
response:
(I've formatted the results for easier reading).
I've used "latest" to find the latest block. You could also use the result from your
eth_blockNumber
call.Source: JSON-RPC - eth_getBlockByNumber.