ENS Logo

Universal Resolver

Overview

The Universal Resolver is a contract that handles the work of resolving a name entirely onchain, making it possible to make a single smart contract call to resolve an ENS name.

Note that this contract is already built into libraries like viem and ENSjs, so most developers don't typically need to use it directly.

Forward Resolution

To resolve one or more records for a name, use one of the resolve methods, such as resolve(bytes name, bytes data).

The name argument for these methods will be the DNS-encoded version of the name. Make sure to normalize the name first, as well! For example, given the name My.Name.eth:

  1. Normalize:
    • My.Name.eth -> my.name.eth
  2. DNS Encode:
    • my.name.eth -> 0x026d79046e616d650365746800

The data argument for these methods will be an ABI-encoded call to the resolver for that name.

For example, if you want to resolve the ETH address for my.name.eth, using the addr(bytes32 node) method, then the corresponding ABI-encoded call would be:

0x3b3b57def61adbd8ee36cf930560efc644af752731733dc6421afe47608f8e2cfeaabe2b

See here for standard resolver methods: Resolver Interface Standards

Reverse Resolution

To reverse-resolve an address to an ENS name, call one of the reverse methods, such as reverse(bytes reverseName).

The reverseName argument for these methods will be the DNS-encoded version of the reverse name. The "reverse name" is [addr].addr.reverse, where [addr] is the Ethereum public address (without the "0x"). Make sure to normalize the name as well! For example, given the address 0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63:

  1. Construct Reverse Name:
    • 0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63 -> 231b0Ee14048e9dCcD1d247744d114a4EB5E8E63.addr.reverse
  2. Normalize:
    • 231b0Ee14048e9dCcD1d247744d114a4EB5E8E63.addr.reverse -> 231b0ee14048e9dccd1d247744d114a4eb5e8e63.addr.reverse
  3. DNS Encode:
    • 231b0ee14048e9dccd1d247744d114a4eb5e8e63.addr.reverse -> 0x28323331623065653134303438653964636364316432343737343464313134613465623565386536330461646472077265766572736500

Interface Standards

UsageFunction Definition
Check Interface SupportsupportsInterface(bytes4 interfaceID) external pure returns (bool)
Resolve Nameresolve(bytes calldata name, bytes memory data) external view returns (bytes memory, address)
Resolve Name (with custom gateways)resolve(bytes calldata name, bytes memory data, string[] memory gateways) external view returns (bytes memory, address)
Resolve Name (multiple records)resolve(bytes calldata name, bytes[] memory data) external view returns (Result[] memory, address)
Resolve Name (multiple records with custom gateways)resolve(bytes calldata name, bytes[] memory data, string[] memory gateways) public view returns (Result[] memory, address)
Resolve Reverse Namereverse(bytes calldata reverseName) external view returns (string memory, address, address, address)
Resolve Reverse Name (with custom gateways)reverse(bytes calldata reverseName, string[] memory gateways) public view returns (string memory, address, address, address)
Find ResolverfindResolver(bytes calldata name) public view returns (Resolver, bytes32, uint256)

Check Interface Support

Function
supportsInterface(bytes4 interfaceID) external pure returns (bool)
EIP-165
  • Interface ID: 0x01ffc9a7

Parameters

  • interfaceID (bytes4): The interface identifier, as specified in ERC-165

Returns

  • bool: True if the contract supports the specified interface.

Resolve Name

Function
resolve(bytes calldata name, bytes memory data) external view returns (bytes memory, address)
ENSIP-10
  • Interface ID: 0x9061b923

Parameters

  • name (bytes): The name to resolve, in normalised and DNS-encoded form.
  • data (bytes): The resolution data, as specified in ENSIP-10.

Returns

  • bytes: The return data of the resolver call.
  • address: The address of the resolver contract.

Resolve Name (with custom gateways)

Function
resolve(bytes calldata name, bytes memory data, string[] memory gateways) external view returns (bytes memory, address)
ENSIP-10
  • Interface ID: 0x0667cfea

Parameters

  • name (bytes): The name to resolve, in normalised and DNS-encoded form.
  • data (bytes): The resolution data, as specified in ENSIP-10.
  • gateways (string[]): An array of custom CCIP Read gateway URLs.

Returns

  • bytes: The return data of the resolver call.
  • address: The address of the resolver contract.

Resolve Name (multiple records)

Function
resolve(bytes calldata name, bytes[] memory data) external view returns (Result[] memory, address)
ENSIP-10
  • Interface ID: 0x206c74c9

Parameters

  • name (bytes): The name to resolve, in normalised and DNS-encoded form.
  • data (bytes[]): The resolution data, as specified in ENSIP-10.

Returns

  • Result[]: The return data of the resolver call. This is a struct with: [bool success, bytes returnData]
  • address: The address of the resolver contract.

Resolve Name (multiple records with custom gateways)

Function
resolve(bytes calldata name, bytes[] memory data, string[] memory gateways) public view returns (Result[] memory, address)
ENSIP-10
  • Interface ID: 0x76286c00

Parameters

  • name (bytes): The name to resolve, in normalised and DNS-encoded form.
  • data (bytes[]): The resolution data, as specified in ENSIP-10.
  • gateways (string[]): An array of custom CCIP Read gateway URLs.

Returns

  • Result[]: The return data of the resolver call. This is a struct with: [bool success, bytes returnData]
  • address: The address of the resolver contract.

Resolve Reverse Name

Function
reverse(bytes calldata reverseName) external view returns (string memory, address, address, address)
  • Interface ID: 0xec11c823

Parameters

  • reverseName (bytes): The reverse name to resolve, in normalised and DNS-encoded form.

Returns

  • string: The resolved name.
  • address: The resolved address.
  • address: The reverse resolver address.
  • address: The resolver address.

Resolve Reverse Name (with custom gateways)

Function
reverse(bytes calldata reverseName, string[] memory gateways) public view returns (string memory, address, address, address)
  • Interface ID: 0xb241d0d3

Parameters

  • reverseName (bytes): The reverse name to resolve, in normalised and DNS-encoded form.
  • gateways (string[]): An array of custom CCIP Read gateway URLs.

Returns

  • string: The resolved name.
  • address: The resolved address.
  • address: The reverse resolver address.
  • address: The resolver address.

Find Resolver

Function
findResolver(bytes calldata name) public view returns (Resolver, bytes32, uint256)
Finds a resolver by recursively querying the registry, starting at the longest name and progressively removing labels until it finds a result.
  • Interface ID: 0xa1cbcbaf

Parameters

  • name (bytes): The name to resolve, in DNS-encoded and normalised form.

Returns

  • address: The Resolver responsible for this name.
  • bytes32: The namehash of the full name.
  • uint256: The offset of the first label with a resolver.
Contributors
Last Modified
2 days ago