---
eip: 7996
label: ERC-7996
title: Contract Feature Detection
status: Draft
type: Standards Track
category: ERC
created: 2025-07-07
requires: 165
official: https://eips.ethereum.org/EIPS/eip-7996
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7996.md
canonical: https://eips.huatuo.xyz/zh/eip-7996/
lang: zh
tldr: 新增 supportsFeature(bytes4)，作为 ERC-165 的补充，让合约可以公布那些没有自身接口的能力，能力用反向域名字符串命名。
tags: [interface-detection, erc-165, ens, introspection]
---

# ERC-7996: Contract Feature Detection

> Method to publish and detect contract features that lack an ERC-165 interface

**TL;DR:** 新增 supportsFeature(bytes4)，作为 ERC-165 的补充，让合约可以公布那些没有自身接口的能力，能力用反向域名字符串命名。

## 它解决什么问题？

[ERC-165](/eip-165/) 允许调用者询问“你是否实现了接口 X？”，其中 X 是函数选择器的异或值。当某项能力意味着新增函数时，这很有效。但许多能力根本不改变 ABI：例如“这个解析器以某种特定方式支持 multicall”“这个合约处理某种边界情况”。为了表示这些能力，目前各项目会自造虚假的“合成”接口 ID，污染了 ERC-165 的命名空间。

高度依赖 ERC-165 来保持向后兼容的 ENS 正好遇到了这个问题。ERC-7996 为这类能力提供了专门的检测方法。

## 它如何运作

- **特性（feature）** 指合约中无法通过 ERC-165 表达的任何属性。
- 特性用反向域名命名，例如 `eth.ens.resolver.extended.multicall`。
- **特性 ID** 为 `bytes4(keccak256(name))`；对于这个例子，规范给出的值是 `0x96b62db8`。
- 公布特性的合约需实现：

```solidity
interface IERC7996 {
    function supportsFeature(bytes4 featureId) external view returns (bool);
}
```

其 ERC-165 接口 ID 为 `0x582de3e7`。

检测分两步：先按常规 ERC-165 流程检查 `supportsInterface(0x582de3e7)`，再调用 `supportsFeature(featureId)`。支持该接口的合约仍可能支持零个特性。

## 示例代码

公布一个特性：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract MyResolver {
    bytes4 constant MULTICALL_FEATURE = bytes4(keccak256("eth.ens.resolver.extended.multicall"));

    function supportsInterface(bytes4 id) external pure returns (bool) {
        return id == 0x01ffc9a7 /* ERC-165 */ || id == 0x582de3e7 /* ERC-7996 */;
    }

    function supportsFeature(bytes4 featureId) external pure returns (bool) {
        return featureId == MULTICALL_FEATURE;
    }
}
```

检测它（ethers v6）：

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

const abi = [
  "function supportsInterface(bytes4) view returns (bool)",
  "function supportsFeature(bytes4) view returns (bool)",
];
const c = new Contract(target, abi, provider);
const featureId = id("eth.ens.resolver.extended.multicall").slice(0, 10); // bytes4

const hasFeatures = await c.supportsInterface("0x582de3e7").catch(() => false);
const ok = hasFeatures && (await c.supportsFeature(featureId));
```

## 需要注意

- 状态为 **Draft**。
- 规范指出 ENS 已经实现了它。
- 与 ERC-165 一样，返回 `true` 只是一种声明，而非保证；合约可能说谎，也可能有 bug。
- 请使用你自己控制的名称（你自己的反向域名）以避免冲突；4 字节的 ID 理论上仍可能发生碰撞。
- 不了解特性的调用者不会看到任何行为变化。


---

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