Deploying ENS on a Private Chain

If you’d like to deploy ENS on your own network, or deploy your own copy of ENS on a public network, this guide shows you how. If you want to use an existing ENS deployment, see Resolving Names, Managing Names, and Registering & Renewing Names instead.

On this page we will use Javascript, Web3 and Truffle for simplicity.

Importing contracts

The majority of smart contrats are published as npm modules (eg: ENS registry) which you can require at migration.

const ENS = require(`@ensdomains/ens/build/contracts/ENSRegistry.sol`)

Including within your smart contract is as follows

import "@ensdomains/ens/contracts/ENS.sol";

ENS contains only interface while ENSRegistry includes the actual implementation.

Deploy the Registry

First, you need to deploy ENS’s central component, the registry.

const ens = await;

Once deployed, you will have a fresh ENS registry, whose root node is owned by the account that submitted the transaction. This account has total control over the ENS registry - it can create and replace any node in the entire tree.

From here, it's possible to create and manage names by directly interacting with the registry, as described in Managing Names. However, you will probably want to deploy a resolver, and you may want to deploy a registrar so other users can register names.

Deploy a Resolver

For most purposes, it's convenient to have a general-purpose resolver available that users can easily use for their names. Deploying one is straightforward:

const publicResolver = await;

For ease of use, we can give this resolver a name:

const namehash = require('eth-ens-namehash');
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", sha3("resolver"), accounts[0]);
await ens.setResolver(namehash.hash("resolver"), publicResolver.address);
await publicResolver.setAddr(namehash.hash("resolver"), publicResolver.address);

Above, we first create a new top-level domain, "resolver", then set its resolver address to our newly deployed public resolver. Finally, we set up an address record for "resolver", pointing back to the resolver address. In effect, the resolver is answering queries about its own address. After this, anyone can find the public resolver at the special ENS name "resolver".

Deploy a Registrar

In order to allow others to register domains without your direct intervention, you will need to deploy a registrar contract, and set it as the owner of a top-level domain that you want it to assign subdomains of. Here, we'll use the simple FIFSRegistrar, and set it as the owner of the top-level domain test:

const sha3 = require('web3-utils').sha3;
const testRegistrar = await, namehash.hash("test"));
ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", sha3("test"), testRegistrar);

Any user can now register domains under .test by calling the register function:

await testRegistrar.register(sha3("alice"), accounts[0]);

After calling the above function, accounts[0] now has ownership of the name alice.test.

Deploy the Reverse Registrar

If you wish to enable reverse resolution on your deployment, you will need to deploy the reverse registrar:

const reverseRegistrar = await, publicResolver.address);
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", sha3("reverse"), accounts[0]);
await ens.setSubnodeOwner(namehash.hash("reverse"), sha3("addr"), reverseRegistrar.address);