---
eip: 2544
label: ERC-2544
title: ENS Wildcard Resolution
status: Stagnant
type: Standards Track
category: ERC
created: 2020-02-28
requires: 137
official: https://eips.ethereum.org/EIPS/eip-2544
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2544.md
canonical: https://eips.huatuo.xyz/zh/eip-2544/
lang: zh
tldr: 当子域名没有解析器时，让 ENS 客户端向上查找父域名的解析器，这样项目无需逐个注册，就能提供数量不限的 `alice.wallet.eth` 这类子域名。
tags: [ens, naming, wildcard, resolver, subdomains]
---

# ERC-2544: ENS Wildcard Resolution

> Adds support for "wildcard" resolution of subdomains in ENS.

**TL;DR:** 当子域名没有解析器时，让 ENS 客户端向上查找父域名的解析器，这样项目无需逐个注册，就能提供数量不限的 `alice.wallet.eth` 这类子域名。

## 它解决什么问题？

在 [EIP-137](/eip-137/) 下，解析一个 ENS 名称分为两步：把名称哈希成 `node`，向 ENS 注册表查询该 node 的解析器，再向解析器查询记录。如果该 node 本身没有设置解析器，解析就直接失败。

钱包、交易所和 dapp 希望给每个用户一个类似 `user123.app.eth` 的名称。这意味着每个用户都要发一笔注册表交易，规模一大成本就很高，而且在该交易被打包之前名称无法使用。

ERC-2544 增加了**通配符解析**：设置在父域名上的一个解析器可以回答其下任意子域名的查询，而无需改动注册表或现有解析器。

## 它如何运作

**查找解析器。** 客户端先查找完整名称的解析器。如果是零地址，就去掉最左边的标签再试一次（`a.b.eth` → `b.eth` → `eth` → 根），直到找到解析器或标签用完为止。

**调用解析器。** 记录始终是针对*原始*名称请求的，而不是找到解析器的那个父域名。解析器还可以实现一个新函数：

```solidity
function resolve(bytes calldata name, bytes calldata data) external view returns (bytes memory);
```

- `name` 是 DNS 线格式（带长度前缀的标签）的完整名称，因此解析器能看到明文标签，而不只是一个哈希。
- `data` 是客户端原本会发起的调用的 ABI 编码，例如 `addr(namehash(name))`。
- 解析器返回该函数 ABI 编码后的结果，如果不支持则 revert。

如果解析器通过 [ERC-165](/eip-165/) 声明支持 `resolve`，客户端就调用它；否则直接调用常规函数（`addr`、`text` 等）。能看到明文标签，使得一些设计成为可能，例如把 `42.nifty.eth` 解析为 NFT #42 的所有者，或解析为由标签推导出的 `CREATE2` 地址。

直接设置在子域名上的解析器仍然优先于父域名的通配符。

## 示例代码

客户端侧的解析器查找，对应规范中的伪代码（ethers v6）：

```ts
import { Contract, ZeroAddress, namehash, dnsEncode } from "ethers";

const parent = (name: string) => name.split(".").slice(1).join(".");

async function findResolver(registry: Contract, name: string) {
  for (let current = name; current !== ""; current = parent(current)) {
    const r: string = await registry.resolver(namehash(current));
    if (r !== ZeroAddress) return r;
  }
  return null; // resolution fails
}

// With an extended resolver: send the original name, DNS-encoded
// const data = iface.encodeFunctionData("addr(bytes32)", [namehash(name)]);
// const out  = await resolver.resolve(dnsEncode(name), data);
```

较新版本的 ethers 和 viem 已经在它们的 ENS 辅助函数中实现了这种向上查找的逻辑。

## 需要注意

- 在 EIP 仓库中状态为 **Stagnant**，规范中 `resolve` 的接口 ID 仍为 `0xTBD`。此后 ENS 在自己的 ENSIP 流程中采纳了这一设计，各库实现的就是那一版；最终的接口 ID 请查阅 ENS 文档。
- 只支持 EIP-137 的旧客户端找不到通配符记录；它们会解析失败，而不会解析出错误结果。
- 兜底型解析器会让拼写错误变得危险：`alcie.app.eth` 可能解析为一个看上去有效的地址。请考虑验证名称，或让资金可以追回。
- `resolve` 与 [ERC-3668](/eip-3668/)（CCIP-Read）天然搭配，后者让解析器可以从链下来源获取记录。


---

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