---
eip: 5269
label: ERC-5269
title: ERC Detection and Discovery
status: Review
type: Standards Track
category: ERC
created: 2022-07-15
requires: 5750
official: https://eips.ethereum.org/EIPS/eip-5269
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5269.md
canonical: https://eips.huatuo.xyz/zh/eip-5269/
lang: zh
tldr: 让合约可以通过 ERC 编号（而不是 ERC-165 的选择器哈希）回答“你是否对这个调用者支持 ERC-N（以及可选功能 X）”，并通过事件宣告支持情况。
tags: [interface-detection, introspection, standard, tooling]
---

# ERC-5269: ERC Detection and Discovery

> An interface to identify if major behavior or optional behavior specified in an ERC is supported for a given caller.

**TL;DR:** 让合约可以通过 ERC 编号（而不是 ERC-165 的选择器哈希）回答“你是否对这个调用者支持 ERC-N（以及可选功能 X）”，并通过事件宣告支持情况。

## 它解决什么问题？

[ERC-165](/eip-165/) 通过接口 ID（函数选择器的异或）检测支持情况。这种方法可行，但有一些缺陷：

- 有些标准**没有函数**可以做哈希，例如数据格式、签名方案，或只是让转账 revert 的灵魂绑定行为。
- 答案无法取决于**谁在询问**。在代理模式下（例如透明代理，见 [ERC-1967](/eip-1967/)），管理员和普通用户看到的行为可能不同。
- `0x80ac58cd` 不便于人读，而“721”可以。

ERC-5269 是一种以 ERC 编号为键的、与之竞争的检测方案。

## 它如何运作

一个 view 函数：

```solidity
function supportERC(
    address caller,
    uint256 majorERCIdentifier,   // the ERC number, e.g. 721
    bytes32 minorERCIdentifier,   // 0 = whole ERC; else e.g. keccak256("ERC721Metadata")
    bytes calldata extraData      // for ERC-5750 extensions
) external view returns (bytes32 ercStatus);
```

以及一个事件：

```solidity
event OnSupportERC(address indexed caller, uint256 indexed majorERCIdentifier,
    bytes32 indexed minorERCIdentifier, bytes32 ercStatus, bytes extraData);
```

规则：

- 对于 Final 的 ERC，`ercStatus` 为 `keccak256("FINAL")`。对于非 Final 的 ERC，它**不得**是 `FINAL`；使用 `keccak256("DRAFT")` 或作者自定义的值，例如 `keccak256("DRAFTv1")`。`0` 表示“不支持”。
- 合约必须对 5269 本身作出回答，在当前版本返回 `keccak256("DRAFTv1")`。
- 合约应在部署或升级时触发 `OnSupportERC(address(0), 5269, 0, ...)`，也可以触发更多事件，使索引器无需调用即可发现支持情况。`caller = address(0)` 表示所有调用者。
- `minorERCIdentifier` 让每个 ERC 的作者可以为可选功能或版本命名。

## 示例代码

查询支持情况（ethers v6）：

```ts
import { Contract, JsonRpcProvider, ZeroHash, id } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const c = new Contract(process.env.CONTRACT!, [
  "function supportERC(address caller, uint256 major, bytes32 minor, bytes extraData) view returns (bytes32)",
], provider);

const me = "0xYourAddress";
const status = await c.supportERC(me, 721n, id("ERC721Metadata"), "0x");

if (status === id("FINAL")) console.log("supports ERC721Metadata (Final)");
else if (status === ZeroHash) console.log("not supported");
else console.log("supported, non-final status:", status);
```

## 需要注意

- 状态为 **Review**；规范中的状态值 `DRAFTv1` 反映了这一点。
- `extraData` 参数需要 [ERC-5750](/eip-5750/)。
- 与 ERC-165 一样，声称支持的合约可能并未正确实现；请验证实际行为，而不是直接信任答案。
- ERC-165 仍是部署最广泛的机制；除非你自己集成，否则工具和钱包不太可能去查询 `supportERC`。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5269
