Skip to main content
The ENSRegistry contract is the implementation of the ENS interface and serves as the central contract used to look up resolvers and owners for domains. It maintains a mapping of domain nodes to their ownership, resolver, and TTL records.

Overview

ENSRegistry is the foundational contract of the Ethereum Name Service. It:
  • Stores ownership, resolver, and TTL information for all ENS domains
  • Provides access control through owner-based authorization
  • Supports operator delegation for managing records
  • Enables hierarchical domain structure through subnode creation

Import

import '@ensdomains/ens-contracts/contracts/registry/ENSRegistry.sol';

Constructor

constructor() public
Constructs a new ENS registry. The deployer becomes the owner of the root node (0x0).

State Variables

records

mapping(bytes32 => Record) records
Maps node hashes to their record information. Record struct:
struct Record {
    address owner;
    address resolver;
    uint64 ttl;
}

operators

mapping(address => mapping(address => bool)) operators
Maps owner addresses to operator addresses and their approval status.

Modifiers

authorised

modifier authorised(bytes32 node)
Permits modifications only by the owner of the specified node or an approved operator.

Functions

setRecord

function setRecord(
    bytes32 node,
    address owner,
    address resolver,
    uint64 ttl
) external virtual override
Sets the record for a node.
node
bytes32
required
The node to update
owner
address
required
The address of the new owner
resolver
address
required
The address of the resolver
ttl
uint64
required
The TTL in seconds

setSubnodeRecord

function setSubnodeRecord(
    bytes32 node,
    bytes32 label,
    address owner,
    address resolver,
    uint64 ttl
) external virtual override
Sets the record for a subnode.
node
bytes32
required
The parent node
label
bytes32
required
The hash of the label specifying the subnode
owner
address
required
The address of the new owner
resolver
address
required
The address of the resolver
ttl
uint64
required
The TTL in seconds

setOwner

function setOwner(
    bytes32 node,
    address owner
) public virtual override authorised(node)
Transfers ownership of a node to a new address. May only be called by the current owner of the node or an approved operator.
node
bytes32
required
The node to transfer ownership of
owner
address
required
The address of the new owner
Emits: Transfer(node, owner)

setSubnodeOwner

function setSubnodeOwner(
    bytes32 node,
    bytes32 label,
    address owner
) public virtual override authorised(node) returns (bytes32)
Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
node
bytes32
required
The parent node
label
bytes32
required
The hash of the label specifying the subnode
owner
address
required
The address of the new owner
Returns: The subnode hash keccak256(abi.encodePacked(node, label)) Emits: NewOwner(node, label, owner)

setResolver

function setResolver(
    bytes32 node,
    address resolver
) public virtual override authorised(node)
Sets the resolver address for the specified node.
node
bytes32
required
The node to update
resolver
address
required
The address of the resolver
Emits: NewResolver(node, resolver)

setTTL

function setTTL(
    bytes32 node,
    uint64 ttl
) public virtual override authorised(node)
Sets the TTL for the specified node.
node
bytes32
required
The node to update
ttl
uint64
required
The TTL in seconds
Emits: NewTTL(node, ttl)

setApprovalForAll

function setApprovalForAll(
    address operator,
    bool approved
) external virtual override
Enables or disables approval for a third party (“operator”) to manage all of msg.sender’s ENS records.
operator
address
required
Address to add to the set of authorized operators
approved
bool
required
True if the operator is approved, false to revoke approval
Emits: ApprovalForAll(msg.sender, operator, approved)

owner

function owner(
    bytes32 node
) public view virtual override returns (address)
Returns the address that owns the specified node.
node
bytes32
required
The specified node
Returns: The address of the owner. Returns address(0x0) if the owner is the registry itself.

resolver

function resolver(
    bytes32 node
) public view virtual override returns (address)
Returns the address of the resolver for the specified node.
node
bytes32
required
The specified node
Returns: The address of the resolver

ttl

function ttl(bytes32 node) public view virtual override returns (uint64)
Returns the TTL of a node and any records associated with it.
node
bytes32
required
The specified node
Returns: The TTL of the node in seconds

recordExists

function recordExists(
    bytes32 node
) public view virtual override returns (bool)
Returns whether a record has been imported to the registry.
node
bytes32
required
The specified node
Returns: True if the record exists (owner is not address(0x0))

isApprovedForAll

function isApprovedForAll(
    address owner,
    address operator
) external view virtual override returns (bool)
Queries if an address is an authorized operator for another address.
owner
address
required
The address that owns the records
operator
address
required
The address that acts on behalf of the owner
Returns: True if operator is an approved operator for owner, false otherwise

Usage Examples

import '@ensdomains/ens-contracts/contracts/registry/ENSRegistry.sol';

// Deploy the registry
ENSRegistry registry = new ENSRegistry();

// The deployer now owns the root node
// and can create top-level domains

Build docs developers (and LLMs) love