Skip to content

Instantly share code, notes, and snippets.

@thrilok209
Last active March 23, 2024 13:18
Show Gist options
  • Save thrilok209/8b19dbd8d46b2805ab8bb8973611aea2 to your computer and use it in GitHub Desktop.
Save thrilok209/8b19dbd8d46b2805ab8bb8973611aea2 to your computer and use it in GitHub Desktop.
Fetch GasPrice from eth gas station
// in nodeJs
const axios = require('axios')
async function getCurrentGasPrices() {
let response = await axios.get('https://ethgasstation.info/json/ethgasAPI.json')
let prices = {
low: response.data.safeLow / 10,
medium: response.data.average / 10,
high: response.data.fast / 10
}
console.log(`Current ETH Gas Prices (in GWEI):`)
console.log(`Low: ${prices.low} (transaction completes in < 30 minutes)`)
console.log(`Standard: ${prices.medium} (transaction completes in < 5 minutes)`)
console.log(`Fast: ${prices.high} (transaction completes in < 2 minutes)`)
return prices;
}
@afmsavage
Copy link

You have a typo in async. People (not me of course) who copy paste without reading things over might get confused 😆

@thrilok209
Copy link
Author

You have a typo in async. People (not me of course) who copy paste without reading things over might get confused

Haha. It's fixed

@Rakkoc
Copy link

Rakkoc commented Aug 26, 2023

https://ethgasstation.info/ was closed. Do you know an altarnative ?

@afmsavage
Copy link

Can use defisaver.com, been using this on my CLI
.gas is aliased to `curl https://app.defisaver.com/api/gas-price/current | jq'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment