EIP-3045 · Stagnant(停滞) · Interface · 2020-10-14
EIP-3045: Adds `baseFee` to `eth_getUncleByBlockHashAndIndex`
一项停滞(Stagnant)的提案:对于 EIP-1559 分叉之后的区块,在 `eth_getUncleByBlockHashAndIndex` 返回的区块对象中增加 `baseFee` 字段。
它解决什么问题?
EIP-1559 为每个区块头增加了每单位 gas 的基础费用。估算 gas 价格或分析费用历史的工具需要通过 JSON-RPC 读取这个值,因此 RPC 响应也必须为它增加一个字段。
EIP-3045 只涉及一个特定的端点:eth_getUncleByBlockHashAndIndex,它返回叔块(uncle,也称 ommer)的区块头。由于分叉之后叔块的区块头也带有基础费用,响应中也应当提供它。
它如何运作
请求参数不变:一个区块哈希和一个叔块索引。只有结果改变:
- 对于 EIP-1559 分叉区块当时及之后的叔块,结果必须包含
baseFee,其为 EIP-1474 中定义的十六进制编码数量。 - 对于分叉之前的区块,结果不得包含该字段。
选择增加一个字段而不是新增端点,是因为这是最容易集成的改动;对旧区块省略该字段,则能让现有的使用方继续正常工作。
示例代码
按提案给出的 JSON-RPC 请求和响应的相关部分:
{
"jsonrpc": "2.0",
"id": 1559,
"method": "eth_getUncleByBlockHashAndIndex",
"params": ["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"]
}
{
"jsonrpc": "2.0",
"id": 1559,
"result": {
"number": "0x1b4",
"baseFee": "0x7",
"gasLimit": "0x9f759",
"gasUsed": "0x9f759"
}
}
用 TypeScript(ethers v6)读取叔块区块头:
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);