EIPs Explained

EIP-3046 · Stagnant · Interface · 2020-10-14

EIP-3046: Adds `baseFee` to `eth_getUncleByBlockNumberAndIndex`

Proposed adding the EIP-1559 base fee to the uncle blocks returned by eth_getUncleByBlockNumberAndIndex, so RPC clients see it for every post-London header.

What problem does it solve?

EIP-1559 added a base fee per gas to every block header. Tools that estimate gas prices or analyze fee history need that value for any block they look at, including uncle (ommer) blocks: valid blocks that were mined but not included in the canonical chain under proof-of-work.

The JSON-RPC method eth_getUncleByBlockNumberAndIndex (specified in EIP-1474) returns an uncle's header fields. Without an explicit rule, clients might or might not include the new field. EIP-3046 makes it explicit.

How it works

The change is a single new field in the response:

  • For uncles whose block number is on or after the EIP-1559 fork block, the result object must include baseFee (a hex Quantity).
  • For uncles before the fork, it must not include baseFee.
  • Request parameters are unchanged: a block number (or tag) and an uncle index.

Adding a field rather than a new endpoint was chosen as the simplest change for clients to adopt, and omitting it on old blocks keeps responses for historical data unchanged.

Sample code

Request:

{
  "jsonrpc": "2.0",
  "id": 1559,
  "method": "eth_getUncleByBlockNumberAndIndex",
  "params": ["<post-London block number>", "0x0"]
}

Response for a post-1559 uncle, as proposed (other header fields abbreviated):

{
  "jsonrpc": "2.0",
  "id": 1559,
  "result": {
    "number": "0x…",
    "hash": "0x…",
    "parentHash": "0x…",
    "gasLimit": "0x…",
    "gasUsed": "0x…",
    "baseFee": "0x7",
    "uncles": []
  }
}

The same call from TypeScript:

const uncle = await provider.send("eth_getUncleByBlockNumberAndIndex", [blockTag, "0x0"]);
// Deployed clients name the field baseFeePerGas; this EIP proposed baseFee.
const baseFee = BigInt(uncle?.baseFeePerGas ?? uncle?.baseFee ?? 0);

Things to know

  • Status is Stagnant. Sibling proposals made the same change for other methods: EIP-3041 (eth_getBlockByHash), EIP-3044 (eth_getBlockByNumber) and EIP-3045 (eth_getUncleByBlockHashAndIndex).
  • The field name proposed here, baseFee, is not what clients shipped. Ethereum JSON-RPC (as used by Geth and others) returns baseFeePerGas in block and header objects. Code against the actual client behavior, not this EIP's example.
  • Uncles no longer occur after the Merge (proof-of-stake has no ommers), so this method only returns data for historical proof-of-work blocks.
  • Inside contracts, the current block's base fee is available via the BASEFEE opcode from EIP-3198.

#json-rpc #base-fee #uncles #interface #api

Details

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

Machine-readable: Markdown · JSON