{"eip":838,"title":"ABI specification for REVERT reason string","description":"A proposal to extend the ABI specification to include typed errors in the REVERT reason string.","authors":["Federico Bond (@federicobond)","Renan Rodrigues de Souza (@RenanSouza2)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2020-08-20","discussionsTo":"https://ethereum-magicians.org/t/eip-838-what-is-the-current-status/14671","repo":"ERCs","label":"ERC-838","officialUrl":"https://eips.ethereum.org/EIPS/eip-838","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-838.md","url":"https://eips.huatuo.xyz/eip-838/","tldr":{"en":"A Draft proposal to declare typed errors in a contract's JSON ABI and encode them in REVERT data with a selector, so clients can decode why a transaction failed.","ja":"コントラクトの JSON ABI に型付きエラーを宣言し、REVERT データにセレクター付きでエンコードして、クライアントがトランザクション失敗の理由をデコードできるようにする Draft 提案。","ko":"컨트랙트의 JSON ABI에 타입이 있는 에러를 선언하고 REVERT 데이터에 셀렉터와 함께 인코딩해, 클라이언트가 트랜잭션이 실패한 이유를 디코딩할 수 있게 하는 Draft 제안.","zh":"一项 Draft 提案：在合约的 JSON ABI 中声明带类型的错误，并以选择器的形式编码到 REVERT 数据中，使客户端能够解码交易失败的原因。"},"tags":["abi","errors","revert","solidity","draft"],"explainers":{"en":{"lang":"en","tldr":"A Draft proposal to declare typed errors in a contract's JSON ABI and encode them in REVERT data with a selector, so clients can decode why a transaction failed.","tags":["abi","errors","revert","solidity","draft"],"related":[140,6093,658],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-838/","markdown":"## What problem does it solve?\n\nThe `REVERT` opcode ([EIP-140](/eip-140/)) lets a contract stop execution, undo its changes, and return some bytes explaining why. At first the only convention for those bytes was a free-form string. A string is fine for people, but software cannot reliably branch on it, it cannot carry structured values, and long messages cost gas.\n\nERC-838 proposes treating errors like functions and events: declare them in the ABI with a name and typed arguments, and encode a **selector** plus the arguments in the revert data. Wallets and libraries can then look up the selector and show a precise, decoded error.\n\n## How it works\n\n- Compilers that produce a JSON ABI **should** include error entries next to functions and events, with `\"type\": \"error\"`, a `name`, and typed arguments.\n- A selector is computed from the error's signature, the same way as for a public function.\n- That selector **must** appear in the revert data so clients can look it up, followed by the encoded arguments.\n- A high-level language can then offer syntax for declaring and throwing errors.\n\nPossible extensions in the spec include a NatSpec `@notice` on an error to give a human-readable message, and listing the errors a function may throw in that function's ABI entry.\n\nThe Draft leaves the exact byte format, the rationale and security considerations \"to be defined\" or \"needs discussion\".\n\n## Sample code\n\nThe ABI entry shape from the proposal:\n\n```json\n{ \"type\": \"error\", \"name\": \"InsufficientBalance\",\n  \"arguments\": [ { \"name\": \"amount\", \"type\": \"uint256\" } ] }\n```\n\nWhat this looks like in practice with Solidity custom errors, which follow the same idea:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// @notice You don't have enough funds to withdraw `amount`.\n    error InsufficientBalance(uint256 available, uint256 amount);\n\n    mapping(address =\u003e uint256) public balance;\n\n    function withdraw(uint256 amount) external {\n        uint256 bal = balance[msg.sender];\n        if (bal \u003c amount) revert InsufficientBalance(bal, amount);\n        balance[msg.sender] = bal - amount;\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\nDecoding the error off chain with ethers v6:\n\n```ts\nimport { Interface } from \"ethers\";\n\nconst iface = new Interface([\"error InsufficientBalance(uint256 available, uint256 amount)\"]);\nconst parsed = iface.parseError(revertData);   // revertData: hex string from the failed call\nconsole.log(parsed?.name, parsed?.args);       // \"InsufficientBalance\", [10n, 25n]\n```\n\n## Things to know\n\n- **This proposal is still a Draft and was never finalized.** It has no binding byte format.\n- In practice the ecosystem settled on what Solidity shipped: custom errors encoded as a 4-byte selector followed by standard ABI-encoded arguments, and ABI entries of `\"type\": \"error\"` with an `inputs` array (not `arguments`, as in the Draft).\n- Plain `require(cond, \"msg\")` strings are encoded as the built-in `Error(string)` error, selector `0x08c379a0`.\n- [ERC-6093](/eip-6093/) standardizes common custom error names for token contracts.\n"},"ja":{"lang":"ja","tldr":"コントラクトの JSON ABI に型付きエラーを宣言し、REVERT データにセレクター付きでエンコードして、クライアントがトランザクション失敗の理由をデコードできるようにする Draft 提案。","tags":["abi","errors","revert","solidity","draft"],"related":[140,6093,658],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-838/","markdown":"## 何を解決するのか\n\n`REVERT` オペコード（[EIP-140](/eip-140/)）により、コントラクトは実行を停止し、変更を取り消し、理由を説明するバイト列を返せます。当初、そのバイト列の慣習は自由形式の文字列だけでした。文字列は人間には十分ですが、ソフトウェアはそれで確実に分岐できず、構造化された値も運べず、長いメッセージはガスを消費します。\n\nERC-838 は、エラーを関数やイベントのように扱うことを提案します。名前と型付きの引数を持つエラーを ABI に宣言し、リバートデータには**セレクター**と引数をエンコードして入れます。そうすればウォレットやライブラリはセレクターを引き当て、正確にデコードされたエラーを表示できます。\n\n## 仕組み\n\n- JSON ABI を生成するコンパイラは、関数やイベントと並べて、`\"type\": \"error\"`、`name`、型付きの引数を持つエラーエントリを含める**べき**（should）です。\n- セレクターは、public 関数と同じ方法で、エラーのシグネチャから計算されます。\n- そのセレクターは、クライアントが引き当てられるよう、リバートデータに含まれていなければ**なりません**（must）。その後ろにエンコードされた引数が続きます。\n- 高水準言語は、エラーを宣言して投げるための構文を提供できます。\n\n仕様に挙げられている拡張の可能性としては、人間が読めるメッセージを与えるためにエラーに NatSpec の `@notice` を付けること、関数が投げうるエラーをその関数の ABI エントリに列挙することがあります。\n\nこの Draft は、正確なバイト形式、根拠、セキュリティ上の考慮事項を「未定義（to be defined）」または「議論が必要（needs discussion）」のままにしています。\n\n## サンプルコード\n\n提案にある ABI エントリの形:\n\n```json\n{ \"type\": \"error\", \"name\": \"InsufficientBalance\",\n  \"arguments\": [ { \"name\": \"amount\", \"type\": \"uint256\" } ] }\n```\n\n同じ考え方に沿った Solidity のカスタムエラーでは、実際には次のようになります。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// @notice You don't have enough funds to withdraw `amount`.\n    error InsufficientBalance(uint256 available, uint256 amount);\n\n    mapping(address =\u003e uint256) public balance;\n\n    function withdraw(uint256 amount) external {\n        uint256 bal = balance[msg.sender];\n        if (bal \u003c amount) revert InsufficientBalance(bal, amount);\n        balance[msg.sender] = bal - amount;\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\nethers v6 でオフチェーンでエラーをデコードする:\n\n```ts\nimport { Interface } from \"ethers\";\n\nconst iface = new Interface([\"error InsufficientBalance(uint256 available, uint256 amount)\"]);\nconst parsed = iface.parseError(revertData);   // revertData: hex string from the failed call\nconsole.log(parsed?.name, parsed?.args);       // \"InsufficientBalance\", [10n, 25n]\n```\n\n## 知っておくべきこと\n\n- **この提案はまだ Draft で、確定されたことはありません。** 拘束力のあるバイト形式はありません。\n- 実際には、エコシステムは Solidity が出荷したものに落ち着きました。つまり、4 バイトのセレクターに標準の ABI エンコードされた引数が続くカスタムエラーと、（Draft の `arguments` ではなく）`inputs` 配列を持つ `\"type\": \"error\"` の ABI エントリです。\n- 単純な `require(cond, \"msg\")` の文字列は、組み込みの `Error(string)` エラー（セレクター `0x08c379a0`）としてエンコードされます。\n- [ERC-6093](/eip-6093/) は、トークンコントラクト向けの一般的なカスタムエラー名を標準化しています。\n"},"ko":{"lang":"ko","tldr":"컨트랙트의 JSON ABI에 타입이 있는 에러를 선언하고 REVERT 데이터에 셀렉터와 함께 인코딩해, 클라이언트가 트랜잭션이 실패한 이유를 디코딩할 수 있게 하는 Draft 제안.","tags":["abi","errors","revert","solidity","draft"],"related":[140,6093,658],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-838/","markdown":"## 어떤 문제를 해결하나요?\n\n`REVERT` opcode([EIP-140](/eip-140/))를 쓰면 컨트랙트가 실행을 멈추고, 변경을 되돌리고, 이유를 설명하는 바이트를 반환할 수 있습니다. 처음에는 그 바이트에 대한 유일한 관례가 자유 형식의 문자열이었습니다. 문자열은 사람에게는 괜찮지만, 소프트웨어는 이를 믿고 분기할 수 없고, 구조화된 값을 담을 수 없으며, 긴 메시지는 가스를 소모합니다.\n\nERC-838은 에러를 함수나 이벤트처럼 취급하자고 제안합니다. 이름과 타입이 있는 인자로 ABI에 선언하고, 리버트 데이터에는 **셀렉터**와 인자를 인코딩해 넣는 것입니다. 그러면 지갑과 라이브러리가 셀렉터를 찾아 정확히 디코딩된 에러를 보여줄 수 있습니다.\n\n## 어떻게 동작하나요?\n\n- JSON ABI를 생성하는 컴파일러는 함수와 이벤트 옆에 `\"type\": \"error\"`, `name`, 타입이 있는 인자를 갖는 에러 항목을 포함**해야 합니다**(should).\n- 셀렉터는 public 함수와 같은 방식으로 에러의 시그니처에서 계산합니다.\n- 클라이언트가 조회할 수 있도록 그 셀렉터가 리버트 데이터에 **반드시** 들어가야 하며(must), 그 뒤에 인코딩된 인자가 옵니다.\n- 그러면 고수준 언어가 에러를 선언하고 던지기 위한 문법을 제공할 수 있습니다.\n\n명세에 나오는 확장 가능성으로는 사람이 읽을 수 있는 메시지를 주기 위해 에러에 NatSpec `@notice`를 붙이는 것, 함수가 던질 수 있는 에러를 그 함수의 ABI 항목에 나열하는 것이 있습니다.\n\n이 Draft는 정확한 바이트 형식, 근거, 보안 고려 사항을 \"정의 예정(to be defined)\" 또는 \"논의 필요(needs discussion)\"로 남겨 두었습니다.\n\n## 샘플 코드\n\n제안에 나온 ABI 항목의 형태:\n\n```json\n{ \"type\": \"error\", \"name\": \"InsufficientBalance\",\n  \"arguments\": [ { \"name\": \"amount\", \"type\": \"uint256\" } ] }\n```\n\n같은 발상을 따르는 Solidity 커스텀 에러는 실제로 이렇게 생겼습니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// @notice You don't have enough funds to withdraw `amount`.\n    error InsufficientBalance(uint256 available, uint256 amount);\n\n    mapping(address =\u003e uint256) public balance;\n\n    function withdraw(uint256 amount) external {\n        uint256 bal = balance[msg.sender];\n        if (bal \u003c amount) revert InsufficientBalance(bal, amount);\n        balance[msg.sender] = bal - amount;\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\nethers v6로 오프체인에서 에러 디코딩하기:\n\n```ts\nimport { Interface } from \"ethers\";\n\nconst iface = new Interface([\"error InsufficientBalance(uint256 available, uint256 amount)\"]);\nconst parsed = iface.parseError(revertData);   // revertData: hex string from the failed call\nconsole.log(parsed?.name, parsed?.args);       // \"InsufficientBalance\", [10n, 25n]\n```\n\n## 알아둘 점\n\n- **이 제안은 아직 Draft이며 최종 확정된 적이 없습니다.** 구속력 있는 바이트 형식이 없습니다.\n- 실제로는 생태계가 Solidity가 내놓은 방식으로 자리 잡았습니다. 즉 4바이트 셀렉터 뒤에 표준 ABI 인코딩 인자가 오는 커스텀 에러, 그리고 (Draft의 `arguments`가 아니라) `inputs` 배열을 가진 `\"type\": \"error\"` ABI 항목입니다.\n- 평범한 `require(cond, \"msg\")` 문자열은 내장 `Error(string)` 에러(셀렉터 `0x08c379a0`)로 인코딩됩니다.\n- [ERC-6093](/eip-6093/)은 토큰 컨트랙트를 위한 일반적인 커스텀 에러 이름을 표준화합니다.\n"},"zh":{"lang":"zh","tldr":"一项 Draft 提案：在合约的 JSON ABI 中声明带类型的错误，并以选择器的形式编码到 REVERT 数据中，使客户端能够解码交易失败的原因。","tags":["abi","errors","revert","solidity","draft"],"related":[140,6093,658],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-838/","markdown":"## 它解决什么问题？\n\n`REVERT` 操作码（[EIP-140](/eip-140/)）让合约可以停止执行、撤销更改，并返回一些解释原因的字节。起初，这些字节唯一的约定是自由格式的字符串。字符串对人来说没问题，但软件无法可靠地据此分支，它无法携带结构化的值，而且较长的消息会消耗 gas。\n\nERC-838 提议像对待函数和事件一样对待错误：在 ABI 中用名称和带类型的参数声明它们，并在回滚数据中编码**选择器**加参数。这样钱包和库就可以查找该选择器，显示精确的、已解码的错误。\n\n## 它如何运作\n\n- 生成 JSON ABI 的编译器**应当**在函数和事件之外包含错误条目，带有 `\"type\": \"error\"`、`name` 和带类型的参数。\n- 选择器根据错误的签名计算，方式与公共函数相同。\n- 该选择器**必须**出现在回滚数据中，以便客户端查找，后面跟着编码后的参数。\n- 这样，高级语言就可以提供用于声明和抛出错误的语法。\n\n规范中提到的可能扩展包括：在错误上使用 NatSpec 的 `@notice` 来提供人类可读的消息，以及在函数的 ABI 条目中列出该函数可能抛出的错误。\n\n该 Draft 将确切的字节格式、设计理由和安全考量留作\"待定义\"或\"需要讨论\"。\n\n## 示例代码\n\n提案中的 ABI 条目形式：\n\n```json\n{ \"type\": \"error\", \"name\": \"InsufficientBalance\",\n  \"arguments\": [ { \"name\": \"amount\", \"type\": \"uint256\" } ] }\n```\n\n遵循相同思路的 Solidity 自定义错误在实践中是这样的：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    /// @notice You don't have enough funds to withdraw `amount`.\n    error InsufficientBalance(uint256 available, uint256 amount);\n\n    mapping(address =\u003e uint256) public balance;\n\n    function withdraw(uint256 amount) external {\n        uint256 bal = balance[msg.sender];\n        if (bal \u003c amount) revert InsufficientBalance(bal, amount);\n        balance[msg.sender] = bal - amount;\n        payable(msg.sender).transfer(amount);\n    }\n}\n```\n\n用 ethers v6 在链下解码错误：\n\n```ts\nimport { Interface } from \"ethers\";\n\nconst iface = new Interface([\"error InsufficientBalance(uint256 available, uint256 amount)\"]);\nconst parsed = iface.parseError(revertData);   // revertData: hex string from the failed call\nconsole.log(parsed?.name, parsed?.args);       // \"InsufficientBalance\", [10n, 25n]\n```\n\n## 需要注意\n\n- **该提案仍处于 Draft 状态，从未最终确定。** 它没有具有约束力的字节格式。\n- 实际上，生态系统采用了 Solidity 所发布的做法：自定义错误编码为 4 字节选择器加标准 ABI 编码的参数，ABI 条目为 `\"type\": \"error\"`，带有 `inputs` 数组（而不是 Draft 中的 `arguments`）。\n- 普通的 `require(cond, \"msg\")` 字符串会被编码为内置的 `Error(string)` 错误，选择器为 `0x08c379a0`。\n- [ERC-6093](/eip-6093/) 标准化了代币合约常用的自定义错误名称。\n"}}}
