---
eip: 162
label: ERC-162
title: Initial ENS Hash Registrar
status: Final
type: Standards Track
category: ERC
created: 2016-10-25
official: https://eips.ethereum.org/EIPS/eip-162
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-162.md
canonical: https://eips.huatuo.xyz/zh/eip-162/
lang: zh
tldr: 描述了 ENS 的首个 .eth 名称注册商，通过密封出价的维克里拍卖分配名称，ETH 被锁定在每个名称各自的 deed 合约中。
tags: [ens, naming, registrar, auction]
---

# ERC-162: Initial ENS Hash Registrar

> This ERC describes the implementation, as deployed to the main ethereum network on 2017-05-04, of a registrar contract to govern the allocation of names in the Ethereum Name Service (ENS). The corresponding source code is here.

**TL;DR:** 描述了 ENS 的首个 .eth 名称注册商，通过密封出价的维克里拍卖分配名称，ETH 被锁定在每个名称各自的 deed 合约中。

## 它解决什么问题？

以太坊域名服务（[EIP-137](/eip-137/)）把 `alice.eth` 之类人类可读的名称映射到地址。ENS 本身只是一个注册表，必须有人决定每个名称归谁，而一个新的命名空间会引来圈地抢注：抢注者注册有价值的名称，只为转手倒卖。

EIP-162 记录了 **Initial Registrar**（初始注册商），它于 2017-05-04 部署到主网，用来分发 `.eth` 名称。它被设计得简单而临时：用大约两年时间从真实使用中积累经验，然后由永久注册商取而代之。

## 它如何运作

**限制。** 只服务 `.eth` 顶级域名，且只开放 7 个字符及以上的名称。更短的名称留待以后。

**哈希后的名称。** 出价针对的是 `sha3(label)`，例如 `abcdefg.eth` 对应 `sha3('abcdefg')`，而不是完整的 ENS namehash。由于注册商只看得到哈希，它自己无法检查长度。任何人都可以用过短名称的明文调用 `invalidateName` 并赢得奖励。

**逐步放开。** 名称在 8 周内陆续开放。何时开放由名称哈希的第一个字节决定。

**维克里拍卖。** 每个名称依次经历以下状态：

1. *Open*：任何人调用 `startAuction`。
2. *Auction*（72 小时）：竞拍者发送密封出价 `shaBid(hash, owner, value, salt)` 和 ETH。他们可以发送多于出价的 ETH 来隐藏真实金额。
3. *Reveal*（48 小时）：竞拍者用真实参数调用 `unsealBid`。
4. *Owned*：赢家调用 `finalizeAuction`，支付**第二高**的出价。最低价格为 0.01 ETH。

**Deed。** ETH 并不会付给任何人，而是为每次出价锁定在单独的 `Deed` 合约中。赢家的 deed 在其拥有该名称期间一直作为抵押被锁定。一年之后，所有者可以释放名称并取回 deed。落选的出价按 99.5 % 退款，其余部分被销毁。揭示得太晚或从未揭示的出价大部分会被销毁。

## 示例代码

用 ethers v6 计算注册商所期望的值：

```ts
import { keccak256, toUtf8Bytes, solidityPackedKeccak256, randomBytes, hexlify, parseEther } from "ethers";

const labelHash = keccak256(toUtf8Bytes("abcdefg"));   // the name being auctioned
const salt = hexlify(randomBytes(32));
const value = parseEther("0.5");                       // true bid

// sealed bid = sha3(hash, owner, value, salt), as returned by shaBid()
const sealedBid = solidityPackedKeccak256(
  ["bytes32", "address", "uint256", "bytes32"],
  [labelHash, myAddress, value, salt],
);
// newBid(sealedBid) with msg.value >= value, then unsealBid(...) in the reveal window
```

## 需要注意

- 这个注册商已成为历史。规范计划在大约两年后替换它，并在四年后停止新的拍卖。此后 ENS 已把 `.eth` 迁移到后来的注册商设计，改为收取续费，而不是锁定押金。
- 及时揭示很重要。在揭示窗口之后才揭示的出价大部分会被销毁，因此无法用来抬高赢家的价格。
- 名称注册后如何解析，请见 [EIP-137](/eip-137/)。从地址到名称的反向查询，请见 [EIP-181](/eip-181/)。


---

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