Metering RPC
The Metering API simulates a transaction against current state and returns gas estimates, per-resource consumption, and the metering metadata the builder uses to price and prioritize inclusion.
What Metering Provides
Section titled “What Metering Provides”Traditional gas estimation (eth_estimateGas) returns a single number. The Metering API goes further by simulating transactions against the current state and reporting:
- Gas consumption — total gas used, broken down by execution phase.
- Resource usage — compute, storage reads, storage writes, and memory allocation.
- Metering metadata — information used by the block builder to price and prioritize transactions.
This is particularly useful for:
- Block builders that need to meter transactions for optimal block packing.
- Applications that want to display detailed cost breakdowns to users.
- MEV searchers estimating transaction costs against live state.
Relevant Crates
Section titled “Relevant Crates”The metering system is implemented across two crates in the base/base workspace:
| Crate | Description |
|---|---|
base-metering | Core metering logic — simulates transactions and computes resource consumption metrics. |
base-builder-metering | Builder-specific metering integration — connects metering to the block building pipeline. |
These crates live under crates/builder/ in the repository.
RPC Endpoints
Section titled “RPC Endpoints”base_estimateMeteredGas
Section titled “base_estimateMeteredGas”Simulates a transaction and returns a detailed metering report.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
transaction | Object | Transaction call object (from, to, data, value, gas, etc.). |
blockNumber | String | Block tag or number. Use "latest" or "pending" for current state. |
Returns
Section titled “Returns”Object — Metering result containing gas estimates and resource breakdown.
Example
Section titled “Example”curl -X POST https://your-base-rpc-endpoint \ -H "Content-Type: application/json" \ -d '{ "method": "base_estimateMeteredGas", "params": [ { "from": "0xSenderAddress", "to": "0xContractAddress", "data": "0xCalldata" }, "latest" ], "id": 1, "jsonrpc": "2.0" }'{ "id": 1, "jsonrpc": "2.0", "result": { "gasUsed": "0x1a4c0", "gasLimit": "0x1e848", "computeUnits": "0x3200", "storageReads": "0x5", "storageWrites": "0x2", "success": true }}base_getMeteringConfig
Section titled “base_getMeteringConfig”Returns the current metering configuration parameters used by the builder.
Parameters
Section titled “Parameters”None.
Returns
Section titled “Returns”Object — Metering configuration including resource weights and limits.
Example
Section titled “Example”curl -X POST https://your-base-rpc-endpoint \ -H "Content-Type: application/json" \ -d '{ "method": "base_getMeteringConfig", "params": [], "id": 1, "jsonrpc": "2.0" }'{ "id": 1, "jsonrpc": "2.0", "result": { "computeWeight": 1, "storageReadWeight": 2, "storageWriteWeight": 5, "maxComputeUnitsPerBlock": "0x989680", "maxStorageReadsPerBlock": "0x493e0", "maxStorageWritesPerBlock": "0x186a0" }}Usage with ethers.js
Section titled “Usage with ethers.js”import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider("https://your-base-rpc-endpoint");
// Estimate metered gas for a transactionasync function estimateMeteredGas(tx) { const result = await provider.send("base_estimateMeteredGas", [ { from: tx.from, to: tx.to, data: tx.data, value: tx.value ?? "0x0", }, "latest", ]);
console.log("Gas used:", parseInt(result.gasUsed, 16)); console.log("Compute units:", parseInt(result.computeUnits, 16)); console.log("Storage reads:", parseInt(result.storageReads, 16)); console.log("Storage writes:", parseInt(result.storageWrites, 16)); console.log("Success:", result.success);
return result;}Usage with viem
Section titled “Usage with viem”import { createPublicClient, http } from "viem";import { base } from "viem/chains";
const client = createPublicClient({ chain: base, transport: http("https://your-base-rpc-endpoint"),});
// Estimate metered gasconst result = await client.request({ method: "base_estimateMeteredGas" as any, params: [ { from: "0xSenderAddress", to: "0xContractAddress", data: "0xCalldata", }, "latest", ],});How Metering Works
Section titled “How Metering Works”The metering pipeline operates as follows:
- Transaction submission — a transaction (or call object) is submitted to the metering RPC.
- State simulation — the transaction is executed against the current (or specified) state using the EVM, with metering instrumentation enabled.
- Resource accounting — during simulation, the metering engine tracks compute cycles, storage operations, and memory usage.
- Result assembly — the raw resource counts are combined with the current metering configuration (weights) to produce the final metering report.
- Builder integration — when used by the block builder, metering results feed into transaction ordering and block packing decisions.
Transaction │ ▼┌──────────────────┐│ EVM Simulation ││ (base-metering) │└────────┬─────────┘ │ ▼┌──────────────────────────┐│ Resource Accounting ││ compute, storage, memory │└────────┬─────────────────┘ │ ▼┌──────────────────────────────┐│ Metering Report ││ gas, compute units, storage │└──────────────────────────────┘Error Handling
Section titled “Error Handling”| Scenario | Behavior |
|---|---|
| Transaction reverts during simulation | success: false in the result; gas and resource fields still populated. |
| Invalid transaction parameters | Standard JSON-RPC error response. |
| State unavailable for requested block | JSON-RPC error with appropriate code. |
Further Reading
Section titled “Further Reading”- Crate Reference — overview of all crate groups, including the builder crates.
- Execution Pipeline — how the EVM and state management work.