Skip to main content
The NameWrapper contract is the main contract that implements name wrapping functionality for ENS names.

Wrapping Functions

wrapETH2LD()

State Transition: Unwrapped → Emancipated | Locked Wraps a .eth second-level name. The wrapped name’s expiration will always be equal to the name’s expiration in the .eth registrar plus the grace period (90 days).
label
string
Label as a string of the .eth domain to wrap (e.g., ‘vitalik’ for ‘vitalik.eth’)
wrappedOwner
address
Owner of the name in this contract
ownerControlledFuses
uint16
Initial owner-controlled fuses to set
resolver
address
Resolver contract address
Can only be called by the owner of the name on the .eth registrar or an authorized caller on the registrar.
If fuses are provided, they will be burned at the same time as wrapping, moving the name directly to Locked status.

wrap()

State Transition: Unwrapped → Wrapped | Emancipated Wraps any name other than a .eth second-level name.
name
bytes
The name to wrap, in DNS format
wrappedOwner
address
Owner of the name in this contract
resolver
address
Resolver contract
Can only be called by the owner in the registry or an authorized caller in the registry.
Parent-controlled fuses are retained on unwrap, so if the name was previously Emancipated and has not since expired, it will return directly to the Emancipated state.

onERC721Received()

State Transition: Unwrapped → Emancipated | Locked Wraps a .eth second-level name by sending the ERC721 NFT to the wrapper contract. Transfers must contain additional data encoding information about the wrapped name such as fuses and expiration, or they will be rejected. Otherwise behaves identically to wrapETH2LD.

registerAndWrapETH2LD()

State Transition: Unregistered → Emancipated | Locked Allows a registrar controller to register and wrap a name in a single operation.
label
string
The label to register (e.g., ‘foo’ for ‘foo.eth’)
wrappedOwner
address
The owner of the wrapped name
duration
uint256
The duration, in seconds, to register the name for
resolver
address
The resolver address to set on the ENS registry (optional)
ownerControlledFuses
uint16
Initial owner-controlled fuses to set
Only callable by authorized controllers.
After registering the name, behaves identically to wrapETH2LD.

Unwrapping Functions

unwrapETH2LD()

State Transition: Emancipated → Unwrapped Unwraps a .eth second-level name, provided that the name is not Locked.
labelhash
bytes32
Labelhash of the .eth domain
registrant
address
Sets the owner in the .eth registrar to this address
controller
address
Sets the owner in the registry to this address
Can only be called by the owner in the wrapper or an authorized caller in the wrapper.

unwrap()

State Transition: Wrapped | Emancipated → Unwrapped Unwraps any name other than a .eth second-level name, provided that the name is not Locked.
parentNode
bytes32
Parent namehash of the name (e.g., vitalik.xyz would be namehash(‘xyz’))
labelhash
bytes32
Labelhash of the name (e.g., vitalik.xyz would be keccak256(‘vitalik’))
controller
address
Sets the owner in the registry to this address
Can only be called by the owner in the wrapper or an authorized caller in the wrapper.
Parent-controlled fuses are retained on unwrap, so if the name was previously Emancipated and has not since expired, it will return directly to the Emancipated state if wrap() is called on it.

Fuse Management Functions

setFuses()

State Transition: Emancipated | Locked → Locked Sets fuses of a name.
node
bytes32
Namehash of the name
ownerControlledFuses
uint16
Owner-controlled fuses to burn
setFuses() can only be called by the owner of a name, and can burn any user-controlled fuses. It cannot burn parent-controlled fuses.In order to burn any other fuse, CANNOT_UNWRAP must be burned as well, moving the name to the Locked state.Cannot be called if CANNOT_BURN_FUSES has been burned.

setChildFuses()

State Transition: Wrapped → Emancipated | Locked Sets fuses of a name that you own the parent of.
parentNode
bytes32
Parent namehash of the name (e.g., vitalik.xyz would be namehash(‘xyz’))
labelhash
bytes32
Labelhash of the name (e.g., vitalik.xyz would be keccak256(‘vitalik’))
fuses
uint32
Fuses to burn
expiry
uint64
When the name will expire in seconds since the Unix epoch
setChildFuses() can only be called by the parent owner of a name. It can burn both user-controlled and parent-controlled fuses.If the name is Emancipated or Locked, this function may be called to extend the expiry, but cannot burn any further fuses.

Expiry Management Functions

extendExpiry()

State Transition: Wrapped | Emancipated | Locked → Wrapped | Emancipated | Locked Extends expiry for a name.
parentNode
bytes32
Parent namehash of the name (e.g., vitalik.xyz would be namehash(‘xyz’))
labelhash
bytes32
Labelhash of the name (e.g., vitalik.xyz would be keccak256(‘vitalik’))
expiry
uint64
When the name will expire in seconds since the Unix epoch
extendExpiry() can only be called by the owner of a name, the owner of the parent name or an approved address (known as a renewal manager). When called by the owner of the name, the CAN_EXTEND_EXPIRY fuse must have already been burned by the parent.The expiry can only be extended, not reduced. And the max expiry is automatically set to the expiry of the parent node.

renew()

