playground

The world is a playground.

Ethereum の Block Gas Limit を取得

この記事では Ethereum のブロックごとの Gas Limit を取得する方法をいくつか紹介します。

ちなみに Privatenet, Ropsten 上での Smart Contract のデプロイ時に  Exceeds block gas limit というエラーが出てかなり困っていたのですが、原因はネットワークによって Block Gas Limit が異なるということでした。(2018年5月4日現在、Mainnet ではおよそ 8000000、Ropsten では 4712388)

geth のコマンドで Block Gas Limit 取得

eth.getBlock("latest").gasLimit

geth の JSON RPC API で Block Gas Limit 取得

  • 次のサンプルでは、Infura を使用しています。
  • 次のコマンドを叩くと JSON が返されるので、そのなかの gasLimit の値をチェックします。
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"

etherscan で取得

メモ

  • Ethereum では、ブロックごとに miner の投票によって Gas Limit が変わる
  • ブロックの Gas Limit を超える Gas Limit を設定してトランザクションを実行しようとすると、Exceeds block gas limit というエラーが出る
  • 現在のところ、Mainnet での Block Gas Limit はおよそ 8000000
  • Ropsten では 4712388
    • どうやら、この値は固定されている模様
    • 16進数だと: 0x47e7c4
  • Mainnet と Ropsten で Block Gas Limit が異なることに注意!!
    • 僕はこれで数時間ハマった
    • Ropsten の gasLimit を上げないか?という Issue が作られている
  • Geth の起動時に --targetgaslimit で目標とする Block Gas Limit を設定できるので、開発時はこのフラグを活用するとよいと思います。
    • デフォルトは 4712388