ERC-2520 · Stagnant · ERC · 2020-02-18
ERC-2520: Multiple contenthash records for ENS
Extends the ENS contenthash record so one name can point to content on several hosting systems at once (IPFS, Swarm, Onion…), keyed by protocol.
What problem does it solve?
EIP-1577 gave ENS names a contenthash record, which tells a browser or gateway where a decentralised website lives (an IPFS CID, a Swarm hash, and so on). But a name can hold only one contenthash. A site owner who publishes to both IPFS and Swarm has to pick one, and a gateway that only speaks Swarm cannot use an IPFS record.
ERC-2520 lets a resolver store one contenthash per protocol, plus a default, so different applications can each fetch the record they understand.
How it works
The resolver keeps the original EIP-1577 functions and adds overloads with a proto argument:
setContenthash(node, proto, hash)stores a hash for that protocol. Calling the original two-argument version stores the default record.contenthash(node, proto)returns the hash for that protocol. The original one-argument version returns the default record.- A resolver that supports this returns
truefromsupportsInterface(0x6de03e07)(ERC-165).
Guidance for clients:
- An app that supports only one system (for example an IPFS gateway) should ask for the protocol-specific record.
- An app that supports several systems (the spec's example is MetaMask) should ask for the default record, exactly as with EIP-1577.
Multiple records per protocol and priority ordering are deliberately not supported, to keep the design simple.
Sample code
Interface and a minimal resolver, following the spec's reference implementation (no access control, for illustration only):
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
contract MultiContentHashResolver {
bytes4 constant MULTI_CONTENT_HASH_INTERFACE_ID = 0x6de03e07;
event ContenthashChanged(bytes32 indexed node, bytes hash);
mapping(bytes32 => mapping(bytes => bytes)) private hashes;
// In production, restrict to the name's owner (`authorised(node)`).
function setContenthash(bytes32 node, bytes calldata proto, bytes calldata hash) external {
hashes[node][proto] = hash;
emit ContenthashChanged(node, hash);
}
function contenthash(bytes32 node, bytes calldata proto) external view returns (bytes memory) {
return hashes[node][proto];
}
function supportsInterface(bytes4 id) external pure returns (bool) {
return id == MULTI_CONTENT_HASH_INTERFACE_ID;
}
}
Things to know
- Status: Stagnant, and it builds on EIP-1577, which is itself Stagnant. The standard ENS public resolver does not implement this extension, so most tools will only see the single default record.
- The spec does not define the exact encoding of the
protokey; implementers would need to agree on it out of band. - The security considerations section of the spec is left as "TBD". As with any resolver, writes must be restricted to the name's owner or approved operators.
- Being an overload, it is backwards compatible: older clients keep working and simply receive the default record.