- 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
- Ethereum 関連の情報は https://scrapbox.io/sushiether/ に集約することにしました。
- この記事の内容に変更・更新がある場合は、以下の URL を更新します。
- https://scrapbox.io/sushiether/Ethereum_の適切な_Gas_Price_を取得する