ENS

Creating a ENS

Creating a simple ENS for testing with ENS.

import {MockProvider} from '@ethereum-waffle/provider';
import {deployENS, ENS} from '@ethereum-waffle/ens';

const provider = new MockProvider();
const [wallet] = provider.getWallets();
const ens: ENS = await deployENS(wallet);

This class takes a wallet in the constructor. The wallet available in MockProvider class in package @ethereum-waffle/provider.

Also, if you use MockProvider, you can use setupENS() function in MockProvider, to create and setup simple ENS. Read more about this usage here.

Creating top level domain

Use createTopLevelDomain function to create a top level domain:

await ensBuilder.createTopLevelDomain('test');

Creating sub domain

Use createSubDomain function for creating a sub domain:

await ensBuilder.createSubDomain('ethworks.test');

Also, it’s possible to create a sub domain recursively, if the top domain doesn’t exist, by specifying the appropriate option:

await ens.createSubDomain('waffle.ethworks.tld', {recursive: true});

Setting address

Use setAddress function for setting address for the domain:

await ensBuilder.setAddress('vlad.ethworks.test', '0x001...03');

Also, it’s possible to set an address for domain recursively, if the domain doesn’t exist, by specifying the appropriate option:

await ens.setAddress('vlad.waffle.ethworks.tld', '0x001...03', {recursive: true});

Use setAddressWithReverse function for setting address for the domain and make this domain reverse. Add recursive option if the domain doesn’t exist:

await ens.setAddressWithReverse('vlad.ethworks.tld', wallet, {recursive: true});