EIPs Explained

EIP-3041 · Stagnant · Interface · 2020-10-13

EIP-3041: Adds `baseFee` to `eth_getBlockByHash`

Proposed adding the EIP-1559 base fee to the block object returned by the eth_getBlockByHash JSON-RPC method, so tools can read the base fee of any post-London block.

What problem does it solve?

EIP-1559 added a protocol-level base fee per gas to every block header. Wallets, fee estimators and analytics tools need that value to predict fees and explain what users paid. Before London, the standard JSON-RPC block object had no field for it.

EIP-3041 proposed the smallest possible change: add one field to the existing eth_getBlockByHash response rather than inventing a new endpoint.

How it works

  • Parameters of eth_getBlockByHash are unchanged: the block hash and a boolean for full transaction objects.
  • For blocks on or after the EIP-1559 fork, the result object must include a baseFee field, encoded as a hex Quantity (see EIP-1474).
  • For blocks before the fork, the field must not be present. This keeps the response identical to the old format for historical blocks, so existing parsers do not break.
  • The field is informational only and has no security implications.

Sample code

Request:

curl -s -X POST -H 'Content-Type: application/json' --data '{
  "jsonrpc": "2.0", "id": 1,
  "method": "eth_getBlockByHash",
  "params": ["0x<block hash>", false]
}' "$RPC_URL"

Response as proposed (abridged):

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x1b4",
    "hash": "0x...",
    "gasLimit": "0x9f759",
    "gasUsed": "0x9f759",
    "baseFee": "0x7"
  }
}

What clients actually return today, read via ethers v6:

import { JsonRpcProvider, formatUnits } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const block = await provider.getBlock(blockHash);
console.log(formatUnits(block!.baseFeePerGas ?? 0n, "gwei")); // null for pre-London blocks

Things to know

  • Status: Stagnant. The idea shipped, but not under this name: Ethereum clients expose the value as baseFeePerGas on the block object returned by eth_getBlockByHash and eth_getBlockByNumber, following the field name in the EIP-1559 header. Do not look for baseFee.
  • Pre-London blocks have no base fee; libraries such as ethers return null for those.
  • Inside contracts, the current block's base fee is available as block.basefee via the BASEFEE opcode from EIP-3198.
  • For fee history over a range of blocks, the eth_feeHistory method is usually more convenient than fetching blocks one by one.

#json-rpc #base-fee #interface #gas #1559

Details

Authors
Abdelhamid Bakhta (@abdelhamidbakhta)
Status
Stagnant
Type
Standards Track / Interface
Created
2020-10-13
Requires

Machine-readable: Markdown · JSON