ERC-1577 · Stagnant · ERC · 2018-11-13
ERC-1577: contenthash field for ENS
Adds a contenthash record to ENS resolvers so a name can point to content on IPFS, Swarm and other networks using a self-describing multicodec format.
What problem does it solve?
Wallets and browsers began resolving ENS names to websites hosted on decentralised storage such as IPFS and Swarm. The older resolver fields (content and multihash) did not clearly say which network a hash belonged to, so apps had to guess, and name owners could not be sure how their content would be loaded.
ERC-1577 replaces them with one field, contenthash, whose value carries its own protocol identifier.
How it works
- A resolver supporting the field returns
truefrom ERC-165supportsInterface(0xbc1c58d1). contenthash(node)returns raw bytes in multicodec form:
<protoCode uvarint><value []byte>
- For IPFS (
0xe3) and Swarm (0xe4), the value is a CIDv1 without a base prefix:
<protoCode uvarint><cid-version><multicodec-content-type><multihash-content-address>
- Clients MUST read the protocol code first and resolve the address with the matching network, if they support it.
- The old
contentandmultihashfields are deprecated. The spec required a grace period, until at least 31 March 2019, during which clients fell back to them.
Breaking down the spec's IPFS example:
| Bytes | Meaning |
|---|---|
e3 01 |
IPFS namespace (0xe3 as a uvarint) |
01 |
CID version 1 |
70 |
content type dag-pb |
12 20 |
sha2-256, 32-byte digest |
29f2…3f1f |
the hash |
Sample code
The spec's examples:
IPFS binary: 0xe3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f
text: ipfs://QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4
Swarm binary: 0xe40101fa011b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
text: bzz://d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
Reading a name's content hash with ethers v6, which decodes common protocols to a URL:
import { JsonRpcProvider, Contract, namehash } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const resolver = await provider.getResolver("vitalik.eth");
console.log(await resolver?.getContentHash()); // e.g. "ipfs://..."
// Or call the resolver directly for the raw bytes
const r = new Contract(resolver!.address,
["function contenthash(bytes32 node) view returns (bytes)"], provider);
console.log(await r.contenthash(namehash("vitalik.eth")));
Inside a resolver contract:
function contenthash(bytes32 node) external view returns (bytes memory);
event ContenthashChanged(bytes32 indexed node, bytes hash);
Things to know
- Status: Stagnant in the EIP repository, but
contenthashis the record that ENS resolvers and ENS-aware gateways and browsers use for decentralised websites. - Only the encoding is standardised; whether a client can actually fetch the content depends on its support for that protocol.
- Use a library (for example the
content-hashpackages the spec links) to encode values instead of assembling bytes by hand. - Name resolution itself is defined by ENS (EIP-137); text records are in EIP-634.