L2 gas comparison
POST /api/l2-gas-comparisonCurrent gas snapshot across Ethereum + supported L2s (Base, Polygon, Arbitrum, Optimism), sorted cheapest-first. Send POST /api/l2-gas-comparison with no required fields (1 optional) and pay $0.002 per call over x402 or MPP (there is no free tier). It returns a JSON object with queriedAt, networks, cheapest and source.
Returns gas price in gwei, latest block number, chain id, and an isL2 flag per chain. Use to route a transaction to the cheapest viable L2 or to track L1→L2 gas spread.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
networks | array | no | Subset of networks to query. Default = all 5. Supported: ethereum, base, polygon, arbitrum, optimism. |
Example request
curl -i -X POST https://agent402.tools/api/l2-gas-comparison \
-H "Content-Type: application/json" \
-d '{"networks":["ethereum","base","arbitrum","optimism","polygon"]}'
Without payment this returns HTTP 402 Payment Required with the exact price for l2-gas-comparison; any x402 v2 or MPP client pays it and retries.
Example response
{
"queriedAt": "2026-06-22T19:00:00.000Z",
"networks": [
{
"network": "base",
"chainId": 8453,
"isL2": true,
"gasPriceWei": "100000000",
"gasPriceGwei": 0.1,
"blockNumber": 22000000
},
{
"network": "arbitrum",
"chainId": 42161,
"isL2": true,
"gasPriceWei": "100000000",
"gasPriceGwei": 0.1,
"blockNumber": 300000000
},
{
"network": "ethereum",
"chainId": 1,
"isL2": false,
"gasPriceWei": "15000000000",
"gasPriceGwei": 15,
"blockNumber": 22000000
}
],
"cheapest": "base",
"source": "alchemy"
}
| Field | Type | Always present | In the example |
|---|---|---|---|
queriedAt | string | yes | 2026-06-22T19:00:00.000Z |
networks | array of objects | yes | 3 items in the example |
cheapest | string | yes | base |
source | string | yes | alchemy |
From an MCP client
catalog.call {
"slug": "l2-gas-comparison",
"params": {
"networks": [
"ethereum",
"base",
"arbitrum",
"optimism",
"polygon"
]
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for l2-gas-comparison; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
- Every field is optional. An input the tool rejects returns an HTTP 4xx whose body carries
error,tool,expected,requiredandexample. - A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - A
GETorHEADto /api/l2-gas-comparison returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/l2-gas-comparison", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"networks": [
"ethereum",
"base",
"arbitrum",
"optimism",
"polygon"
]
}),
});
Part of these workflows
L2 gas comparison is one step in this skill pack, each sold as a single call:
- Cheapest rail right now - Where should an agent transact this minute? Live gas on Ethereum + every major L2 side by side, Base gas tiers, a fee estimate for your transaction type, and ETH spot to price it all in dollars.
Related tools
Block info
GET /api/block-infoHeader-level detail for one block on Ethereum, Base, Polygon, Arbitrum, or Optimism: hash, timestamp (unix + ISO), trans…
Block receipts (one block, summarised)
POST /api/block-receiptsEvery transaction receipt in one block, fetched as a single upstream read and summarised: tx count, succeeded vs failed,…
Chain info snapshot
GET /api/chain-infoOne-call chain state snapshot: chain id, latest block number, and current gas price (wei + gwei) for Ethereum, Base, Pol…
Pending block
GET /api/chain/pendingThe chain's pending block: how many transactions are queued for the next block, the base fee they will pay, and the gas …
DeFi TVL by chain
POST /api/defi-chainsBlockchains ranked by DeFi TVL from DefiLlama's free chain list: name, TVL in USD, share of total DeFi TVL, native token…
Gas snapshot (slow / standard / fast)
POST /api/gas-snapshotLive gas price snapshot for a chain - slow / standard / fast tiers in gwei, plus the latest base fee. Sampled from eth_f…