1import { NETWORK_TYPES } from './network';
2import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
4export default async function getSuggestedGasPrice(networkType) {
6 case NETWORK_TYPES.ROPSTEN:
8 case NETWORK_TYPES.OFFLINE:
9 return DEFAULT_GAS_PRICE_GWEI;
10 case NETWORK_TYPES.LOCAL:
13 const response = await fetch(
14 'https://api.etherscan.io/api' +
15 '?module=gastracker' +
17 '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
24 const json = await response.json();
26 if (json && json.status !== '1') {
27 console.warn('suggested gas price warning', json.message);
30 const suggestedGasPrice = parseInt(
31 json && json.result && json.result.ProposeGasPrice
33 if (isNaN(suggestedGasPrice)) {
34 throw new Error('strange gas price response', json);
37 // safeguard against obscene suggestions
38 return Math.min(suggestedGasPrice, MAX_GAS_PRICE_GWEI);
40 console.warn('error fetching gas price', e);
41 return DEFAULT_GAS_PRICE_GWEI;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list