{"eip":165,"title":"Standard Interface Detection","description":"Creates a standard method to publish and detect what interfaces a smart contract implements.","authors":["Christian Reitwießner \u003cchris@ethereum.org\u003e","Nick Johnson \u003cnick@ethereum.org\u003e","Fabian Vogelsteller \u003cfabian@lukso.network\u003e","Jordi Baylina \u003cjordi@baylina.cat\u003e","Konrad Feldmeier \u003ckonrad.feldmeier@brainbot.com\u003e","William Entriken \u003cgithub.com@phor.net\u003e"],"status":"Final","type":"Standards Track","category":"ERC","created":"2018-01-23","requires":[214],"repo":"ERCs","label":"ERC-165","officialUrl":"https://eips.ethereum.org/EIPS/eip-165","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-165.md","url":"https://eips.huatuo.xyz/eip-165/","tldr":{"en":"A single supportsInterface(bytes4) function that lets any contract declare which interfaces it implements, so other contracts and apps can check before calling.","ja":"supportsInterface(bytes4) という 1 つの関数で、コントラクトがどのインターフェースを実装しているかを宣言できるようにし、他のコントラクトやアプリが呼び出す前に確認できるようにする。","ko":"supportsInterface(bytes4) 함수 하나로 컨트랙트가 어떤 인터페이스를 구현하는지 선언할 수 있게 해서, 다른 컨트랙트와 앱이 호출하기 전에 확인할 수 있도록 한다.","zh":"一个 supportsInterface(bytes4) 函数，让任何合约都能声明自己实现了哪些接口，这样其他合约和应用在调用之前就能先检查。"},"tags":["interface","introspection","standard","erc"],"explainers":{"en":{"lang":"en","tldr":"A single supportsInterface(bytes4) function that lets any contract declare which interfaces it implements, so other contracts and apps can check before calling.","tags":["interface","introspection","standard","erc"],"related":[721,1155,20,214,1820],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-165/","markdown":"## What problem does it solve?\n\nA contract address on its own tells you nothing about what the contract can do. If a marketplace receives an address, it cannot tell whether that address is an NFT contract, a multi-token contract or something else. It can call a function and hope, but a missing function might revert, or fall through to a fallback that does something unexpected.\n\nERC-165 gives contracts a standard way to say \"I implement interface X\", and gives callers a safe way to ask.\n\n## How it works\n\n**Interface IDs.** An interface is identified by the XOR of the 4-byte function selectors of all its functions. For example, the ID of ERC-165 itself is the selector of `supportsInterface(bytes4)`, which is `0x01ffc9a7`.\n\n**Publishing.** A compliant contract implements:\n\n```solidity\nfunction supportsInterface(bytes4 interfaceID) external view returns (bool);\n```\n\nIt must return:\n\n- `true` for `0x01ffc9a7` (ERC-165 itself)\n- `false` for `0xffffffff`\n- `true` for every other interface it implements, and `false` otherwise\n\nThe function must use at most 30,000 gas.\n\n**Detecting.** To check whether a contract supports ERC-165 at all, make a `STATICCALL` ([EIP-214](/eip-214/)) with 30,000 gas. Ask `supportsInterface(0x01ffc9a7)`, which must return true. Then ask `supportsInterface(0xffffffff)`, which must return false. The second check catches older contracts whose fallback returns true for any call. If both checks pass, you can query any interface ID directly.\n\n## Sample code\n\nImplementing ERC-165 alongside a custom interface:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC165 {\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\ninterface IGreeter {\n    function greet() external view returns (string memory);\n}\n\ncontract Greeter is IERC165, IGreeter {\n    function supportsInterface(bytes4 id) external pure returns (bool) {\n        return id == type(IERC165).interfaceId   // 0x01ffc9a7\n            || id == type(IGreeter).interfaceId;\n    }\n\n    function greet() external pure returns (string memory) {\n        return \"hello\";\n    }\n}\n```\n\nChecking whether an address is an ERC-721 contract (ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst c = new Contract(addr, [\"function supportsInterface(bytes4) view returns (bool)\"], provider);\n\nconst isErc165 =\n  (await c.supportsInterface(\"0x01ffc9a7\")) \u0026\u0026 !(await c.supportsInterface(\"0xffffffff\"));\nconst isErc721 = isErc165 \u0026\u0026 (await c.supportsInterface(\"0x80ac58cd\"));\n```\n\n## Things to know\n\n- [ERC-721](/eip-721/) and [ERC-1155](/eip-1155/) require ERC-165, which is why NFT marketplaces can detect token types automatically. [ERC-20](/eip-20/) came earlier and does not require it.\n- The interface ID covers function selectors only. Events, return types and optional functions are not part of it.\n- A contract that returns `true` is only making a claim. ERC-165 does not prove the functions behave correctly.\n- In Solidity, `type(I).interfaceId` computes the ID for you. OpenZeppelin's `ERC165` base contract is the usual starting point.\n- [ERC-1820](/eip-1820/) is a registry-based alternative that also lets regular accounts (EOAs) register interfaces.\n"},"ja":{"lang":"ja","tldr":"supportsInterface(bytes4) という 1 つの関数で、コントラクトがどのインターフェースを実装しているかを宣言できるようにし、他のコントラクトやアプリが呼び出す前に確認できるようにする。","tags":["interface","introspection","standard","erc"],"related":[721,1155,20,214,1820],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-165/","markdown":"## 何を解決するのか\n\nコントラクトのアドレスだけでは、そのコントラクトに何ができるのか分かりません。マーケットプレイスがアドレスを受け取っても、それが NFT コントラクトなのか、マルチトークンコントラクトなのか、それ以外なのかを判別できません。関数を呼んで期待することはできますが、関数が存在しなければ revert するかもしれず、あるいは予期しない動作をするフォールバックに落ちるかもしれません。\n\nERC-165 は、コントラクトが「インターフェース X を実装している」と宣言するための標準的な方法と、呼び出し側が安全に問い合わせる方法を提供します。\n\n## 仕組み\n\n**インターフェース ID。** インターフェースは、そこに含まれるすべての関数の 4 バイトの関数セレクタの XOR で識別されます。たとえば ERC-165 自身の ID は `supportsInterface(bytes4)` のセレクタで、`0x01ffc9a7` です。\n\n**公開。** 準拠するコントラクトは次を実装します。\n\n```solidity\nfunction supportsInterface(bytes4 interfaceID) external view returns (bool);\n```\n\n戻り値は次のとおりでなければなりません。\n\n- `0x01ffc9a7`（ERC-165 自身）には `true`\n- `0xffffffff` には `false`\n- 実装している他のすべてのインターフェースには `true`、それ以外には `false`\n\nこの関数が使うガスは 30,000 以下でなければなりません。\n\n**検出。** コントラクトが ERC-165 をサポートしているかどうかを確認するには、30,000 ガスで `STATICCALL`（[EIP-214](/eip-214/)）を行います。まず `supportsInterface(0x01ffc9a7)` を問い合わせ、true が返る必要があります。次に `supportsInterface(0xffffffff)` を問い合わせ、false が返る必要があります。2 つ目のチェックは、どんな呼び出しにも true を返すフォールバックを持つ古いコントラクトを見つけるためのものです。両方に合格すれば、任意のインターフェース ID を直接問い合わせられます。\n\n## サンプルコード\n\nERC-165 をカスタムインターフェースと一緒に実装する例です。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC165 {\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\ninterface IGreeter {\n    function greet() external view returns (string memory);\n}\n\ncontract Greeter is IERC165, IGreeter {\n    function supportsInterface(bytes4 id) external pure returns (bool) {\n        return id == type(IERC165).interfaceId   // 0x01ffc9a7\n            || id == type(IGreeter).interfaceId;\n    }\n\n    function greet() external pure returns (string memory) {\n        return \"hello\";\n    }\n}\n```\n\nアドレスが ERC-721 コントラクトかどうかを確認する例（ethers v6）:\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst c = new Contract(addr, [\"function supportsInterface(bytes4) view returns (bool)\"], provider);\n\nconst isErc165 =\n  (await c.supportsInterface(\"0x01ffc9a7\")) \u0026\u0026 !(await c.supportsInterface(\"0xffffffff\"));\nconst isErc721 = isErc165 \u0026\u0026 (await c.supportsInterface(\"0x80ac58cd\"));\n```\n\n## 知っておくべきこと\n\n- [ERC-721](/eip-721/) と [ERC-1155](/eip-1155/) は ERC-165 を必須としており、そのため NFT マーケットプレイスはトークンの種類を自動的に判別できます。[ERC-20](/eip-20/) はそれより前に作られたため、必須ではありません。\n- インターフェース ID は関数セレクタだけが対象です。イベント、戻り値の型、任意の関数は含まれません。\n- `true` を返すコントラクトは、主張をしているだけです。ERC-165 は、関数が正しく動作することを証明するものではありません。\n- Solidity では、`type(I).interfaceId` が ID を計算してくれます。OpenZeppelin の `ERC165` 基底コントラクトが通常の出発点です。\n- [ERC-1820](/eip-1820/) はレジストリベースの代替案で、通常のアカウント（EOA）もインターフェースを登録できます。\n"},"ko":{"lang":"ko","tldr":"supportsInterface(bytes4) 함수 하나로 컨트랙트가 어떤 인터페이스를 구현하는지 선언할 수 있게 해서, 다른 컨트랙트와 앱이 호출하기 전에 확인할 수 있도록 한다.","tags":["interface","introspection","standard","erc"],"related":[721,1155,20,214,1820],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-165/","markdown":"## 어떤 문제를 해결하나요?\n\n컨트랙트 주소만으로는 그 컨트랙트가 무엇을 할 수 있는지 알 수 없습니다. 마켓플레이스가 주소를 받아도 그것이 NFT 컨트랙트인지, 멀티 토큰 컨트랙트인지, 다른 무엇인지 알 수 없습니다. 함수를 호출해 보고 기대할 수는 있지만, 함수가 없으면 revert될 수도 있고 예상치 못한 동작을 하는 fallback으로 빠질 수도 있습니다.\n\nERC-165는 컨트랙트가 \"나는 인터페이스 X를 구현한다\"고 말할 수 있는 표준 방법과, 호출자가 안전하게 물어볼 수 있는 방법을 제공합니다.\n\n## 어떻게 동작하나요?\n\n**인터페이스 ID.** 인터페이스는 포함된 모든 함수의 4바이트 함수 셀렉터를 XOR한 값으로 식별됩니다. 예를 들어 ERC-165 자체의 ID는 `supportsInterface(bytes4)`의 셀렉터인 `0x01ffc9a7`입니다.\n\n**공개.** 표준을 따르는 컨트랙트는 다음을 구현합니다.\n\n```solidity\nfunction supportsInterface(bytes4 interfaceID) external view returns (bool);\n```\n\n반환값은 다음과 같아야 합니다.\n\n- `0x01ffc9a7`(ERC-165 자체)에는 `true`\n- `0xffffffff`에는 `false`\n- 구현한 다른 모든 인터페이스에는 `true`, 그렇지 않으면 `false`\n\n이 함수는 최대 30,000 가스만 사용해야 합니다.\n\n**감지.** 컨트랙트가 ERC-165를 지원하는지 확인하려면 30,000 가스로 `STATICCALL`([EIP-214](/eip-214/))을 보냅니다. 먼저 `supportsInterface(0x01ffc9a7)`을 물어보면 true가 반환되어야 합니다. 그다음 `supportsInterface(0xffffffff)`를 물어보면 false가 반환되어야 합니다. 두 번째 확인은 어떤 호출에도 true를 반환하는 fallback을 가진 오래된 컨트랙트를 걸러냅니다. 두 확인을 모두 통과하면 어떤 인터페이스 ID든 직접 조회할 수 있습니다.\n\n## 샘플 코드\n\n커스텀 인터페이스와 함께 ERC-165를 구현하는 예입니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC165 {\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\ninterface IGreeter {\n    function greet() external view returns (string memory);\n}\n\ncontract Greeter is IERC165, IGreeter {\n    function supportsInterface(bytes4 id) external pure returns (bool) {\n        return id == type(IERC165).interfaceId   // 0x01ffc9a7\n            || id == type(IGreeter).interfaceId;\n    }\n\n    function greet() external pure returns (string memory) {\n        return \"hello\";\n    }\n}\n```\n\n주소가 ERC-721 컨트랙트인지 확인하는 예(ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst c = new Contract(addr, [\"function supportsInterface(bytes4) view returns (bool)\"], provider);\n\nconst isErc165 =\n  (await c.supportsInterface(\"0x01ffc9a7\")) \u0026\u0026 !(await c.supportsInterface(\"0xffffffff\"));\nconst isErc721 = isErc165 \u0026\u0026 (await c.supportsInterface(\"0x80ac58cd\"));\n```\n\n## 알아둘 점\n\n- [ERC-721](/eip-721/)과 [ERC-1155](/eip-1155/)는 ERC-165를 요구하기 때문에 NFT 마켓플레이스가 토큰 유형을 자동으로 감지할 수 있습니다. [ERC-20](/eip-20/)은 그보다 먼저 나왔기 때문에 요구하지 않습니다.\n- 인터페이스 ID는 함수 셀렉터만 포함합니다. 이벤트, 반환 타입, 선택적 함수는 포함되지 않습니다.\n- `true`를 반환하는 컨트랙트는 주장을 하는 것일 뿐입니다. ERC-165는 함수가 올바르게 동작함을 증명하지 않습니다.\n- Solidity에서는 `type(I).interfaceId`가 ID를 계산해 줍니다. OpenZeppelin의 `ERC165` 베이스 컨트랙트가 보통의 출발점입니다.\n- [ERC-1820](/eip-1820/)은 레지스트리 기반의 대안으로, 일반 계정(EOA)도 인터페이스를 등록할 수 있습니다.\n"},"zh":{"lang":"zh","tldr":"一个 supportsInterface(bytes4) 函数，让任何合约都能声明自己实现了哪些接口，这样其他合约和应用在调用之前就能先检查。","tags":["interface","introspection","standard","erc"],"related":[721,1155,20,214,1820],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-165/","markdown":"## 它解决什么问题？\n\n仅凭一个合约地址，你无法知道该合约能做什么。如果某个市场收到一个地址，它无法判断这个地址是 NFT 合约、多代币合约，还是别的东西。它可以调用某个函数然后碰运气，但缺失的函数可能会 revert，或者落入执行意外操作的 fallback。\n\nERC-165 为合约提供了一种标准方式来声明\"我实现了接口 X\"，也为调用方提供了一种安全的查询方式。\n\n## 它如何运作\n\n**接口 ID。** 接口由其所有函数的 4 字节函数选择器的异或（XOR）来标识。例如，ERC-165 自身的 ID 就是 `supportsInterface(bytes4)` 的选择器，即 `0x01ffc9a7`。\n\n**声明。** 符合标准的合约需要实现：\n\n```solidity\nfunction supportsInterface(bytes4 interfaceID) external view returns (bool);\n```\n\n它必须返回：\n\n- 对 `0x01ffc9a7`（ERC-165 自身）返回 `true`\n- 对 `0xffffffff` 返回 `false`\n- 对它实现的其他每个接口返回 `true`，其余返回 `false`\n\n该函数最多只能使用 30,000 gas。\n\n**检测。** 要检查一个合约是否支持 ERC-165，使用 30,000 gas 发起 `STATICCALL`（[EIP-214](/eip-214/)）。先查询 `supportsInterface(0x01ffc9a7)`，它必须返回 true。再查询 `supportsInterface(0xffffffff)`，它必须返回 false。第二项检查用于识别那些 fallback 对任何调用都返回 true 的旧合约。如果两项检查都通过，就可以直接查询任意接口 ID。\n\n## 示例代码\n\n在自定义接口之外同时实现 ERC-165：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC165 {\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n\ninterface IGreeter {\n    function greet() external view returns (string memory);\n}\n\ncontract Greeter is IERC165, IGreeter {\n    function supportsInterface(bytes4 id) external pure returns (bool) {\n        return id == type(IERC165).interfaceId   // 0x01ffc9a7\n            || id == type(IGreeter).interfaceId;\n    }\n\n    function greet() external pure returns (string memory) {\n        return \"hello\";\n    }\n}\n```\n\n检查某个地址是否为 ERC-721 合约（ethers v6）：\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst c = new Contract(addr, [\"function supportsInterface(bytes4) view returns (bool)\"], provider);\n\nconst isErc165 =\n  (await c.supportsInterface(\"0x01ffc9a7\")) \u0026\u0026 !(await c.supportsInterface(\"0xffffffff\"));\nconst isErc721 = isErc165 \u0026\u0026 (await c.supportsInterface(\"0x80ac58cd\"));\n```\n\n## 需要注意\n\n- [ERC-721](/eip-721/) 和 [ERC-1155](/eip-1155/) 要求实现 ERC-165，因此 NFT 市场可以自动识别代币类型。[ERC-20](/eip-20/) 出现得更早，并不要求实现它。\n- 接口 ID 只涵盖函数选择器。事件、返回类型和可选函数都不包含在内。\n- 返回 `true` 的合约只是在做声明。ERC-165 并不能证明这些函数的行为是正确的。\n- 在 Solidity 中，`type(I).interfaceId` 会替你计算该 ID。OpenZeppelin 的 `ERC165` 基础合约是常见的起点。\n- [ERC-1820](/eip-1820/) 是基于注册表的替代方案，普通账户（EOA）也可以注册接口。\n"}},"requiredBy":[634,721,725,820,926,998,1155,1261,1337,1363,1417,1450,1616,1633,1761,1820,1844,1922,1923,2135,2390,2477,2615,2767,2981,3386,3525,4353,4393,4400,4494,4519,4524,4671,4675,4799,4885,4906,4907,4910,4973,4974,4987,5005,5006,5007,5008,5023,5050,5058,5169,5173,5187,5192,5216,5289,5313,5334,5380,5409,5437,5453,5484,5489,5501,5507,5516,5521,5560,5604,5633,5635,5646,5679,5700,5727,5732,5750,5753,5773,5827,5982,6059,6066,6105,6120,6147,6150,6220,6239,6268,6315,6381,6454,6464,6551,6604,6672,6785,6786,6900,6909,6956,6982,7007,7066,7092,7160,7204,7208,7231,7291,7303,7401,7409,7410,7417,7432,7439,7444,7496,7498,7508,7513,7518,7527,7531,7540,7546,7548,7564,7574,7575,7578,7579,7585,7586,7589,7590,7603,7604,7621,7629,7632,7634,7651,7652,7656,7695,7699,7721,7765,7802,7829,7831,7858,7861,7866,7878,7887,7893,7897,7943,7984,7992,7996,8034,8047,8048,8049,8056,8063,8065,8107,8143,8161,8199,8226,8257,8262,8273,8320,8325,8326,8327,8328,8329,8330,8348,8349,8354,8376,8377,8436,8444]}
