ENS Logo

Writing a Resolver

Every ENS name has a resolver, which is responsible for resolving information about a name.

Resolvers are a core part of the ENS protocol. They give each name, represented as a "node", the power to control the resolution process for itself and all of its subnames. Resolvers were originally standardized in EIP 137, but have since received a few updates such as EIP 181, EIP 2304, and ENSIP-10.

You can find the latest default resolver implementation, called the Public Resolver, on GitHub and Etherscan.

Resolver Interface

You can view an extended list of resolver methods here, however a simple interface might look something like this:

interface IMyResolver {
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
    function addr(bytes32 node) external view returns (address payable);
    function addr(bytes32 node, uint256 coinType) external view returns (bytes memory);
    function contenthash(bytes32 node) external view returns (bytes memory);
    function text(bytes32 node, string calldata key) external view returns (string memory);
    
    function setAddr(bytes32 node, address addr) external;
    function setAddr(bytes32 node, uint256 coinType, bytes calldata a) external;
    function setContenthash(bytes32 node, bytes calldata hash) external;
    function setText(bytes32 node, string calldata key, string calldata value) external;
}

Wildcard Resolution

In ENSIP-10 a new resolve() method was added to the resolver interface to allow for wildcard resolution.

interface IExtendedResolver {    
    /**
     * @dev Performs ENS name resolution for the supplied name and resolution data.
     * @param name The name to resolve, in normalised and DNS-encoded form.
     * @param data The resolution data, as specified in ENSIP-10.
     * @return The result of resolving the name.
     */
    function resolve(
        bytes memory name,
        bytes memory data
    ) external view returns (bytes memory);
}

Offchain Resolution

When you write your own resolver, you are able to leverage CCIP Read to effectively defer name resolution to an HTTP server. This server can then load data from any source including offchain databases, APIs, or other blockchains. Learn more about implementing CCIP Read in your resolver here.

Last Modified
27 days ago