{"eip":6093,"title":"Custom errors for commonly-used tokens","description":"Lists custom errors for common token implementations","authors":["Ernesto García (@ernestognw)","Francisco Giordano (@frangio)","Hadrien Croubois (@Amxx)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2022-12-06","requires":[20,721,1155],"discussionsTo":"https://ethereum-magicians.org/t/eip-6093-custom-errors-for-erc-tokens/12043","repo":"ERCs","label":"ERC-6093","officialUrl":"https://eips.ethereum.org/EIPS/eip-6093","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6093.md","url":"https://eips.huatuo.xyz/eip-6093/","tldr":{"en":"A shared set of Solidity custom errors for ERC-20, ERC-721 and ERC-1155 tokens, so wallets and tools can decode why a token call reverted in a consistent, structured way.","ja":"ERC-20、ERC-721、ERC-1155 トークンで共通に使える Solidity カスタムエラーのセット。ウォレットやツールが、トークン呼び出しが revert した理由を、一貫した構造化された方法でデコードできるようにする。","ko":"ERC-20, ERC-721, ERC-1155 토큰이 함께 쓰는 Solidity 커스텀 에러 모음. 지갑과 도구가 토큰 호출이 revert된 이유를 일관되고 구조화된 방식으로 디코딩할 수 있게 한다.","zh":"一组适用于 ERC-20、ERC-721 和 ERC-1155 代币的共享 Solidity 自定义错误，让钱包和工具能以一致、结构化的方式解码代币调用为何 revert。"},"tags":["token","errors","solidity","standard"],"explainers":{"en":{"lang":"en","tldr":"A shared set of Solidity custom errors for ERC-20, ERC-721 and ERC-1155 tokens, so wallets and tools can decode why a token call reverted in a consistent, structured way.","tags":["token","errors","solidity","standard"],"related":[20,721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-6093/","markdown":"## What problem does it solve?\n\n[ERC-20](/eip-20/), [ERC-721](/eip-721/) and [ERC-1155](/eip-1155/) were finalized before Solidity 0.8.4 introduced custom errors, so none of them say how a failed call should report what went wrong. Every implementation invented its own revert strings (\"ERC20: transfer amount exceeds balance\", \"insufficient balance\", ...). Strings cost deployment gas, carry no machine-readable data, and differ from token to token.\n\nERC-6093 standardizes the error names and arguments, so a wallet or test framework can decode, say, \"allowance was 5, needed 10\" the same way for every compliant token.\n\n## How it works\n\nEvery error name follows one grammar:\n\n```\n\u003cDomain\u003e\u003cErrorPrefix\u003e\u003cSubject\u003e(\u003cArguments\u003e)\n```\n\n- **Domain**: `ERC20`, `ERC721` or `ERC1155`. The prefix avoids Solidity declaration clashes between same-named errors with different arguments.\n- **ErrorPrefix**: *why* it failed, e.g. `Invalid` or `Insufficient`.\n- **Subject**: *what* failed in one of the two token actions: transfer (sender, receiver, balance) or approval (approver, operator/spender).\n- **Arguments** are ordered *who*, *what*, *why*, with `tokenId` at the end when needed.\n\nExamples: `ERC20InsufficientBalance(sender, balance, needed)`, `ERC20InsufficientAllowance(spender, allowance, needed)`, `ERC721NonexistentToken(tokenId)`, `ERC721IncorrectOwner(sender, tokenId, owner)`, `ERC1155MissingApprovalForAll(operator, owner)`, `ERC1155InvalidArrayLength(idsLength, valuesLength)`.\n\nThe EIP defines *which* error to use in a scenario, not *whether* to revert; that remains up to each token standard and implementation. Usage rules keep errors precise, e.g. `ERC20InvalidSender` is for a zero-address sender, while a too-low balance must use `ERC20InsufficientBalance`.\n\n## Sample code\n\nUsing the ERC-20 errors in a token:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC20Errors {\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n    error ERC20InvalidSender(address sender);\n    error ERC20InvalidReceiver(address receiver);\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n    error ERC20InvalidApprover(address approver);\n    error ERC20InvalidSpender(address spender);\n}\n\nabstract contract Token is IERC20Errors {\n    mapping(address =\u003e uint256) internal _balances;\n\n    function _transfer(address from, address to, uint256 value) internal {\n        if (from == address(0)) revert ERC20InvalidSender(address(0));\n        if (to == address(0)) revert ERC20InvalidReceiver(address(0));\n        uint256 bal = _balances[from];\n        if (bal \u003c value) revert ERC20InsufficientBalance(from, bal, value);\n        unchecked { _balances[from] = bal - value; }\n        _balances[to] += value;\n    }\n}\n```\n\nDecoding the revert in a client (ethers v6):\n\n```ts\ntry {\n  await token.transfer(to, amount);\n} catch (e: any) {\n  const err = token.interface.parseError(e.data);\n  if (err?.name === \"ERC20InsufficientBalance\") {\n    const [sender, balance, needed] = err.args;\n    console.log(`${sender} has ${balance}, needs ${needed}`);\n  }\n}\n```\n\n## Things to know\n\n- Status is **Final**. OpenZeppelin Contracts 5.x ships these errors (`IERC20Errors`, `IERC721Errors`, `IERC1155Errors`), so most new tokens built on it emit them.\n- Older and non-upgradeable tokens still revert with strings or their own errors. Clients should tolerate both.\n- Upgrading a token to these errors can break off-chain systems that match on old revert strings.\n- Don't let a UI blindly act on decoded errors from untrusted contracts; a malicious contract can return any error data to nudge users into harmful actions.\n"},"ja":{"lang":"ja","tldr":"ERC-20、ERC-721、ERC-1155 トークンで共通に使える Solidity カスタムエラーのセット。ウォレットやツールが、トークン呼び出しが revert した理由を、一貫した構造化された方法でデコードできるようにする。","tags":["token","errors","solidity","standard"],"related":[20,721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-6093/","markdown":"## 何を解決するのか\n\n[ERC-20](/eip-20/)、[ERC-721](/eip-721/)、[ERC-1155](/eip-1155/) は、Solidity 0.8.4 でカスタムエラーが導入される前に確定したため、失敗した呼び出しが何が悪かったのかをどう報告すべきかについて、どれも何も定めていません。実装ごとに独自の revert 文字列（\"ERC20: transfer amount exceeds balance\"、\"insufficient balance\" など）が作られました。文字列はデプロイ時のガスがかかり、機械可読なデータを持たず、トークンごとに異なります。\n\nERC-6093 はエラー名と引数を標準化します。これにより、ウォレットやテストフレームワークは、たとえば「allowance は 5 で、必要なのは 10 だった」という情報を、準拠するすべてのトークンで同じ方法でデコードできます。\n\n## 仕組み\n\nすべてのエラー名は、1 つの文法に従います。\n\n```\n\u003cDomain\u003e\u003cErrorPrefix\u003e\u003cSubject\u003e(\u003cArguments\u003e)\n```\n\n- **Domain**: `ERC20`、`ERC721`、`ERC1155` のいずれか。引数が異なる同名のエラーによる Solidity の宣言の衝突を、このプレフィックスで避けます。\n- **ErrorPrefix**: *なぜ*失敗したか。たとえば `Invalid` や `Insufficient`。\n- **Subject**: トークンの 2 つのアクション（転送: 送信者・受信者・残高、承認: 承認者・オペレーター/スペンダー）のうち、*何が*失敗したか。\n- **Arguments** は、*誰が*、*何を*、*なぜ*の順に並び、必要な場合は `tokenId` が最後に来ます。\n\n例: `ERC20InsufficientBalance(sender, balance, needed)`、`ERC20InsufficientAllowance(spender, allowance, needed)`、`ERC721NonexistentToken(tokenId)`、`ERC721IncorrectOwner(sender, tokenId, owner)`、`ERC1155MissingApprovalForAll(operator, owner)`、`ERC1155InvalidArrayLength(idsLength, valuesLength)`。\n\nこの EIP が定めるのは、あるシナリオで*どの*エラーを使うかであり、*revert するかどうか*ではありません。それは各トークン標準と実装に委ねられています。使用ルールによって、エラーは正確に保たれます。たとえば `ERC20InvalidSender` はゼロアドレスの送信者のためのもので、残高不足には必ず `ERC20InsufficientBalance` を使わなければなりません。\n\n## サンプルコード\n\nトークンで ERC-20 のエラーを使う例です。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC20Errors {\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n    error ERC20InvalidSender(address sender);\n    error ERC20InvalidReceiver(address receiver);\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n    error ERC20InvalidApprover(address approver);\n    error ERC20InvalidSpender(address spender);\n}\n\nabstract contract Token is IERC20Errors {\n    mapping(address =\u003e uint256) internal _balances;\n\n    function _transfer(address from, address to, uint256 value) internal {\n        if (from == address(0)) revert ERC20InvalidSender(address(0));\n        if (to == address(0)) revert ERC20InvalidReceiver(address(0));\n        uint256 bal = _balances[from];\n        if (bal \u003c value) revert ERC20InsufficientBalance(from, bal, value);\n        unchecked { _balances[from] = bal - value; }\n        _balances[to] += value;\n    }\n}\n```\n\nクライアントで revert をデコードする例です（ethers v6）。\n\n```ts\ntry {\n  await token.transfer(to, amount);\n} catch (e: any) {\n  const err = token.interface.parseError(e.data);\n  if (err?.name === \"ERC20InsufficientBalance\") {\n    const [sender, balance, needed] = err.args;\n    console.log(`${sender} has ${balance}, needs ${needed}`);\n  }\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Final** です。OpenZeppelin Contracts 5.x はこれらのエラー（`IERC20Errors`、`IERC721Errors`、`IERC1155Errors`）を同梱しているため、それを使って作られた新しいトークンの多くがこれらを emit します。\n- 古いトークンやアップグレード不可能なトークンは、依然として文字列や独自のエラーで revert します。クライアントは両方を許容すべきです。\n- トークンをこれらのエラーにアップグレードすると、古い revert 文字列に一致させているオフチェーンのシステムが壊れる可能性があります。\n- 信頼できないコントラクトからデコードしたエラーに、UI が盲目的に反応してはいけません。悪意のあるコントラクトは任意のエラーデータを返して、ユーザーを有害な操作に誘導できます。\n"},"ko":{"lang":"ko","tldr":"ERC-20, ERC-721, ERC-1155 토큰이 함께 쓰는 Solidity 커스텀 에러 모음. 지갑과 도구가 토큰 호출이 revert된 이유를 일관되고 구조화된 방식으로 디코딩할 수 있게 한다.","tags":["token","errors","solidity","standard"],"related":[20,721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-6093/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-20](/eip-20/), [ERC-721](/eip-721/), [ERC-1155](/eip-1155/)는 Solidity 0.8.4가 커스텀 에러를 도입하기 전에 확정되었기 때문에, 실패한 호출이 무엇이 잘못되었는지 어떻게 알려야 하는지 어느 것도 정해 두지 않았습니다. 구현마다 자체 revert 문자열(\"ERC20: transfer amount exceeds balance\", \"insufficient balance\" 등)을 만들어 냈습니다. 문자열은 배포 가스가 들고, 기계가 읽을 수 있는 데이터가 없으며, 토큰마다 다릅니다.\n\nERC-6093은 에러 이름과 인자를 표준화하여, 지갑이나 테스트 프레임워크가 예를 들어 \"allowance는 5였고 필요한 값은 10이었다\"를 모든 규격 준수 토큰에서 같은 방식으로 디코딩할 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n모든 에러 이름은 하나의 문법을 따릅니다.\n\n```\n\u003cDomain\u003e\u003cErrorPrefix\u003e\u003cSubject\u003e(\u003cArguments\u003e)\n```\n\n- **Domain**: `ERC20`, `ERC721`, `ERC1155` 중 하나. 이 접두사는 인자가 다른 같은 이름의 에러 사이에서 생기는 Solidity 선언 충돌을 피합니다.\n- **ErrorPrefix**: *왜* 실패했는지. 예: `Invalid`, `Insufficient`.\n- **Subject**: 토큰의 두 가지 동작 중 *무엇이* 실패했는지. 전송(송신자, 수신자, 잔액) 또는 승인(승인자, 오퍼레이터/스펜더).\n- **Arguments**는 *누가*, *무엇을*, *왜* 순서로 배열되며, 필요하면 `tokenId`가 맨 뒤에 옵니다.\n\n예: `ERC20InsufficientBalance(sender, balance, needed)`, `ERC20InsufficientAllowance(spender, allowance, needed)`, `ERC721NonexistentToken(tokenId)`, `ERC721IncorrectOwner(sender, tokenId, owner)`, `ERC1155MissingApprovalForAll(operator, owner)`, `ERC1155InvalidArrayLength(idsLength, valuesLength)`.\n\n이 EIP가 정하는 것은 어떤 시나리오에서 *어떤* 에러를 쓸지이며, *revert할지 여부*가 아닙니다. 그것은 각 토큰 표준과 구현에 달려 있습니다. 사용 규칙은 에러를 정확하게 유지합니다. 예를 들어 `ERC20InvalidSender`는 송신자가 제로 주소일 때를 위한 것이고, 잔액 부족에는 반드시 `ERC20InsufficientBalance`를 써야 합니다.\n\n## 샘플 코드\n\n토큰에서 ERC-20 에러를 사용하는 예시입니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC20Errors {\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n    error ERC20InvalidSender(address sender);\n    error ERC20InvalidReceiver(address receiver);\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n    error ERC20InvalidApprover(address approver);\n    error ERC20InvalidSpender(address spender);\n}\n\nabstract contract Token is IERC20Errors {\n    mapping(address =\u003e uint256) internal _balances;\n\n    function _transfer(address from, address to, uint256 value) internal {\n        if (from == address(0)) revert ERC20InvalidSender(address(0));\n        if (to == address(0)) revert ERC20InvalidReceiver(address(0));\n        uint256 bal = _balances[from];\n        if (bal \u003c value) revert ERC20InsufficientBalance(from, bal, value);\n        unchecked { _balances[from] = bal - value; }\n        _balances[to] += value;\n    }\n}\n```\n\n클라이언트에서 revert를 디코딩하는 예시(ethers v6)입니다.\n\n```ts\ntry {\n  await token.transfer(to, amount);\n} catch (e: any) {\n  const err = token.interface.parseError(e.data);\n  if (err?.name === \"ERC20InsufficientBalance\") {\n    const [sender, balance, needed] = err.args;\n    console.log(`${sender} has ${balance}, needs ${needed}`);\n  }\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Final**입니다. OpenZeppelin Contracts 5.x는 이 에러들(`IERC20Errors`, `IERC721Errors`, `IERC1155Errors`)을 포함하므로, 이를 기반으로 만든 대부분의 새 토큰이 이 에러를 emit합니다.\n- 오래된 토큰과 업그레이드할 수 없는 토큰은 여전히 문자열이나 자체 에러로 revert합니다. 클라이언트는 둘 다 허용해야 합니다.\n- 토큰을 이 에러들로 업그레이드하면 예전 revert 문자열에 맞춰 동작하던 오프체인 시스템이 깨질 수 있습니다.\n- UI가 신뢰할 수 없는 컨트랙트에서 디코딩한 에러를 무작정 따라 동작하게 하지 마세요. 악의적인 컨트랙트는 임의의 에러 데이터를 반환해 사용자가 해로운 행동을 하도록 유도할 수 있습니다.\n"},"zh":{"lang":"zh","tldr":"一组适用于 ERC-20、ERC-721 和 ERC-1155 代币的共享 Solidity 自定义错误，让钱包和工具能以一致、结构化的方式解码代币调用为何 revert。","tags":["token","errors","solidity","standard"],"related":[20,721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-6093/","markdown":"## 它解决什么问题？\n\n[ERC-20](/eip-20/)、[ERC-721](/eip-721/) 和 [ERC-1155](/eip-1155/) 在 Solidity 0.8.4 引入自定义错误之前就已定稿，所以它们都没有规定失败的调用应如何报告出了什么问题。每个实现都发明了自己的 revert 字符串（\"ERC20: transfer amount exceeds balance\"、\"insufficient balance\" 等）。字符串会消耗部署 gas，不携带机器可读的数据，而且每种代币各不相同。\n\nERC-6093 标准化了错误名称和参数，使钱包或测试框架能够以同样的方式解码任何合规代币的错误，例如\"allowance 为 5，需要 10\"。\n\n## 它如何运作\n\n每个错误名称都遵循同一种语法：\n\n```\n\u003cDomain\u003e\u003cErrorPrefix\u003e\u003cSubject\u003e(\u003cArguments\u003e)\n```\n\n- **Domain**：`ERC20`、`ERC721` 或 `ERC1155`。这个前缀可以避免同名但参数不同的错误引发 Solidity 声明冲突。\n- **ErrorPrefix**：*为什么*失败，例如 `Invalid` 或 `Insufficient`。\n- **Subject**：在代币的两种操作之一中，*什么*失败了：转账（发送方、接收方、余额）或授权（授权方、操作员/花费者）。\n- **Arguments** 的顺序是*谁*、*什么*、*为什么*，需要时把 `tokenId` 放在最后。\n\n例如：`ERC20InsufficientBalance(sender, balance, needed)`、`ERC20InsufficientAllowance(spender, allowance, needed)`、`ERC721NonexistentToken(tokenId)`、`ERC721IncorrectOwner(sender, tokenId, owner)`、`ERC1155MissingApprovalForAll(operator, owner)`、`ERC1155InvalidArrayLength(idsLength, valuesLength)`。\n\n该 EIP 规定的是在某种场景下使用*哪个*错误，而不是*是否* revert；后者仍由各代币标准和实现决定。使用规则使错误保持精确，例如 `ERC20InvalidSender` 用于发送方为零地址的情况，而余额不足必须使用 `ERC20InsufficientBalance`。\n\n## 示例代码\n\n在代币中使用 ERC-20 错误：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC20Errors {\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n    error ERC20InvalidSender(address sender);\n    error ERC20InvalidReceiver(address receiver);\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n    error ERC20InvalidApprover(address approver);\n    error ERC20InvalidSpender(address spender);\n}\n\nabstract contract Token is IERC20Errors {\n    mapping(address =\u003e uint256) internal _balances;\n\n    function _transfer(address from, address to, uint256 value) internal {\n        if (from == address(0)) revert ERC20InvalidSender(address(0));\n        if (to == address(0)) revert ERC20InvalidReceiver(address(0));\n        uint256 bal = _balances[from];\n        if (bal \u003c value) revert ERC20InsufficientBalance(from, bal, value);\n        unchecked { _balances[from] = bal - value; }\n        _balances[to] += value;\n    }\n}\n```\n\n在客户端解码 revert（ethers v6）：\n\n```ts\ntry {\n  await token.transfer(to, amount);\n} catch (e: any) {\n  const err = token.interface.parseError(e.data);\n  if (err?.name === \"ERC20InsufficientBalance\") {\n    const [sender, balance, needed] = err.args;\n    console.log(`${sender} has ${balance}, needs ${needed}`);\n  }\n}\n```\n\n## 需要注意\n\n- 状态为 **Final**。OpenZeppelin Contracts 5.x 内置了这些错误（`IERC20Errors`、`IERC721Errors`、`IERC1155Errors`），所以大多数基于它构建的新代币都会抛出这些错误。\n- 较旧的和不可升级的代币仍然使用字符串或自己的错误来 revert。客户端应同时兼容两者。\n- 把代币升级为使用这些错误，可能会破坏那些匹配旧 revert 字符串的链下系统。\n- 不要让 UI 盲目地根据来自不受信任合约的解码错误采取行动；恶意合约可以返回任意错误数据，诱导用户做出有害的操作。\n"}},"requiredBy":[1450]}
