All Collections
Developer Basics
Set primary name for contract
Set primary name for contract
Updated over a week ago

Set Primary Name For Contract

For most regular wallet accounts, you can just use the ENS Manager App to set the Primary Name. Even if your address is technically a contract account, you may still be able to use the app to do this, if the contract allows arbitrary transactions (e.g. Gnosis Safe).

See here for a how-to guide for the Manager App: Set a Primary Name

Otherwise, see below for additional methods.

Existing contracts

If your contract has already been deployed, and it doesn't have any built-in methods to set its own primary name, then you may still be able to set it by other means, if:

  • Your contract inherits the Ownable module, and you are the owner

Or:

  • You are an approved operator for the contract in the ENS Registry.

Using Set Primary Tool

This is a small helper website we built on the side to address some edge-cases that may not make sense for the ENS Manager App (or are still on the roadmap):

Simply connect your wallet, enter your name, and then click on Set Primary Name.

Using the contract directly

You can interact directly with the Reverse Registrar contract on Etherscan: https://etherscan.io/address/0xa58e81fe9b61b5c3fe2afd33cf304c454abfc7cb#writeContract#F8

At the top, click on "Connect to Web3" to connect your wallet. Then scroll down and expand the setNameForAddrmethod:

Enter the four fields:

  • addr: The contract address you are setting the primary name for.

  • owner: The owner of the reverse node in the ENS Registry. Enter your address.

  • resolver: The resolver to use for the reverse node. Enter the default Public Resolver: 0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63

  • name: The primary name to set for the contract. This must be a name that already forward-resolves to the contract address, otherwise Primary Name resolution will not work.

Then click on Write to send the transaction to your wallet.


New Contracts

If you a developing a new contract, and you want to be able to easily set the ENS Primary Name for it, then you can include this module: ReverseClaimer.sol

Also include the interface for the core ENS registry: ENS.sol

Make sure your contract inherits ReverseClaimer:

contract MyContract is ReverseClaimer {
...
}

Then call it in your constructor:

constructor (
ENS ens,
...
) ReverseClaimer(ens, msg.sender) {
...
}

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

Then, use the tool above to set the Primary Name whenever you want.

If you want to do it manually via the contract, see below.


When you already own the reverse node

If you already own the reverse node for a particular address, then you can update the Primary Name at any time.

Using Set Primary Tool:

The easiest method is just to use the same tool as above! It will automatically make sure you have a resolver set on the node, and then set the name for you.

Using the contract directly:

If you want to call the contracts directly instead, then see below.

The "reverse node" is the namehash for <addr>.addr.reverse, where <addr> is the address (all lowercase, and remove the 0x).

Example for address 0x481f50a5BdcCC0bc4322C4dca04301433dED50f0

  • namehash('481f50a5bdccc0bc4322c4dca04301433ded50f0.addr.reverse')

  • 0x58354ffdde6ac279f3a058aafbeeb14059bcb323a248fb338ee41f95fa544c86

If none is set, set the resolver to the default Public Resolver (0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63): https://etherscan.io/address/0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e#writeContract#F4

Then, call setName on the resolver:

Did this answer your question?