ENS Logo

Naming Contracts

For most regular wallets you can set your primary name from within the Manager App. However also smart contracts can have names, and even better they can have primary names.

governance.uniswap.eth

In order for you to manage the primary name of your smart contract, you need to own the reverse node for the contract address. There are several ways of doing this, depending on if you are actively developing your contract or if it is already deployed.

New Contracts

If you are developing a new contract, and you want to be able to easily set the ENS Primary Name for it.

ReverseClaimer.sol

There is a simple drop-in module called the ReverseClaimer.sol

contract MyContract is ReverseClaimer {
    constructor (ENS ens) ReverseClaimer(ens, msg.sender) {
        // ...
    }
}

When you deploy your contract it will automatically claim the reverse node for that contract address.

Ownable (OpenZeppelin)

You can can also choose to have your smart-contract implement Ownable from OpenZeppelin. The ReverseRegistrar supports the Ownable interface and will let the Owner set a Primary name.

Manually

//SPDX-License-Identifier: MIT
pragma solidity >=0.8.17 <0.9.0;

import {ENS} from "../registry/ENS.sol";
import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";

contract ReverseClaimer {
    bytes32 constant ADDR_REVERSE_NODE =
        0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;

    constructor(ENS ens, address claimant) {
        IReverseRegistrar reverseRegistrar = IReverseRegistrar(ens.owner(ADDR_REVERSE_NODE));
        reverseRegistrar.claim(claimant);
    }
}

You can also call the ReverseRegistrar's setName function directly. However note that if you do this, you will not be able to change the primary name for that contract ever again. Also remember to set the ETH address on your ENS name to the address at which your contract was deployed.

import {ENS} from "../registry/ENS.sol";
import {IReverseRegistrar} from "../reverseRegistrar/IReverseRegistrar.sol";

contract ReverseClaimer {
    bytes32 constant ADDR_REVERSE_NODE =
        0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;

    constructor(ENS ens, string primaryName) {
        IReverseRegistrar reverseRegistrar = IReverseRegistrar(ens.owner(ADDR_REVERSE_NODE));
        reverseRegistrar.setName(primaryName);
    }
}

You can read more about setting a primary name for a contract in on the support page.

Existing Contracts

If your contract is already deployed you might still be able to set a name for it. If your contract supports the Ownable interface from OpenZeppelin, you can use the tool above to set a name for it.

Safe, Multisig & DAO

If your contract is a Safe, Multisig, DAO, or has a function that can send arbitrary ETH calls, you can use the ReverseRegistrar contract directly to set a name for it. You might even be able to use the ENS Manager App inside of your safe app to set a primary name.

Setting a name for your contract

Once you have granted yourself ownership of the contract's reverse node you can set the name for the contract. You can do so by hitting the setNameForAddr function on the Reverse Registrar.

From your contract you can execute setName function on the Reverse Registrar

Reverse Set Name For
Supports Ownable
User is owner of contract
Transaction
Set Reverse Name.
ReverseRegistrar.setNameForAddr(<Address>, <Owner>, 0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63, <Name>)

L2 Contracts

Primary Names are not yet supported on L2s. In the meantime, the following sections only apply to testnet ENS deployments. Mainnet support should be coming by the end of January 2025.

L2 - Ownable

If you want to set a primary name for a contract you are deploying on an L2 chain, you need to make sure your contract implements the Ownable interface from OpenZeppelin, and has an account you own set as the owner.

You will also need to locate the canonical Reverse Registry for that L2 chain. We currently do not have a way to discover those contracts, but for now, selected deployments are listed here: Primary Names

Then, after you've deployed your contract, call setNameForAddr(address addr, string name) on the L2 Reverse Resolver from your authorized owner account. The addr is the address of your contract, and name is the ENS name to set it to.

L2 - Manually

Another option is to call the L2ReverseRegistry's setName(string name) function directly, in the constructor of your contract. However note that if you do this, you will not be able to change the primary name for that contract ever again.

Last Modified
25 days ago