{"eip":3198,"title":"BASEFEE opcode","description":"Adds an opcode that gives the EVM access to the block's base fee.","authors":["Abdelhamid Bakhta (@abdelhamidbakhta)","Vitalik Buterin (@vbuterin)"],"status":"Final","type":"Standards Track","category":"Core","created":"2021-01-13","requires":[1559],"discussionsTo":"https://ethereum-magicians.org/t/eip-3198-basefeeopcode/5162","repo":"EIPs","label":"EIP-3198","officialUrl":"https://eips.ethereum.org/EIPS/eip-3198","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3198.md","url":"https://eips.huatuo.xyz/eip-3198/","tldr":{"en":"Added the BASEFEE opcode (0x48), which returns the current block's EIP-1559 base fee so contracts can react to network fee levels.","ja":"BASEFEE オペコード（0x48）を追加した。現在のブロックの EIP-1559 ベースフィーを返し、コントラクトがネットワークの手数料水準に反応できるようにする。","ko":"BASEFEE 오퍼코드(0x48)를 추가했다. 현재 블록의 EIP-1559 베이스 피를 반환해 컨트랙트가 네트워크 수수료 수준에 반응할 수 있게 한다.","zh":"新增 BASEFEE 操作码（0x48），返回当前区块的 EIP-1559 基础费用，让合约可以根据网络费用水平作出反应。"},"tags":["evm","opcode","gas","fees","london"],"explainers":{"en":{"lang":"en","tldr":"Added the BASEFEE opcode (0x48), which returns the current block's EIP-1559 base fee so contracts can react to network fee levels.","tags":["evm","opcode","gas","fees","london"],"related":[1559,3332,3416],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3198/","markdown":"## What problem does it solve?\n\n[EIP-1559](/eip-1559/) gave every block a protocol-set **base fee per gas**. That number lives in the block header, but without a new opcode a contract had no way to read it.\n\nContracts that care about gas prices had to rely on guesses, admin-updated constants or `tx.gasprice` (which the caller controls). Typical use cases the spec gives:\n\n- **Keeper bounties**: a contract that pays people to \"poke\" it can set the reward to `basefee + x` or `basefee * (1 + x)`, so it always covers the cost of the call whatever market conditions are.\n- **Gas price derivatives**: futures or options on gas can settle against an on-chain, manipulation-resistant price.\n- **Fraud-proof systems**: state channels and optimistic rollups can lengthen challenge periods automatically when base fee is high and posting a challenge is expensive.\n\n## How it works\n\nOne opcode, activated in the London upgrade together with EIP-1559:\n\n| Opcode | Name | Inputs | Outputs | Gas |\n| --- | --- | --- | --- | --- |\n| `0x48` | `BASEFEE` | 0 | 1 | 2 (`G_base`) |\n\nIt pushes the base fee of the block currently being executed, in wei per gas, as a 32-byte word. The value is already known before execution starts (it is needed to validate transactions), so the opcode costs the same as other cheap environment reads like `NUMBER` or `TIMESTAMP`.\n\nExample from the spec: if the base fee is 7 wei, bytecode `0x4800` (`BASEFEE`, `STOP`) leaves `7` on the stack and uses 2 gas.\n\n## Sample code\n\nIn Solidity (0.8.7 and later) the opcode is exposed as `block.basefee`:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract PokeBounty {\n    uint256 public constant POKE_GAS = 60_000;\n    uint256 public lastPoke;\n\n    receive() external payable {}\n\n    function poke() external {\n        require(block.timestamp \u003e= lastPoke + 1 hours, \"too soon\");\n        lastPoke = block.timestamp;\n        // ... do the periodic work ...\n\n        // Reimburse at base fee plus a 20% margin, independent of the caller's tip.\n        uint256 reward = POKE_GAS * block.basefee * 12 / 10;\n        (bool ok, ) = msg.sender.call{value: reward}(\"\");\n        require(ok, \"pay failed\");\n    }\n\n    function priorityFeePaid() external view returns (uint256) {\n        return tx.gasprice - block.basefee; // the tip per gas this tx actually pays\n    }\n}\n```\n\nFrom off-chain code, the same value is in the block header (`baseFeePerGas`):\n\n```ts\nconst block = await provider.getBlock(\"latest\");\nconsole.log(block!.baseFeePerGas); // bigint, wei per gas\n```\n\n## Things to know\n\n- Status: **Final**. Live on mainnet since the London upgrade (August 2021).\n- `tx.gasprice - block.basefee` gives the effective priority fee of the current transaction.\n- In `eth_call` simulations some nodes run with a base fee of 0 when no gas price is supplied, so `block.basefee` may read 0 there. Do not treat that as the real network value.\n- The base fee can move by up to 12.5 % per block, so a reward based on it is only a rough estimate of what the caller paid.\n- Blob transactions have a separate blob base fee, exposed by the `BLOBBASEFEE` opcode (`block.blobbasefee`), not by this one.\n"},"ja":{"lang":"ja","tldr":"BASEFEE オペコード（0x48）を追加した。現在のブロックの EIP-1559 ベースフィーを返し、コントラクトがネットワークの手数料水準に反応できるようにする。","tags":["evm","opcode","gas","fees","london"],"related":[1559,3332,3416],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3198/","markdown":"## 何を解決するのか\n\n[EIP-1559](/eip-1559/) は、すべてのブロックにプロトコルが決める**ガス単価あたりのベースフィー**を与えました。この数値はブロックヘッダーにありますが、新しいオペコードがなければ、コントラクトはそれを読む手段がありませんでした。\n\nガス価格を気にするコントラクトは、推測、管理者が更新する定数、あるいは `tx.gasprice`（呼び出し側が制御できる）に頼るしかありませんでした。仕様が挙げる典型的なユースケースは次のとおりです。\n\n- **キーパー報酬**: 人に「突いて」もらうために報酬を払うコントラクトは、報酬を `basefee + x` や `basefee * (1 + x)` に設定できます。これにより、市況がどうであれ、呼び出しのコストを常にカバーできます。\n- **ガス価格デリバティブ**: ガスの先物やオプションを、オンチェーンの操作されにくい価格に対して決済できます。\n- **不正証明システム**: ステートチャネルや Optimistic ロールアップは、ベースフィーが高く、異議の投稿が高コストなときに、チャレンジ期間を自動的に延ばせます。\n\n## 仕組み\n\nオペコードは 1 つで、London アップグレードで EIP-1559 とともに有効化されました。\n\n| オペコード | 名前 | 入力 | 出力 | ガス |\n| --- | --- | --- | --- | --- |\n| `0x48` | `BASEFEE` | 0 | 1 | 2（`G_base`） |\n\n現在実行中のブロックのベースフィーを、ガス単価あたりの wei で、32 バイトのワードとしてプッシュします。この値は実行開始前にすでに分かっている（トランザクションの検証に必要）ため、オペコードのコストは `NUMBER` や `TIMESTAMP` のような他の安価な環境情報の読み取りと同じです。\n\n仕様の例: ベースフィーが 7 wei の場合、バイトコード `0x4800`（`BASEFEE`、`STOP`）はスタックに `7` を残し、2 ガスを使います。\n\n## サンプルコード\n\nSolidity（0.8.7 以降）では、このオペコードは `block.basefee` として公開されています。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract PokeBounty {\n    uint256 public constant POKE_GAS = 60_000;\n    uint256 public lastPoke;\n\n    receive() external payable {}\n\n    function poke() external {\n        require(block.timestamp \u003e= lastPoke + 1 hours, \"too soon\");\n        lastPoke = block.timestamp;\n        // ... do the periodic work ...\n\n        // Reimburse at base fee plus a 20% margin, independent of the caller's tip.\n        uint256 reward = POKE_GAS * block.basefee * 12 / 10;\n        (bool ok, ) = msg.sender.call{value: reward}(\"\");\n        require(ok, \"pay failed\");\n    }\n\n    function priorityFeePaid() external view returns (uint256) {\n        return tx.gasprice - block.basefee; // the tip per gas this tx actually pays\n    }\n}\n```\n\nオフチェーンのコードからは、同じ値がブロックヘッダー（`baseFeePerGas`）にあります。\n\n```ts\nconst block = await provider.getBlock(\"latest\");\nconsole.log(block!.baseFeePerGas); // bigint, wei per gas\n```\n\n## 知っておくべきこと\n\n- ステータス: **Final**。London アップグレード（2021 年 8 月）以降、メインネットで稼働しています。\n- `tx.gasprice - block.basefee` で、現在のトランザクションの実効プライオリティフィーが得られます。\n- `eth_call` のシミュレーションでは、ガス価格が指定されていないとき、一部のノードがベースフィー 0 で動くため、そこでは `block.basefee` が 0 と読めることがあります。それをネットワークの本当の値として扱わないでください。\n- ベースフィーは 1 ブロックあたり最大 12.5 % 変動しうるため、それに基づく報酬は、呼び出し側が支払ったものの大まかな見積もりにすぎません。\n- Blob トランザクションには別の blob ベースフィーがあり、これは本オペコードではなく `BLOBBASEFEE` オペコード（`block.blobbasefee`）で公開されます。\n"},"ko":{"lang":"ko","tldr":"BASEFEE 오퍼코드(0x48)를 추가했다. 현재 블록의 EIP-1559 베이스 피를 반환해 컨트랙트가 네트워크 수수료 수준에 반응할 수 있게 한다.","tags":["evm","opcode","gas","fees","london"],"related":[1559,3332,3416],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3198/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-1559](/eip-1559/)는 모든 블록에 프로토콜이 정하는 **가스당 베이스 피**를 부여했습니다. 이 숫자는 블록 헤더에 있지만, 새 오퍼코드가 없으면 컨트랙트가 이를 읽을 방법이 없었습니다.\n\n가스 가격이 중요한 컨트랙트는 추측, 관리자가 갱신하는 상수, 또는 `tx.gasprice`(호출자가 통제함)에 의존해야 했습니다. 명세가 드는 대표적인 사용 사례는 다음과 같습니다.\n\n- **키퍼 보상**: 사람들에게 \"찔러 달라\"고 보수를 주는 컨트랙트는 보상을 `basefee + x`나 `basefee * (1 + x)`로 정할 수 있습니다. 그러면 시장 상황과 상관없이 호출 비용을 항상 충당합니다.\n- **가스 가격 파생상품**: 가스에 대한 선물이나 옵션을 온체인의 조작에 강한 가격으로 정산할 수 있습니다.\n- **사기 증명 시스템**: 스테이트 채널과 옵티미스틱 롤업은 베이스 피가 높아 이의 제기를 올리는 비용이 클 때 챌린지 기간을 자동으로 늘릴 수 있습니다.\n\n## 어떻게 동작하나요?\n\n오퍼코드 하나이며, 런던 업그레이드에서 EIP-1559와 함께 활성화되었습니다.\n\n| 오퍼코드 | 이름 | 입력 | 출력 | 가스 |\n| --- | --- | --- | --- | --- |\n| `0x48` | `BASEFEE` | 0 | 1 | 2(`G_base`) |\n\n현재 실행 중인 블록의 베이스 피를 가스당 wei 단위로 32바이트 워드로 푸시합니다. 이 값은 실행이 시작되기 전에 이미 알려져 있고(트랜잭션 검증에 필요), 따라서 이 오퍼코드의 비용은 `NUMBER`나 `TIMESTAMP` 같은 다른 저렴한 환경 읽기와 같습니다.\n\n명세의 예: 베이스 피가 7 wei이면 바이트코드 `0x4800`(`BASEFEE`, `STOP`)은 스택에 `7`을 남기고 2 가스를 사용합니다.\n\n## 샘플 코드\n\nSolidity(0.8.7 이상)에서는 이 오퍼코드가 `block.basefee`로 노출됩니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract PokeBounty {\n    uint256 public constant POKE_GAS = 60_000;\n    uint256 public lastPoke;\n\n    receive() external payable {}\n\n    function poke() external {\n        require(block.timestamp \u003e= lastPoke + 1 hours, \"too soon\");\n        lastPoke = block.timestamp;\n        // ... do the periodic work ...\n\n        // Reimburse at base fee plus a 20% margin, independent of the caller's tip.\n        uint256 reward = POKE_GAS * block.basefee * 12 / 10;\n        (bool ok, ) = msg.sender.call{value: reward}(\"\");\n        require(ok, \"pay failed\");\n    }\n\n    function priorityFeePaid() external view returns (uint256) {\n        return tx.gasprice - block.basefee; // the tip per gas this tx actually pays\n    }\n}\n```\n\n오프체인 코드에서는 같은 값이 블록 헤더(`baseFeePerGas`)에 있습니다.\n\n```ts\nconst block = await provider.getBlock(\"latest\");\nconsole.log(block!.baseFeePerGas); // bigint, wei per gas\n```\n\n## 알아둘 점\n\n- 상태: **Final**. 런던 업그레이드(2021년 8월) 이후 메인넷에서 동작 중입니다.\n- `tx.gasprice - block.basefee`로 현재 트랜잭션의 실효 우선 수수료를 구할 수 있습니다.\n- `eth_call` 시뮬레이션에서는 가스 가격이 제공되지 않으면 일부 노드가 베이스 피 0으로 실행하므로, 그곳에서는 `block.basefee`가 0으로 읽힐 수 있습니다. 이를 네트워크의 실제 값으로 취급하지 마세요.\n- 베이스 피는 블록당 최대 12.5%까지 변동할 수 있으므로, 이를 기반으로 한 보상은 호출자가 지불한 금액의 대략적인 추정치일 뿐입니다.\n- 블롭 트랜잭션에는 별도의 블롭 베이스 피가 있으며, 이 오퍼코드가 아니라 `BLOBBASEFEE` 오퍼코드(`block.blobbasefee`)로 노출됩니다.\n"},"zh":{"lang":"zh","tldr":"新增 BASEFEE 操作码（0x48），返回当前区块的 EIP-1559 基础费用，让合约可以根据网络费用水平作出反应。","tags":["evm","opcode","gas","fees","london"],"related":[1559,3332,3416],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3198/","markdown":"## 它解决什么问题？\n\n[EIP-1559](/eip-1559/) 为每个区块设定了由协议决定的**每单位 gas 基础费用**。这个数字存放在区块头中，但没有新的操作码，合约就无法读取它。\n\n关心 gas 价格的合约只能依靠猜测、由管理员更新的常量，或 `tx.gasprice`（由调用者控制）。规范给出的典型用例：\n\n- **Keeper 赏金**：为\"戳一下\"合约而向人付费的合约，可以把奖励设为 `basefee + x` 或 `basefee * (1 + x)`，这样无论市场状况如何，都能始终覆盖调用的成本。\n- **gas 价格衍生品**：关于 gas 的期货或期权可以对照链上难以操纵的价格进行结算。\n- **欺诈证明系统**：状态通道和 optimistic rollup 可以在基础费用较高、提交质疑成本昂贵时，自动延长质疑期。\n\n## 它如何运作\n\n一个操作码，在伦敦升级中与 EIP-1559 一同激活：\n\n| 操作码 | 名称 | 输入 | 输出 | Gas |\n| --- | --- | --- | --- | --- |\n| `0x48` | `BASEFEE` | 0 | 1 | 2（`G_base`） |\n\n它把当前正在执行的区块的基础费用（单位为每 gas 多少 wei）作为 32 字节的字压入栈。该值在执行开始前就已知（验证交易时需要它），因此该操作码的成本与 `NUMBER` 或 `TIMESTAMP` 等其他廉价的环境读取相同。\n\n规范中的示例：若基础费用为 7 wei，字节码 `0x4800`（`BASEFEE`、`STOP`）会在栈上留下 `7`，并消耗 2 gas。\n\n## 示例代码\n\n在 Solidity（0.8.7 及以后）中，该操作码以 `block.basefee` 的形式提供：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract PokeBounty {\n    uint256 public constant POKE_GAS = 60_000;\n    uint256 public lastPoke;\n\n    receive() external payable {}\n\n    function poke() external {\n        require(block.timestamp \u003e= lastPoke + 1 hours, \"too soon\");\n        lastPoke = block.timestamp;\n        // ... do the periodic work ...\n\n        // Reimburse at base fee plus a 20% margin, independent of the caller's tip.\n        uint256 reward = POKE_GAS * block.basefee * 12 / 10;\n        (bool ok, ) = msg.sender.call{value: reward}(\"\");\n        require(ok, \"pay failed\");\n    }\n\n    function priorityFeePaid() external view returns (uint256) {\n        return tx.gasprice - block.basefee; // the tip per gas this tx actually pays\n    }\n}\n```\n\n在链下代码中，同样的值位于区块头（`baseFeePerGas`）：\n\n```ts\nconst block = await provider.getBlock(\"latest\");\nconsole.log(block!.baseFeePerGas); // bigint, wei per gas\n```\n\n## 需要注意\n\n- 状态：**Final**。自伦敦升级（2021 年 8 月）起已在主网上线。\n- `tx.gasprice - block.basefee` 可得到当前交易的实际优先费。\n- 在 `eth_call` 模拟中，如果没有提供 gas 价格，一些节点会以 0 作为基础费用运行，因此那里的 `block.basefee` 可能读出 0。不要把它当作网络的真实值。\n- 基础费用每个区块最多可变动 12.5%，因此基于它的奖励只是对调用者所付费用的粗略估计。\n- Blob 交易有单独的 blob 基础费用，由 `BLOBBASEFEE` 操作码（`block.blobbasefee`）提供，而不是这个操作码。\n"}},"requiredBy":[7516]}