State Transition: Emancipated | Locked → Emancipated | Locked Allows a registrar controller to renew a .eth second-level name.
tokenId
uint256
The hash of the label to register (e.g., keccak256('foo'), for ‘foo.eth’)
duration
uint256
The number of seconds to renew the name for
Only callable by authorized controllers.

Subdomain Management Functions

setSubnodeOwner()

State Transition: Unregistered | Unwrapped | Wrapped → Unregistered | Wrapped | Emancipated | Locked Creates, replaces, or deletes a subname.
parentNode
bytes32
Parent namehash of the subdomain
label
string
Label of the subdomain as a string
owner
address
New owner in the wrapper
fuses
uint32
Initial fuses for the wrapped subdomain
expiry
uint64
When the name will expire in seconds since the Unix epoch
  • When called with a subname that does not yet exist, creates the name and wraps it.
  • When called with a subname that already exists, transfers the name to a new owner, wrapping it if necessary, provided the name is not Emancipated or Locked.
  • When called with a subname that exists and a new owner value of address(0), unwraps and deletes the name.
If an expiration is provided, the subname’s expiration will be set to the greater of the provided expiration and the one already on the subname. If fuses are provided, they will be burned on the subname.

setSubnodeRecord()

State Transition: Unregistered | Unwrapped | Wrapped → Wrapped | Emancipated | Locked Creates or replaces a subname while updating resolver and TTL records.
parentNode
bytes32
Parent namehash of the subdomain
label
string
Label of the subdomain as a string
owner
address
New owner in the wrapper
resolver
address
Resolver contract in the registry
ttl
uint64
TTL in the registry
fuses
uint32
Initial fuses for the wrapped subdomain
expiry
uint64
When the name will expire in seconds since the Unix epoch
Behaves identically to setSubnodeOwner(), additionally setting the resolver and TTL for the subname. If the new owner is address(0), resolver and TTL are ignored.

Record Setting Functions

setRecord()

State Transition: Wrapped | Emancipated | Locked → Unregistered | Wrapped | Emancipated | Locked Mirrors the existing registry functionality, allowing you to set owner, resolver and ttl at the same time.
node
bytes32
Namehash of the name to set a record for
owner
address
New owner in the registry
resolver
address
Resolver contract
ttl
uint64
Time to live in the registry
When called with an owner of address(0), unwraps the name provided it is not Locked and not a .eth second-level name.

setResolver()

State Transition: Wrapped | Emancipated | Locked → Wrapped | Emancipated | Locked Sets resolver contract in the registry.
node
bytes32
Namehash of the name
resolver
address
The resolver contract

setTTL()

State Transition: Wrapped | Emancipated | Locked → Wrapped | Emancipated | Locked Sets TTL in the registry.
node
bytes32
Namehash of the name
ttl
uint64
TTL in the registry

Query Functions

getData()

Gets the data for a name.
id
uint256
Namehash of the name
Returns:
  • owner (address): Owner of the name
  • fuses (uint32): Fuses of the name
  • expiry (uint64): Expiry of the name
The fuses it returns will be a uint32 and you will have to decode this yourself. If you just need to check a fuse has been burned, you can call allFusesBurned as it will use less gas.

ownerOf()

Gets the owner of a name.
id
uint256
Namehash of the name
Returns:
  • owner (address): The owner of the name
It adheres to the rules applied by emancipating a name. If the name is emancipated, expired names will return address(0) when calling ownerOf.

allFusesBurned()

Checks all fuses in the mask are burned for the node.
node
bytes32
Namehash of the name
fuseMask
uint32
The fuses you want to check
Returns:
  • bool: Whether or not all the selected fuses are burned
const areBurned = await allFusesBurned(
  namehash('vitalik.eth'),
  CANNOT_TRANSFER | CANNOT_SET_RESOLVER,
)
// if CANNOT_UNWRAP AND CANNOT_SET_RESOLVER are *both* burned this will return true

isWrapped()

Checks if a name is wrapped.
node
bytes32
Namehash of the name
Returns:
  • bool: Whether or not the name is wrapped
Alternatively, you can call the overloaded version:
parentNode
bytes32
Parent namehash of the name
labelhash
bytes32
Labelhash of the name
This version is more gas efficient.

canModifyName()

Checks if the address is the owner or operator of the owner.
node
bytes32
Namehash of the name to check
addr
address
Which address to check permissions for
Returns:
  • bool: Whether or not is owner or operator

canExtendSubnames()

Checks if the address is owner/operator or approved by owner.
node
bytes32
Namehash of the name to check
addr
address
Which address to check permissions for
Returns:
  • bool: Whether or not is owner/operator or approved

Upgrade Functions

upgrade()

Upgrades a domain of any kind. Could be a .eth name vitalik.eth, a DNSSEC name vitalik.xyz, or a subdomain.
name
bytes
The name to upgrade, in DNS format
extraData
bytes
Extra data to pass to the upgrade contract
Can only be called by the owner or an authorized caller.

setUpgradeContract()

Sets the address of the upgradeContract of the contract.
_upgradeAddress
INameWrapperUpgrade
Address of an upgraded contract
Only the owner can call this function. The default value of upgradeContract is the 0 address. Use the 0 address at any time to make the contract not upgradable.

Administrative Functions

setMetadataService()

Sets the metadata service.
_metadataService
IMetadataService
The new metadata service
Only the owner can call this function.

Build docs developers (and LLMs) love