How to get Ethereum Block Gas Limit

There are several ways.

Geth command

If you run your Geth node, you can just run the following command.

eth.getBlock("latest").gasLimit

Geth JSON RPC API

You can get Ethereum Block Gas Limit through JSON RPC API as well.

If you run the example command below, you will get a JSON response. In the JSON response, you can check gasLimit value.

curl -i -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", true],"id":1}' \
"https://mainnet.infura.io/YOUR_API_KEY"

Web3.js

With web3.js, you can get Block Gas Limit by following code.

web3.eth.getBlock("latest", false, (error, result) => {
console.log(result.gasLimit)
// => 8000029
});

Etherscan

The easiest way ;)

Memos

  • In Ethereum, Block Gas Limit is changed in every block. The new Block Gas Limit is decided by algorithm and vote by miners.
  • If you try to send a transaction with Gas Limit which exceeds Block Gas Limit, the “Exceeds block gas limit” error shows.
  • Currently (May 4th 2018), Block Gas Limit in mainnet is about 8000000.
  • In Ropsten, 4712388. It looks like fixed.
  • NOTE: Block Gas Limit is different between Mainnet and Ropsten.
  • I spent few hours because of this difference.
  • When you run Geth, you can use “ — targetgaslimit” to set Block Gas Limit target. This can help you when you develop/test with your own private chain. By default, targetgaslimit is 4712388.

Reference

Support

If you find this article is helpful, it would be greatly appreciated if you could tip Ether to the address below. Thank you!

0x0089d53F703f7E0843953D48133f74cE247184c2