Reputation: 10417
Parity UI displays current block number at the bottom, but if UI is not enabled, then how do we find the current block number?
Is there a way to find current block number
Note: If anyone can find proper tags, please update it! Currently there is no tag for parity
.
Upvotes: 3
Views: 3679
Reputation: 10417
Using the answer posted by @carver I was able to get only the current block number in decimal form, my RPC port is 8545(default):
echo $((`curl --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 | grep -oh "\w*0x\w*"`))
Upvotes: 2
Reputation: 2349
You can get the latest block number over rpc by calling the 'eth_blockNumber' method.
From the JSON RPC docs:
Returns the number of most recent block.
// Request curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' // Result { "id":83, "jsonrpc": "2.0", "result": "0x4b7" // 1207 }
There are other, higher level APIs that you might be interested in, like web3.js or web3.py. They both allow you to use web3.eth.blockNumber
to get the latest block number, and generally work in native types rather than hex strings.
Upvotes: 2