Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

gas-forecast

Predict optimal Ethereum gas prices using EIP-1559 base fee dynamics and historical block data.

Install

pip install requests rich
# or
pip install -r requirements.txt

Configuration

Optional environment variables:

  • ETHERSCAN_API_KEY — Not currently used but reserved for future features
  • COINGECKO_API_KEY — Not required; CoinGecko free tier is used for ETH/USD price

Usage

Predict

Predict optimal gas price for next N blocks:

python gas_forecast.py predict -n 10 --blocks 50

Sample 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│
└──────────┴───────────┴───────────┴──────────┴────────────┘

History

Show gas price history:

python gas_forecast.py history --blocks 20

Sample 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 │
│  ...    │        ... │        ... │    ...  │      ... │        ... │
└─────────┴────────────┴────────────┴─────────┴──────────┴────────────┘

Trend

Analyze gas trend with moving averages:

python gas_forecast.py trend --blocks 100

Sample 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  │
└─────────────────┴───────────────┘

Alerts

Set gas price alert — notify when base fee drops below threshold:

python gas_forecast.py alerts 15.0 --mode below

Set alert for high gas:

python gas_forecast.py alerts 50.0 --mode above

Polls 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!

Stats

Network gas statistics:

python gas_forecast.py stats --blocks 100

Sample 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

Simulate transaction cost:

python gas_forecast.py simulate 21000 --gas-price 20.0

Sample 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                  │
└──────────────────────────────────────────────────┘

Dashboard

Live terminal dashboard (refreshes every ~12 seconds):

python gas_forecast.py dashboard

Shows 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.

JSON Output

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 --json

EIP-1559 Explained

EIP-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).

Base Fee Formula

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

Trend Analysis

  • 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

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    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                   │
└─────────────────────────────────────────────────────────────┘

Public RPC Endpoints

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.

License

MIT

About

CLI gas price predictor — EIP-1559 base fee trend analysis, moving averages, live dashboard, transaction cost simulation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages