ERC-634 · Stagnant · ERC · 2017-05-17
ERC-634: Storage of text records in ENS
An ENS resolver profile, text(node, key), that lets a name store arbitrary key/value text such as an avatar, website, email or Twitter handle, turning ENS names into simple public profiles.
What problem does it solve?
ENS maps human-readable names such as alice.eth to machine data like addresses and content hashes. People also wanted to attach human-readable information to a name: a website, an email address, an avatar, social handles. Adding a separate resolver function for each kind of data would never keep up with new needs.
EIP-634 borrows the idea of DNS TXT records. It adds one general function that returns a text value for any key, so new kinds of data need only a new key and never a new contract interface.
How it works
A resolver that supports this profile implements:
function text(bytes32 node, string calldata key) external view returns (string memory);
nodeis the ENS namehash of the name.- The value is any UTF-8 string. If the key is not set, the resolver must return
"". - Its EIP-165 interface ID is
0x59d1d43c, so clients can check support first.
Keys come in three groups:
- Global keys use lowercase letters, digits and hyphens:
avatar,description,display,email,keywords,mail,notice,location,phone(E.164 format) andurl. Ifdisplayis set, it must match the name when case is ignored, for exampleRicMoo.ethforricmoo.eth. Otherwise clients should ignore it. - Service keys use reverse-DNS notation for a namespace the service owns and contain at least one dot:
com.github,com.twitter,com.linkedin,io.keybase,org.telegram. A service can also define a hierarchy such ascom.example.users. - Legacy keys (
vnd.github,vnd.twitter,vnd.peepeth) come from earlier drafts. Clients may query them as a fallback.
Sample code
Reading text records with ethers v6:
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const resolver = await provider.getResolver("vitalik.eth");
if (resolver) {
const url = await resolver.getText("url");
const twitter = await resolver.getText("com.twitter");
console.log({ url, twitter }); // empty or null when the key is unset
}
A minimal resolver storing records per name (no access control, for illustration only):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract TextResolver {
event TextChanged(bytes32 indexed node, string indexed indexedKey, string key);
mapping(bytes32 => mapping(string => string)) private texts;
function setText(bytes32 node, string calldata key, string calldata value) external {
texts[node][key] = value; // real resolvers check the caller owns `node`
emit TextChanged(node, key, key);
}
function text(bytes32 node, string calldata key) external view returns (string memory) {
return texts[node][key];
}
function supportsInterface(bytes4 id) external pure returns (bool) {
return id == 0x59d1d43c || id == 0x01ffc9a7;
}
}
Things to know
- This EIP's status is Stagnant. The text-record interface is nevertheless implemented by ENS resolvers and read by wallets and apps. ENS now maintains it as ENSIP-5.
- Text records are public on-chain data. Do not store anything you would not publish, such as a private email or phone number.
- Values are not verified. A
com.twitterrecord proves only what the name owner claims, not that they control that account. - The
avatarvalue is usually a URL, but clients differ in which formats they resolve, so test with your target wallets.