ERC-1844 · Stagnant · ERC · 2019-03-15
ERC-1844: ENS Interface Discovery
Adds an ENS resolver record, interfaceImplementer, that tells apps which contract implements a given interface for a name or address, even if that contract is not the target itself.
What problem does it solve?
ERC-165 lets you ask a contract "do you support interface X?". But often the useful functionality lives somewhere else. A token contract might not offer atomic swaps itself, yet there may be a separate contract that does swaps for that token. ERC-165 cannot express "go over there for that".
Adding such a lookup table directly to each contract has drawbacks: it needs access control, it must be designed in from the start, and it cannot be added to contracts already deployed. EIP-1844 puts the table in the ENS resolver instead, so anyone who controls a name can point interfaces at implementer contracts, even for contracts that were never built with this in mind.
How it works
A new resolver profile with one function:
function interfaceImplementer(bytes32 node, bytes4 interfaceID)
external view returns (address);
nodeis the ENS namehash of the name;interfaceIDis an ERC-165 interface ID.- It returns the address of a contract implementing that interface for that name, or
0if none. - The returned address must be a contract and should implement ERC-165.
- The ERC-165 ID of this resolver profile itself is
0xb8f2bbb4.
Fallback: a resolver may check the contract returned by the name's addr() record. If that contract supports the requested interface via ERC-165, the resolver returns its address. It must return 0, not revert, if that check fails.
The record works for forward names (mytoken.eth) and for reverse records (EIP-181), so you can also attach interface information to an address.
Sample code
Looking up an implementer with ethers v6:
import { Contract, JsonRpcProvider, namehash } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
async function findImplementer(name: string, interfaceId: string) {
const resolver = await provider.getResolver(name);
if (!resolver) return null;
const r = new Contract(resolver.address, [
"function supportsInterface(bytes4) view returns (bool)",
"function interfaceImplementer(bytes32,bytes4) view returns (address)",
], provider);
if (!(await r.supportsInterface("0xb8f2bbb4"))) return null; // profile not supported
const impl: string = await r.interfaceImplementer(namehash(name), interfaceId);
return impl === "0x0000000000000000000000000000000000000000" ? null : impl;
}
Setting the record is not part of the standard and is resolver-specific (the ENS PublicResolver exposes a setInterface function for the name's owner).
Things to know
- Status: Stagnant. The spec states that the ENS PublicResolver implements this profile, but the EIP itself was never finalized.
- The result only tells you where an implementation lives, not that it is trustworthy. Whoever controls the ENS name controls the answer.
- ERC-1820 solves a similar "who implements this for address X" problem with a single global registry contract instead of ENS.