@@ -11,7 +11,10 @@ export default async function getSuggestedGasPrice(networkType) {
1111 default:
1212 try {
1313 const response = await fetch(
14− 'https://ethgasstation.info/json/ethgasAPI.json',
14+ 'https://api.etherscan.io/api' +
15+ '?module=gastracker' +
16+ '&action=gasoracle' +
17+ '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
1518 {
1619 method: 'GET',
1720 cache: 'no-cache',
@@ -20,13 +23,21 @@ export default async function getSuggestedGasPrice(networkType) {
2023
2124 const json = await response.json();
2225
23− // ethgasstation returns values in floating point, one order of magitude
24− // more than gwei. see: https://docs.ethgasstation.info
25− const suggestedGasPrice = Math.ceil(json.fast / 10); // to gwei
26+ if (json && json.status !== '1') {
27+ console.warn('suggested gas price warning', json.message);
28+ }
2629
27− // we don't want to charge users more than the gas tank funds
30+ const suggestedGasPrice = parseInt(
31+ json && json.result && json.result.ProposeGasPrice
32+ );
33+ if (isNaN(suggestedGasPrice)) {
34+ throw new Error('strange gas price response', json);
35+ }
36+
37+ // safeguard against obscene suggestions
2838 return Math.min(suggestedGasPrice, MAX_GAS_PRICE_GWEI);
2939 } catch (e) {
40+ console.warn('error fetching gas price', e);
3041 return DEFAULT_GAS_PRICE_GWEI;
3142 }
3243 }