Skip to main content
The ENS interface defines the core contract specification that lies at the heart of ENS resolution. All ENS lookups start by querying a contract that implements this interface.

Overview

The ENS interface is the base specification for the ENS Registry. It defines methods for:
  • Managing domain ownership and transfers
  • Setting and querying resolvers
  • Managing TTL (Time To Live) values
  • Creating and managing subdomains
  • Operator approvals for managing records on behalf of owners

Import

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

Events

NewOwner

event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner)
Logged when the owner of a node assigns a new owner to a subnode.
node
bytes32
required
The parent node
label
bytes32
required
The hash of the subdomain label
owner
address
required
The address of the new owner

Transfer

event Transfer(bytes32 indexed node, address owner)
Logged when the owner of a node transfers ownership to a new account.
node
bytes32
required
The node being transferred
owner
address
required
The address of the new owner

NewResolver

event NewResolver(bytes32 indexed node, address resolver)
Logged when the resolver for a node changes.
node
bytes32
required
The node whose resolver is being updated
resolver
address
required
The address of the new resolver

NewTTL

event NewTTL(bytes32 indexed node, uint64 ttl)
Logged when the TTL of a node changes.
node
bytes32
required
The node whose TTL is being updated
ttl
uint64
required
The new TTL value in seconds

ApprovalForAll

event ApprovalForAll(address indexed owner, address indexed operator, bool approved)
Logged when an operator is added or removed.
owner
address
required
The address that owns the records
operator
address
required
The address being approved or revoked
approved
bool
required
True if approved, false if revoked

Functions

setRecord

function setRecord(
    bytes32 node,
    address owner,
    address resolver,
    uint64 ttl
) external
Sets the owner, resolver, and TTL for a node in a single operation.
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
Sets the owner, resolver, and TTL for a subnode in a single operation.
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

setSubnodeOwner

function setSubnodeOwner(
    bytes32 node,
    bytes32 label,
    address owner
) external returns (bytes32)
Creates a new subnode and sets its owner.
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 created subnode hash keccak256(abi.encodePacked(node, label))

setResolver

function setResolver(bytes32 node, address resolver) external
Sets the resolver address for a node.
node
bytes32
required
The node to update
resolver
address
required
The address of the resolver

setOwner

function setOwner(bytes32 node, address owner) external
Transfers ownership of a node to a new address.
node
bytes32
required
The node to transfer ownership of
owner
address
required
The address of the new owner

setTTL

function setTTL(bytes32 node, uint64 ttl) external
Sets the TTL for a node.
node
bytes32
required
The node to update
ttl
uint64
required
The TTL in seconds

setApprovalForAll

function setApprovalForAll(address operator, bool approved) external
Enables or disables approval for a third party (“operator”) to manage all of the caller’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

owner

function owner(bytes32 node) external view returns (address)
Returns the address that owns the specified node.
node
bytes32
required
The specified node
Returns: The address of the owner

resolver

function resolver(bytes32 node) external view 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) external view 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) external view returns (bool)
Returns whether a record exists for the specified node.
node
bytes32
required
The specified node
Returns: True if the record exists, false otherwise

isApprovedForAll

function isApprovedForAll(
    address owner,
    address operator
) external view 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 Example

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

contract MyContract {
    ENS public ens;

    constructor(ENS _ens) {
        ens = _ens;
    }

    function resolveAddress(bytes32 node) public view returns (address) {
        address resolverAddress = ens.resolver(node);
        // Use the resolver to get more information
        return resolverAddress;
    }

    function checkOwnership(bytes32 node) public view returns (address) {
        return ens.owner(node);
    }
}

Build docs developers (and LLMs) love