This service fetches an estimated gas price for which transaction could get mined in less than 5 minutes.
Two services are used for this purpose.
- Eth Gas Station
This service is used primarily. An API call is made to the below URL and gasPrices are parsed for usage.
(Source: 'https://ethgasstation.info/json/predictTable.json'). - Ether Chain
In case EthGasStation returns gasPrice as 0 or a price greater than the threshold, price is fetched from EtherChain.
(Source: 'https://www.etherchain.org/tools/gasPriceOracle').
Usage:
dynamicGasPriceProvider = require('@ostdotcom/ost-dynamic-gas-price');
chainId = 1; //main Ethereum Network
dynamicGasPriceProvider.dynamicGasPrice.get(chainId).then(function(val){
console.log("Gas Price In GWei", val);
});