---
eip: 3041
label: EIP-3041
title: Adds `baseFee` to `eth_getBlockByHash`
status: Stagnant
type: Standards Track
category: Interface
created: 2020-10-13
requires: 1474, 1559
official: https://eips.ethereum.org/EIPS/eip-3041
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3041.md
canonical: https://eips.huatuo.xyz/zh/eip-3041/
lang: zh
tldr: 提议把 EIP-1559 的 base fee 加入 eth_getBlockByHash JSON-RPC 方法返回的区块对象，使工具可以读取任何 London 之后区块的 base fee。
tags: [json-rpc, base-fee, interface, gas, 1559]
---

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

> Add basefee field to ethgetBlockByHash RPC endpoint response.

**TL;DR:** 提议把 EIP-1559 的 base fee 加入 eth_getBlockByHash JSON-RPC 方法返回的区块对象，使工具可以读取任何 London 之后区块的 base fee。

## 它解决什么问题？

[EIP-1559](/eip-1559/) 在每个区块头中加入了协议层面的每 gas base fee。钱包、手续费估算器和分析工具需要这个值来预测费用并解释用户支付了什么。在 London 之前，标准的 JSON-RPC 区块对象没有这个字段。

EIP-3041 提出了尽可能小的改动：在现有的 `eth_getBlockByHash` 响应中增加一个字段，而不是发明一个新的端点。

## 它如何运作

- `eth_getBlockByHash` 的参数不变：区块哈希，以及一个表示是否返回完整交易对象的布尔值。
- 对于 EIP-1559 分叉**当时及之后**的区块，`result` 对象**必须**包含 `baseFee` 字段，编码为十六进制 `Quantity`（见 [EIP-1474](/eip-1474/)）。
- 对于分叉**之前**的区块，该字段**不得**出现。这使历史区块的响应与旧格式保持一致，因此现有解析器不会出问题。
- 该字段仅供参考，不涉及安全影响。

## 示例代码

请求：

```sh
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"
```

按提案设想的响应（节选）：

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

客户端如今实际返回的内容，通过 ethers v6 读取：

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

## 需要注意

- **状态：Stagnant。** 这个想法落地了，但不是以这个名字：以太坊客户端遵循 EIP-1559 区块头中的字段名，在 `eth_getBlockByHash` 和 `eth_getBlockByNumber` 返回的区块对象上以 **`baseFeePerGas`** 暴露该值。不要去找 `baseFee`。
- London 之前的区块没有 base fee；ethers 等库对这些区块返回 `null`。
- 在合约内部，当前区块的 base fee 可通过 [EIP-3198](/eip-3198/) 的 `BASEFEE` opcode 以 `block.basefee` 的形式获得。
- 要获取一段区块范围内的费用历史，`eth_feeHistory` 方法通常比逐个获取区块更方便。


---

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