Skip to content

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.

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.

The metering system is implemented across two crates in the base/base workspace:

CrateDescription
base-meteringCore metering logic — simulates transactions and computes resource consumption metrics.
base-builder-meteringBuilder-specific metering integration — connects metering to the block building pipeline.

These crates live under crates/builder/ in the repository.

Simulates a transaction and returns a detailed metering report.

NameTypeDescription
transactionObjectTransaction call object (from, to, data, value, gas, etc.).
blockNumberStringBlock tag or number. Use "latest" or "pending" for current state.

Object — Metering result containing gas estimates and resource breakdown.

Terminal window
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
}
}

Returns the current metering configuration parameters used by the builder.

None.

Object — Metering configuration including resource weights and limits.

Terminal window
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"
}
}
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider("https://your-base-rpc-endpoint");
// Estimate metered gas for a transaction
async 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;
}
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";
const client = createPublicClient({
chain: base,
transport: http("https://your-base-rpc-endpoint"),
});
// Estimate metered gas
const result = await client.request({
method: "base_estimateMeteredGas" as any,
params: [
{
from: "0xSenderAddress",
to: "0xContractAddress",
data: "0xCalldata",
},
"latest",
],
});

The metering pipeline operates as follows:

  1. Transaction submission — a transaction (or call object) is submitted to the metering RPC.
  2. State simulation — the transaction is executed against the current (or specified) state using the EVM, with metering instrumentation enabled.
  3. Resource accounting — during simulation, the metering engine tracks compute cycles, storage operations, and memory usage.
  4. Result assembly — the raw resource counts are combined with the current metering configuration (weights) to produce the final metering report.
  5. 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 │
└──────────────────────────────┘
ScenarioBehavior
Transaction reverts during simulationsuccess: false in the result; gas and resource fields still populated.
Invalid transaction parametersStandard JSON-RPC error response.
State unavailable for requested blockJSON-RPC error with appropriate code.