I want to know about how can i get ethereum blockchain network hash rate via geth console or web3.
Like the result of this api - https://www.etherchain.org/api/miningEstimator


The way of deriving the information can be found here. So via the console,

function getNetworkStats(
        sampleSize //!< [in] Larger n give more accurate numbers but with longer latency.
    ) {
    blockNum = eth.blockNumber; // Save this value to atomically get a block number.
    blockTime = (eth.getBlock(blockNum).timestamp - eth.getBlock(blockNum - sampleSize).timestamp) / sampleSize;
    difficulty = eth.getBlock(blockNum).difficulty; // You can sum up the last n-blocks and average; this is mathematically sound.

    return {
      "blocktime": blockTime,
      "difficulty": difficulty,
      "hashrate": difficulty / blockTime,

Values are in seconds, hashes, and hashes per second, respectively.


I have implemented the above method with python, and it feels about the same as the computing power of the whole network hashrate!

eth = create_rpc("ETH")
current_height = int(eth.eth_blockNumber(), 16)
sampleSize = 200
current_block = eth.eth_getBlockByNumber(hex(current_height), False)
pre_height = eth.eth_getBlockByNumber(hex(current_height - sampleSize), False)
current_height_time = int(current_block.get("timestamp"), 16)
pre_height_time = int(pre_height.get("timestamp"), 16)

avg_block_time = (current_height_time - pre_height_time) / sampleSize
print(int(current_block.get("difficulty"), 16) / avg_block_time / 1000000000000)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.