@@ -11,6 +11,8 @@ const feeToInt = f => (f < 1 ? 1 : Math.round(f));
12const feeToWei = fee => Web3.utils.toHex(Web3.utils.toWei(String(fee), 'gwei'));
12const feeToWei = fee => Web3.utils.toHex(Web3.utils.toWei(String(fee), 'gwei'));
14+const weiToGwei = wei => Math.ceil(wei / 1_000_000_000);
14const calculateMaxFee = (baseFee, maxPriorityFee) =>
16const calculateMaxFee = (baseFee, maxPriorityFee) =>
15 feeToWei(Math.round(2 * baseFee + maxPriorityFee));
17 feeToWei(Math.round(2 * baseFee + maxPriorityFee));
@@ -43,68 +45,32 @@ export const defaultGasValues = value => ({
44const getGasForNetwork = async providerUrl => {
46const getGasForNetwork = async providerUrl => {
46− const [feeResponse, waitResponse] = await Promise.all([
48+ const feeResponse = await fetch(
48− `${providerUrl}/api` +
49+ providerUrl,
49− '?module=gastracker' +
50+ {
50− '&action=gasoracle' +
51− '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
57− fetch('https://ethereum-api.xyz/gas-prices', {
58− method: 'GET',
51+ method: 'get',
59 cache: 'no-cache',
52 cache: 'no-cache',
63− const [feeJson, waitJson] = await Promise.all([
64− feeResponse.json(),
55+ const feeJson = await feeResponse.json();
68− const suggestedBaseFeePerGas = Number(feeJson.result.suggestBaseFee);
70 // Calculations derived from:
57 // Calculations derived from:
71 // https://www.blocknative.com/blog/eip-1559-fees
58 // https://www.blocknative.com/blog/eip-1559-fees
74− price: minGas(feeJson.result.FastGasPrice),
61+ price: minGas(weiToGwei(feeJson.data.rapid)),
75− wait: formatWait(waitJson.result.fast.time),
62+ wait: formatWait(15),
76− maxFeePerGas: calculateMaxFee(
63+ maxFeePerGas: weiToGwei(feeJson.data.rapid)
77− suggestedBaseFeePerGas,
78− feeJson.result.FastGasPrice - suggestedBaseFeePerGas
80− maxPriorityFeePerGas: feeToInt(
81− feeJson.result.FastGasPrice - suggestedBaseFeePerGas
83− suggestedBaseFeePerGas,
85 average: {
65 average: {
86− price: minGas(feeJson.result.ProposeGasPrice),
66+ price: minGas(weiToGwei(feeJson.data.fast)),
87− wait: formatWait(waitJson.result.average.time),
67+ wait: formatWait(60),
88− maxFeePerGas: calculateMaxFee(
68+ maxFeePerGas: weiToGwei(feeJson.data.fast)
89− suggestedBaseFeePerGas,
90− feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas
92− maxPriorityFeePerGas: feeToInt(
93− feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas
95− suggestedBaseFeePerGas,
98− price: minGas(feeJson.result.SafeGasPrice),
71+ price: minGas(weiToGwei(feeJson.data.standard)),
99− wait: formatWait(waitJson.result.slow.time),
72+ wait: formatWait(180),
100− maxFeePerGas: calculateMaxFee(
73+ maxFeePerGas: weiToGwei(feeJson.data.standard)
101− suggestedBaseFeePerGas,
102− feeJson.result.SafeGasPrice - suggestedBaseFeePerGas
104− maxPriorityFeePerGas: feeToInt(
105− feeJson.result.SafeGasPrice - suggestedBaseFeePerGas
107− suggestedBaseFeePerGas,
110 } catch (e) {
76 } catch (e) {
@@ -116,11 +82,11 @@ const getGasForNetwork = async providerUrl => {
116export default async function getSuggestedGasPrice(networkType) {
82export default async function getSuggestedGasPrice(networkType) {
117 switch (networkType) {
83 switch (networkType) {
118 case NETWORK_TYPES.GOERLI:
84 case NETWORK_TYPES.GOERLI:
119− return getGasForNetwork('https://api-goerli.etherscan.io');
85+ return getGasForNetwork('https://beaconcha.in/api/v1/execution/gasnow');
120 case NETWORK_TYPES.OFFLINE:
86 case NETWORK_TYPES.OFFLINE:
121 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
87 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
122 case NETWORK_TYPES.LOCAL:
88 case NETWORK_TYPES.LOCAL:
124− return getGasForNetwork('https://api.etherscan.io/');
90+ return getGasForNetwork('https://beaconcha.in/api/v1/execution/gasnow');