Skip to content
Lattice

ENSResolverLib

Git Source

Title: ENSResolverLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ENS (https://github.com/ensdomains/ens-contracts)

Library for on-chain ENS forward resolution: looks up an ENS node's resolver in the configured registry and reads its addr record.

Three-layer pattern: this library holds the logic and namespaced storage; the stateless ENSResolver facet forwards to it. Basic resolution only (registry -> resolver -> addr); ENSIP-10 wildcard / extended resolution is out of scope for v1.

Functions

ensResolverStorage

function ensResolverStorage() internal pure returns (ENSResolverStorage storage $);

Returns

NameTypeDescription
$ENSResolverStorage

__ENSResolver_init

Initializes the ENSResolver module with the ENS registry to use.

Must be called inside a pre/postInitializer block. Reverts ENSResolverZeroRegistry for a zero registry. Registers IENSResolver for ERC-165 discovery.

function __ENSResolver_init(address _ensRegistry) internal;

Parameters

NameTypeDescription
_ensRegistryaddressThe ENS registry for this chain.

registerInterface

Registers support for the IENSResolver interface via ERC-165.

function registerInterface() internal;

resolve

Resolves an ENS node to its address.

Returns zero ONLY when node has no resolver configured. MAY revert (bubbling the resolver's revert) if a configured resolver does not implement addr(bytes32) or itself reverts. The resolved address is set by the node's owner (a third party) — treat it as untrusted; use resolverOf to distinguish "no resolver" from "resolves to zero".

function resolve(bytes32 node) internal view returns (address);

Parameters

NameTypeDescription
nodebytes32The ENS node (namehash) to resolve.

Returns

NameTypeDescription
<none>addressThe resolved address (zero if no resolver is set).

resolverOf

Returns the resolver configured for node in the ENS registry.

function resolverOf(bytes32 node) internal view returns (address);

Parameters

NameTypeDescription
nodebytes32The ENS node (namehash) to query.

Returns

NameTypeDescription
<none>addressThe resolver address (zero if unset).

subnode

Computes the namehash of label.<parent> (one ENS namehash recursion step).

function subnode(bytes32 parentNode, string calldata label) internal pure returns (bytes32);

Parameters

NameTypeDescription
parentNodebytes32The parent name's node.
labelstringThe subname label.

Returns

NameTypeDescription
<none>bytes32The child node (namehash).

setEnsRegistry

Sets or rotates the ENS registry.

Gated on ENS_MANAGER_ROLE. Reverts ENSResolverZeroRegistry for a zero address.

function setEnsRegistry(address _ensRegistry) internal;

Parameters

NameTypeDescription
_ensRegistryaddressThe ENS registry to use.

ensRegistry

Returns the configured ENS registry.

function ensRegistry() internal view returns (address);

Returns

NameTypeDescription
<none>address