- 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); });