Base Gas
Live and historical Base mainnet gas data through x402-protected endpoints, served from https://base-gas-x402-production.up.railway.app.
All values are read directly from the chain. Fees are returned in gwei; transaction costs also come back in ETH and USD.
Setup
See rules/getting-started.md for installation and wallet setup.
Quick Reference
| Task | Endpoint | Price | Returns |
|---|---|---|---|
| Current gas | GET /gas |
$0.002 | Base fee, low/med/high priority tiers, cost estimate in ETH and USD |
| Compare chains | GET /gas/compare |
$0.01 | Base, OP, Arbitrum, Ethereum ranked cheapest first, cost in USD |
| Historical trend | GET /gas/history |
$0.01 | Time series, min/max/avg/median, cheap-or-expensive verdict |
| Cheapest hours | GET /gas/cheapest-window |
$0.02 | Hours to avoid, cheapest hour, savings vs the average hour and in USD |
| Data coverage | GET /health |
free | How much history has been collected so far |
See rules/choosing-an-endpoint.md for which route answers which question.
Current Gas
npx agentcash@latest fetch https://base-gas-x402-production.up.railway.app/gas
Parameters:
gasLimit(optional) - Gas units to price the estimate against. Defaults to 21000.
Price the cost of a Uniswap swap instead of a plain transfer:
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas?gasLimit=180000"
Common gas limits:
| Operation | gasLimit |
|---|---|
| ETH transfer | 21000 |
| ERC-20 transfer | 65000 |
| NFT mint | 85000 |
| Uniswap swap | 180000 |
| Contract deploy | 1500000 |
Returns: baseFeePerGas, priorityFeePerGas (low/medium/high), gasPrice, estimatedTransferCost (gwei and ETH), blockNumber, fetchedAt.
Compare Chains
npx agentcash@latest fetch https://base-gas-x402-production.up.railway.app/gas/compare
Parameters:
gasLimit(optional) - Gas units to price each chain against. Defaults to 21000.
Returns: chains ranked cheapest first, cheapest, baseRank, baseVsEthereum (a plain-language multiplier), and unavailable for any chain whose RPC did not respond.
Chains that fail are reported rather than failing the whole request, so a partial comparison still returns useful data.
Historical Trend
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas/history?hours=24"
Parameters:
hours(optional) - Lookback window, 1 to 168. Defaults to 24.
Returns: samples time series, summary (min, max, avg, median), currentGasPrice, verdict, verdictNote, and spreadPercent.
The verdict field is the useful part: cheap, normal, or expensive relative to the requested window, or flat when the window's spread is under 1%. A raw RPC call cannot answer this, because it has no history to compare against.
flat is common on Base and is a real answer: gas is not moving, so there is nothing to wait for. Quote verdictNote rather than reinterpreting it.
Cheapest Hours
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas/cheapest-window?hours=168"
Parameters:
hours(optional) - Lookback window used to compute hourly averages, 1 to 168. Defaults to 168 (7 days).
Returns: hasDailyCycle, a plain-language recommendation, savingsPercent, and hourlyAverages bucketed by hour of day in UTC and ranked cheapest first, plus cheapestHourUtc and priciestHourUtc.
Check hasDailyCycle before using the ranking. When it is false the hours do not meaningfully differ and timing saves nothing; report recommendation instead of naming a cheapest hour.
Check Coverage First (free)
Both history endpoints depend on samples collected over time. Check coverage before paying:
curl -s https://base-gas-x402-production.up.railway.app/health
Returns: under history: samples, hoursCovered, oldestSample, newestSample, sampleIntervalSeconds, retentionHours, durable (whether history survives a redeploy) and lastError. Also nextSteps, ready-to-run commands for the paid routes.
If hoursCovered is smaller than the window you need, the answer will be thin. Every paid response also carries a coverage object so the depth of the underlying data is always visible.
Workflows
Decide whether to transact now
- Check the trend and verdict:
GET /gas/history?hours=24 - If
verdictisflat, proceed and tell the user there is nothing to wait for - If
cheap, proceed - If
expensive, check whether waiting actually helps:GET /gas/cheapest-window
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas/history?hours=24"
Price a specific operation
- Pick the gasLimit for the operation type
- Call
/gaswith that gasLimit - Read
estimatedTransferCost.usdfor the cost in dollars (or.eth) - If
usdisnull, the price feed was unavailable: fall back to.eth
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas?gasLimit=85000"
Pick the cheapest chain
- (Optional) Check coverage or balance
- Compare chains at the relevant gasLimit
- Route the transaction to
cheapest
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas/compare?gasLimit=180000"
Schedule a batch job
- Check history coverage:
GET /health(free) - If coverage is at least 24 hours, call
/gas/cheapest-window - If
hasDailyCycleisfalse, reportrecommendationand run the job whenever - If
true, keep the job out ofavoidHoursUtc(worst first) - Check
savingsUsd.vsAverageHour: if the saving is negligible at your volume, run whenever - Otherwise schedule the job for
cheapestHourUtc(convert from UTC)
curl -s https://base-gas-x402-production.up.railway.app/health
npx agentcash@latest fetch "https://base-gas-x402-production.up.railway.app/gas/cheapest-window?hours=168"
Cost Optimization
Use /gas when:
- You only need the current price
- You are pricing a single known operation
Use /gas/history when:
- The question is "is this high or low", not "what is it"
- You need a trend or chart
Use /gas/cheapest-window when:
- The work can wait
- You are scheduling recurring or batch transactions
Efficient patterns
- Check
/healthbefore history calls. It is free and tells you whether the data is deep enough to be worth paying for. - One
/gas/comparebeats four/gascalls. It reads all four chains in a single paid request. - Pass
gasLimitinstead of doing the math. The estimate is returned already priced for the operation you care about, in gwei, ETH and USD. - Do not poll. Base blocks are two seconds apart but gas moves slowly; sampling more than once a minute spends money for no new information.
Notes
- Payment settles on Base mainnet (
eip155:8453) in USDC via x402. - Prices are published in the endpoint's OpenAPI document at
/openapi.jsonand are the source of truth if they ever differ from this table. - The service is open source: github.com/memosr/base-gas-x402.
