---
eip: 3044
label: EIP-3044
title: Adds `baseFee` to `eth_getBlockByNumber`
status: Stagnant
type: Standards Track
category: Interface
created: 2020-10-14
requires: 1474, 1559
official: https://eips.ethereum.org/EIPS/eip-3044
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3044.md
canonical: https://eips.huatuo.xyz/zh/eip-3044/
lang: zh
tldr: 一项处于停滞（Stagnant）状态的 JSON-RPC 提案：在 `eth_getBlockByNumber` 的响应中包含每个区块的 EIP-1559 base fee，也就是今天 `baseFeePerGas` 字段背后的想法。
tags: [json-rpc, base-fee, interface, eip-1559, stagnant]
---

# EIP-3044: Adds `baseFee` to `eth_getBlockByNumber`

> Add basefee field to ethgetBlockByNumber RPC endpoint response.

**TL;DR:** 一项处于停滞（Stagnant）状态的 JSON-RPC 提案：在 `eth_getBlockByNumber` 的响应中包含每个区块的 EIP-1559 base fee，也就是今天 `baseFeePerGas` 字段背后的想法。

## 它解决什么问题？

[EIP-1559](/eip-1559/) 在每个区块头中增加了由协议计算的每 gas base fee。钱包和 gas 估算器需要这个数字来选择合理的 `maxFeePerGas`，但标准的 JSON-RPC 区块对象（[EIP-1474](/eip-1474/)）中没有对应的字段。

EIP-3044 提出了最简单的修复方式：把 base fee 加到现有的 `eth_getBlockByNumber` 结果中，而不是新建一个端点。

## 它如何运作

- `eth_getBlockByNumber` 的参数不变。
- 对于 EIP-1559 分叉**当时及之后**的区块，结果对象**必须**以十六进制 `Quantity` 的形式包含 base fee。
- 对于分叉**之前**的区块，该字段**不得**出现，因此旧的响应不变，现有客户端也不会被破坏。
- 该字段纯粹是信息性的，对共识没有影响。

提案把这个字段命名为 `baseFee`。当客户端在 London 升级中真正上线 EIP-1559 时，区块对象里出现的字段名为 **`baseFeePerGas`**，`eth_getBlockByHash` 也会返回它。

## 示例代码

请求以及客户端如今返回的精简响应：

```sh
curl -s -X POST -H 'content-type: application/json' "$RPC_URL" --data '{
  "jsonrpc": "2.0", "id": 1,
  "method": "eth_getBlockByNumber",
  "params": ["latest", false]
}'
```

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x1b4",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0x9f759",
    "baseFeePerGas": "0x7",
    "transactions": []
  }
}
```

用 ethers v6 读取：

```ts
const block = await provider.getBlock("latest");
console.log(block?.baseFeePerGas); // bigint in wei, null for pre-London blocks
```

## 需要注意

- 状态为 **Stagnant**。这项提案本身从未定稿，但它所描述的行为，即额外的 base fee 字段、在 London 之前的区块上不存在，正是客户端以 `baseFeePerGas` 这个名字实现的。
- 不要针对 `baseFee` 这个键编写代码；请使用 `baseFeePerGas`。
- 在合约内部，可以通过 [EIP-3198](/eip-3198/) 的 `BASEFEE` opcode 获取当前区块的 base fee。
- 一次性获取一段区块范围的 base fee，通常的做法是使用 `eth_feeHistory`。


---

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