LoginSignup
6
5

More than 5 years have passed since last update.

Ethereum の適切な Gas Price を取得する

Last updated at Posted at 2018-05-17
  • Web3.js の eth.getGasPrice メソッドを使用することで、過去数ブロックの GasPrice の中央値を取得することができる
  • ドキュメント
  • 以下の例は web3 version 0.20.x

サンプルコード

var web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io'));
web3.eth.getGasPrice(function(error, result) {
  console.log(result.toString(10));
  var gasPriceInGwei = web3.fromWei(result, 'gwei');
  console.log(gasPriceInGwei);
});

実際に動いているデモ

Note

6
5
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
6
5