ERC-137 · Final · ERC · 2016-04-04
ERC-137: Ethereum Domain Name Service - Specification
The Ethereum Name Service spec: a registry plus pluggable resolvers that turn names like foo.eth into addresses and other records, using the namehash algorithm.
What problem does it solve?
Addresses such as 0x8e23…d052 are impossible to remember and easy to mistype. Early Ethereum name registries had one global namespace, one central resolver, a single record type and no subdomains.
ERC-137 defines the Ethereum Name Service (ENS): a hierarchical, DNS-like system where the owner of mysite.eth can create forum.mysite.eth, point the name at a wallet, a contract or other resources, and change those targets later without changing the name.
How it works
ENS has three parts:
- Registry. One contract mapping each name to an owner, a resolver and a TTL. The owner of a name can set its resolver and create subnames with different owners.
- Resolvers. Contracts that answer lookups. A resolver advertises which record types it supports via ERC-165
supportsInterface. The base type isaddr(node)(interface0x3b3b57de); others, such asnamefrom ERC-181, are defined in later proposals. - Registrars. Whoever owns a name node and hands out its subnames. How names are allocated is left to each registrar.
Names are never stored as strings on chain. They are normalized (UTS-46, case-folded) and hashed with namehash, which produces a 32-byte "node":
def namehash(name):
if name == '':
return b'\0' * 32
label, _, rest = name.partition('.')
return keccak256(namehash(rest) + keccak256(label))
So namehash("eth") is 0x93cdeb70…c4ae. Because the node depends only on the name, a contract can hard-code it.
Resolving is two steps: ask the registry for the resolver of node, then ask the resolver for the record.
Sample code
Resolving a name and doing a reverse lookup with ethers v6:
import { JsonRpcProvider, namehash } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const node = namehash("vitalik.eth"); // 32-byte node
const resolver = await provider.getResolver("vitalik.eth");
const addr = await resolver?.getAddress(); // calls addr(node)
console.log(node, addr);
// Reverse direction (ERC-181)
const name = await provider.lookupAddress(addr!);
A minimal resolver in Solidity:
contract SimpleResolver {
mapping(bytes32 => address) public addr; // addr(bytes32)
function supportsInterface(bytes4 id) external pure returns (bool) {
return id == 0x3b3b57de || id == 0x01ffc9a7;
}
}
Things to know
- If
addrreturns the zero address, clients must treat the name as unresolved and refuse to send funds. Skipping this check can burn funds. - Names should be normalized before hashing. Different Unicode forms of the "same" name produce different nodes, and look-alike names are a phishing risk.
- The spec recommends labels of 64 characters or less and full names of 255 or less for DNS compatibility.
- ERC-137 deliberately does not define how names are registered or priced. The
.ethregistrar and its auction or rental rules are separate contracts built on top. - Later proposals extend resolvers, for example ERC-3668 (CCIP Read) lets a resolver fetch records from off-chain sources.