Skip to content

Instantly share code, notes, and snippets.

@jordanmack
Created June 3, 2018 21:00
Show Gist options
  • Save jordanmack/844e918de74675179fc3933e04604ef0 to your computer and use it in GitHub Desktop.
Save jordanmack/844e918de74675179fc3933e04604ef0 to your computer and use it in GitHub Desktop.
A simple Python script to determine the Ethereum gas price that should be used by utilizing the EthGasStation.info API. I use this in simple automation scripts and find it to be more reliable for predicting a safe gas price during congested periods.
#!/usr/bin/env python3
import json
import math
import requests
DEFAULT = 15
MODIFIER = 2
try:
url = "https://ethgasstation.info/json/ethgasAPI.json"
r = requests.get(url, timeout=10)
j = json.loads(r.content.decode("utf-8"))
g = math.ceil(j["safeLow"] / 10) + MODIFIER
print(g)
except:
print(DEFAULT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment