---
eip: 3045
label: EIP-3045
title: Adds `baseFee` to `eth_getUncleByBlockHashAndIndex`
status: Stagnant
type: Standards Track
category: Interface
created: 2020-10-14
requires: 1474, 1559
official: https://eips.ethereum.org/EIPS/eip-3045
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3045.md
canonical: https://eips.huatuo.xyz/zh/eip-3045/
lang: zh
tldr: 一项停滞（Stagnant）的提案：对于 EIP-1559 分叉之后的区块，在 `eth_getUncleByBlockHashAndIndex` 返回的区块对象中增加 `baseFee` 字段。
tags: [json-rpc, api, fees, uncles, interface]
---

# EIP-3045: Adds `baseFee` to `eth_getUncleByBlockHashAndIndex`

> Add basefee field to ethgetUncleByBlockHashAndIndex RPC endpoint response.

**TL;DR:** 一项停滞（Stagnant）的提案：对于 EIP-1559 分叉之后的区块，在 `eth_getUncleByBlockHashAndIndex` 返回的区块对象中增加 `baseFee` 字段。

## 它解决什么问题？

[EIP-1559](/eip-1559/) 为每个区块头增加了每单位 gas 的基础费用。估算 gas 价格或分析费用历史的工具需要通过 JSON-RPC 读取这个值，因此 RPC 响应也必须为它增加一个字段。

EIP-3045 只涉及一个特定的端点：`eth_getUncleByBlockHashAndIndex`，它返回叔块（uncle，也称 ommer）的区块头。由于分叉之后叔块的区块头也带有基础费用，响应中也应当提供它。

## 它如何运作

请求参数不变：一个区块哈希和一个叔块索引。只有结果改变：

- 对于 EIP-1559 分叉区块**当时及之后**的叔块，结果**必须**包含 `baseFee`，其为 [EIP-1474](/eip-1474/) 中定义的十六进制编码数量。
- 对于分叉**之前**的区块，结果**不得**包含该字段。

选择增加一个字段而不是新增端点，是因为这是最容易集成的改动；对旧区块省略该字段，则能让现有的使用方继续正常工作。

## 示例代码

按提案给出的 JSON-RPC 请求和响应的相关部分：

```json
{
  "jsonrpc": "2.0",
  "id": 1559,
  "method": "eth_getUncleByBlockHashAndIndex",
  "params": ["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"]
}
```

```json
{
  "jsonrpc": "2.0",
  "id": 1559,
  "result": {
    "number": "0x1b4",
    "baseFee": "0x7",
    "gasLimit": "0x9f759",
    "gasUsed": "0x9f759"
  }
}
```

用 TypeScript（ethers v6）读取叔块区块头：

```ts
import { JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const uncle = await provider.send("eth_getUncleByBlockHashAndIndex", [blockHash, "0x0"]);
// Clients expose the field as `baseFeePerGas`, not the `baseFee` name proposed here
console.log(uncle?.baseFeePerGas ?? uncle?.baseFee);
```

## 需要注意

- 状态为 **Stagnant**。它从未最终确定，这里提议的字段名（`baseFee`）也不是客户端实际使用的名字：以太坊客户端在区块和区块头对象中返回的是 `baseFeePerGas`。
- 它所扩展的 JSON-RPC API，即 [EIP-1474](/eip-1474/)，本身也是 Stagnant；目前维护的参考规范是 `ethereum/execution-apis`。
- 自合并（The Merge）以来，权益证明的以太坊不再产生叔块，所以这个端点只与历史上的工作量证明区块有关。
- 在合约内部，可以通过 [EIP-3198](/eip-3198/) 的 `BASEFEE` 操作码获取当前区块的基础费用。


---

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