L2 gas comparison

$0.002 per call · USDC via x402 · POST /api/l2-gas-comparison

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

Category: Crypto & onchain data · Tags: l2 gas cross-chain comparison routing

TRY IN PLAYGROUND →

Parameters

NameTypeRequiredDescription
networksarraynoSubset 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"
}
FieldTypeAlways presentIn the example
queriedAtstringyes2026-06-22T19:00:00.000Z
networksarray of objectsyes3 items in the example
cheapeststringyesbase
sourcestringyesalchemy

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

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:

Related tools

Block info

$0.001 · GET /api/block-info

Header-level detail for one block on Ethereum, Base, Polygon, Arbitrum, or Optimism: hash, timestamp (unix + ISO), trans…

Block receipts (one block, summarised)

$0.005 · POST /api/block-receipts

Every transaction receipt in one block, fetched as a single upstream read and summarised: tx count, succeeded vs failed,…

Chain info snapshot

$0.001 · GET /api/chain-info

One-call chain state snapshot: chain id, latest block number, and current gas price (wei + gwei) for Ethereum, Base, Pol…

Pending block

$0.001 · GET /api/chain/pending

The 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

$0.002 · POST /api/defi-chains

Blockchains 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)

$0.005 · POST /api/gas-snapshot

Live gas price snapshot for a chain - slow / standard / fast tiers in gwei, plus the latest base fee. Sampled from eth_f…