LoginSignup
5
7

More than 5 years have passed since last update.

Ethereum の Block Gas Limit を取得

Last updated at Posted at 2018-05-04

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

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

参考

Note

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7