---
eip: 3046
label: EIP-3046
title: Adds `baseFee` to `eth_getUncleByBlockNumberAndIndex`
status: Stagnant
type: Standards Track
category: Interface
created: 2020-10-14
requires: 1474, 1559
official: https://eips.ethereum.org/EIPS/eip-3046
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3046.md
canonical: https://eips.huatuo.xyz/zh/eip-3046/
lang: zh
tldr: 提议在 eth_getUncleByBlockNumberAndIndex 返回的叔块（uncle）中加入 EIP-1559 的基础费用，使 RPC 客户端能在伦敦升级之后的每个区块头中看到它。
tags: [json-rpc, base-fee, uncles, interface, api]
---

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

> Add basefee field to ethgetUncleByBlockNumberAndIndex RPC endpoint response.

**TL;DR:** 提议在 eth_getUncleByBlockNumberAndIndex 返回的叔块（uncle）中加入 EIP-1559 的基础费用，使 RPC 客户端能在伦敦升级之后的每个区块头中看到它。

## 它解决什么问题？

[EIP-1559](/eip-1559/) 为每个区块头增加了**每 gas 基础费用**。估算 gas 价格或分析费用历史的工具，对它们查看的任何区块都需要这个值，包括*叔块*（ommer）：在工作量证明下被挖出、但没有被纳入规范链的有效区块。

JSON-RPC 方法 `eth_getUncleByBlockNumberAndIndex`（在 [EIP-1474](/eip-1474/) 中规定）返回叔块的区块头字段。如果没有明确规则，客户端可能包含也可能不包含这个新字段。EIP-3046 将其明确化。

## 它如何运作

变更只是响应中新增一个字段：

- 对于区块号**等于或晚于** EIP-1559 分叉区块的叔块，`result` 对象**必须**包含 `baseFee`（十六进制 `Quantity`）。
- 对于分叉**之前**的叔块，**不得**包含 `baseFee`。
- 请求参数不变：一个区块号（或标签）和一个叔块索引。

选择增加字段而不是新端点，是因为这是客户端最容易采纳的变更；在旧区块上省略它，则使历史数据的响应保持不变。

## 示例代码

请求：

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

按提议，对 1559 之后的叔块的响应（其他区块头字段已省略）：

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

用 TypeScript 发起同样的调用：

```ts
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);
```

## 需要注意

- 状态为 **Stagnant**。同系列的提案对其他方法做了同样的修改：[EIP-3041](/eip-3041/)（`eth_getBlockByHash`）、[EIP-3044](/eip-3044/)（`eth_getBlockByNumber`）和 [EIP-3045](/eip-3045/)（`eth_getUncleByBlockHashAndIndex`）。
- 这里提议的字段名 `baseFee` **不是**客户端实际发布的名称。以太坊 JSON-RPC（Geth 等使用）在区块和区块头对象中返回 `baseFeePerGas`。请按客户端的实际行为编写代码，而不是照搬这份 EIP 中的示例。
- 合并（Merge）之后不再出现叔块（权益证明没有 ommer），因此该方法只会为历史上的工作量证明区块返回数据。
- 在合约内部，可以通过 [EIP-3198](/eip-3198/) 的 `BASEFEE` 操作码获取当前区块的基础费用。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-3046
