ERC-205 · Stagnant · ERC · 2017-02-06
ERC-205: ENS support for contract ABIs
Lets an ENS name publish its contract's ABI, so a caller can look up both the address and the interface of a contract from one name.
What problem does it solve?
To call a contract you need its address and its ABI, the JSON description of its functions and events. ENS solved the address part: mytoken.eth resolves to an address. The ABI, though, still had to come from somewhere else, such as a website, a GitHub repo or a block explorer. That is awkward for one-off interactions and for contracts whose interface changes over time.
ABIs are small. The spec notes that even The DAO's large ABI was about 9.4 KB of raw JSON and about 1.1 KB compressed. So ERC-205 proposes storing them right in ENS, next to the address.
How it works
ERC-205 defines a new resolver profile:
function ABI(bytes32 node, uint256 contentTypes) view returns (uint256, bytes);
Its ERC-165 interface ID is 0x2203ab56.
contentTypes is a bitmask of the encodings the caller can handle. The resolver returns one of them, or (0, "") if it has nothing suitable.
| ID | Encoding | Notes |
|---|---|---|
| 1 | JSON | Standard, but the largest |
| 2 | zlib-compressed JSON | Small, easy to decode off-chain |
| 4 | CBOR | Compact and easier to parse in the EVM |
| 8 | URI | Points elsewhere (HTTP, IPFS, Swarm…) |
Lookup order: first ask the resolver for the name itself, such as mytoken.eth. If that returns nothing, do a reverse lookup (ERC-181) on the address the name points to, and ask that record. A contract can publish its own canonical ABI on its reverse record, and individual names can override it, for example with a trimmed ABI.
Sample code
Fetching a JSON ABI via ENS with ethers v6:
import { Contract, JsonRpcProvider, namehash, toUtf8String } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const name = "example.eth";
const resolverInfo = await provider.getResolver(name);
if (!resolverInfo) throw new Error("no resolver");
const resolver = new Contract(
resolverInfo.address,
["function ABI(bytes32 node, uint256 contentTypes) view returns (uint256, bytes)"],
provider,
);
const [type, data] = await resolver.ABI(namehash(name), 1); // accept JSON only
if (type === 1n) {
const abi = JSON.parse(toUtf8String(data));
const target = new Contract((await provider.resolveName(name))!, abi, provider);
}
Things to know
- This ERC is Stagnant. It never reached Final, but the
ABIrecord does appear in ENS resolver implementations. - In practice, most developers still get ABIs from verified source on block explorers or from package artifacts, not from ENS.
- Uncompressed JSON is expensive to write on-chain. Prefer compressed, CBOR or URI forms for large ABIs.
- Other ENS record types follow the same resolver-profile pattern, for example text records in ERC-634. Off-chain resolution is possible with ERC-3668 (CCIP Read).