Predict optimal Ethereum gas prices using EIP-1559 base fee dynamics and historical block data.
pip install requests rich
# or
pip install -r requirements.txtOptional environment variables:
ETHERSCAN_API_KEY— Not currently used but reserved for future featuresCOINGECKO_API_KEY— Not required; CoinGecko free tier is used for ETH/USD price
Predict optimal gas price for next N blocks:
python gas_forecast.py predict -n 10 --blocks 50Sample output:
╔═══════════════════════════════════════════╗
║ ⛽ gas-forecast predict ║
╠═══════════════════════════════════════════╣
║ Current Block: 18500000 ║
║ Current Base Fee: 18.45 Gwei ║
║ Trend: ▼ DOWN (bullish) ║
╚═══════════════════════════════════════════╝
┌─────────────────────────────────────┐
│ Predicted Base Fees (Next Blocks) │
├───────┬─────────────────────────────┤
│ Block │ Predicted Base Fee (Gwei) │
├───────┼─────────────────────────────┤
│ +1 │ 18.12 │
│ +2 │ 17.80 │
│ ... │ ... │
└───────┴─────────────────────────────┘
┌──────────────────────────────────────────────────────────┐
│ Recommended Gas │
├──────────┬───────────┬───────────┬──────────┬────────────┤
│ Tier │ maxFee │ Priority │ Total │ Inclusion │
├──────────┼───────────┼───────────┼──────────┼────────────┤
│ FAST │ 22.14 │ 2.00 │ 24.14 │ < 1 block │
│ STANDARD │ 19.93 │ 1.50 │ 21.43 │ < 3 blocks │
│ SLOW │ 17.20 │ 1.00 │ 18.20 │ < 10 blocks│
└──────────┴───────────┴───────────┴──────────┴────────────┘
Show gas price history:
python gas_forecast.py history --blocks 20Sample output:
┌──────────────────────────────────────────────────────────────────────┐
│ Gas History — Last 20 Blocks │
├─────────┬────────────┬────────────┬─────────┬──────────┬────────────┤
│ Block │ Base Fee │ Gas Used │ Util% │ Burned │ Time │
├─────────┼────────────┼────────────┼─────────┼──────────┼────────────┤
│ 185000 │ 18.45 │ 15,234,567 │ 50.8% │ 0.004521 │ 12:34:56 │
│ ... │ ... │ ... │ ... │ ... │ ... │
└─────────┴────────────┴────────────┴─────────┴──────────┴────────────┘
Analyze gas trend with moving averages:
python gas_forecast.py trend --blocks 100Sample output:
┌─────────────────────────────────────────┐
│ ⛽ Trend Analysis │
├─────────────────────────────────────────┤
│ Current Base Fee: 18.45 Gwei │
│ EMA(12): 19.20 Gwei │
│ EMA(26): 20.15 Gwei │
│ SMA(20): 19.80 Gwei │
│ Volatility (20-block): 2.34 Gwei │
│ Direction: ▼ DOWN (bullish) │
└─────────────────────────────────────────┘
┌─────────────────────────────────┐
│ Predicted Base Fees │
├─────────────────┬───────────────┤
│ Horizon │ Predicted │
├─────────────────┼───────────────┤
│ Next 1 block │ 18.12 │
│ Next 5 blocks │ 17.05 │
│ Next 15 blocks │ 15.80 │
└─────────────────┴───────────────┘
Set gas price alert — notify when base fee drops below threshold:
python gas_forecast.py alerts 15.0 --mode belowSet alert for high gas:
python gas_forecast.py alerts 50.0 --mode abovePolls every 12 seconds (1 block time) until condition is met:
[12:34:56] Block 18500001 | Base Fee: 18.45 Gwei
[12:35:08] Block 18500002 | Base Fee: 17.90 Gwei
[12:35:20] Block 18500003 | Base Fee: 14.80 Gwei
🚨 ALERT! Base fee 14.80 Gwei is below 15.0 Gwei!
Network gas statistics:
python gas_forecast.py stats --blocks 100Sample output:
┌─────────────────────────────────────────────────┐
│ ⛽ Network Stats │
├─────────────────────────────────────────────────┤
│ Blocks: 18499900 → 18500000 (100 blocks, 20.0h)│
│ │
│ Base Fee │
│ Average: 19.20 Gwei │
│ Median: 18.50 Gwei │
│ P95: 28.30 Gwei │
│ Min: 14.20 Gwei │
│ Max: 35.10 Gwei │
│ │
│ Utilization │
│ Average: 52.3% │
│ │
│ ETH Burned │
│ Total: 2.845231 ETH │
│ Per Block: 0.028452 ETH │
│ Per Minute: 0.002371 ETH │
│ Per Hour: 0.142261 ETH │
└─────────────────────────────────────────────────┘
Simulate transaction cost:
python gas_forecast.py simulate 21000 --gas-price 20.0Sample output:
┌──────────────────────────────────────────────────┐
│ ⛽ Transaction Simulation │
├──────────────────────────────────────────────────┤
│ Gas Limit: 21,000 │
│ Gas Price: 20.00 Gwei │
│ Cost (ETH): 0.00042000 ETH │
│ Cost (USD): $1.26 │
│ ETH Price: $3,000.00 │
│ │
│ For comparison with recommended tiers: │
│ Fast: 0.00050400 ETH │
│ Standard: 0.00045000 ETH │
│ Slow: 0.00038100 ETH │
└──────────────────────────────────────────────────┘
Live terminal dashboard (refreshes every ~12 seconds):
python gas_forecast.py dashboardShows real-time:
- Current base fee (large display)
- Trend arrow with color (green=falling, red=rising, yellow=stable)
- Predicted next base fee
- Recommended gas: Fast / Standard / Slow
- Gas used ratio bar
- ETH burned stats
Press Ctrl+C to exit.
All commands support --json flag for machine-readable output:
python gas_forecast.py predict --json -n 5
python gas_forecast.py stats --json --blocks 200
python gas_forecast.py simulate 21000 --jsonEIP-1559 (implemented in London hard fork, August 2021) changed Ethereum's fee market:
- Base Fee: Algorithmically determined per block. Burns ETH.
- Priority Fee (Tip): Paid to validators for transaction inclusion.
- Target Gas: 15M gas per block (50% of 30M max limit).
- Adjustment: Base fee increases when blocks are >50% full, decreases when <50%.
- Max Change: 12.5% per block (1/8 of previous base fee).
if gasUsed > target:
baseFee_new = baseFee_parent + baseFee_parent * (gasUsed - target) / target / 8
elif gasUsed < target:
baseFee_new = baseFee_parent - baseFee_parent * (target - gasUsed) / target / 8
else:
baseFee_new = baseFee_parent
- EMA(12): Fast exponential moving average (short-term trend)
- EMA(26): Slow exponential moving average (long-term trend)
- SMA(20): Simple moving average (reference)
- Bullish (for gas): EMA(12) < EMA(26) → gas prices falling
- Bearish (for gas): EMA(12) > EMA(26) → gas prices rising
┌─────────────────────────────────────────────────────────────┐
│ gas-forecast CLI │
├─────────────┬──────────────┬──────────────┬─────────────────┤
│ predict │ history │ trend │ alerts │
├─────────────┼──────────────┼──────────────┼─────────────────┤
│ stats │ simulate │ dashboard │ │
├─────────────┴──────────────┴──────────────┴─────────────────┤
│ Core Engine │
├──────────────┬──────────────┬───────────────────────────────┤
│ EIP-1559 Math│ EMA / SMA │ Recommendation Engine │
├──────────────┴──────────────┴───────────────────────────────┤
│ Data Layer │
├──────────────┬──────────────┬───────────────────────────────┤
│ RPC Client │ Cache │ CoinGecko (ETH price) │
│ (failover) │ (1-min TTL) │ │
├──────────────┴──────────────┴───────────────────────────────┤
│ Ethereum JSON-RPC Endpoints │
│ llamarpc · ankr · publicnode · cloudflare │
└─────────────────────────────────────────────────────────────┘
Automatic failover across these public endpoints:
| Provider | Endpoint |
|---|---|
| LlamaRPC | https://eth.llamarpc.com |
| Ankr | https://rpc.ankr.com/eth |
| PublicNode | https://ethereum.publicnode.com |
| Cloudflare | https://cloudflare-eth.com |
No API key required. Rate limiting with automatic delays between calls.
MIT