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
.
Setup ENS¶
Note
The feature was introduced in Waffle 3.0.0
Also, if you use MockProvider
, you can use setupENS()
function in MockProvider
,
to create and setup simple ENS
.
import {MockProvider} from '@ethereum-waffle/provider';
const provider = new MockProvider();
await provider.setupENS();
await provider.ens.createTopLevelDomain('test');
setupENS()
method employs the last of the provider’s wallets
by default, but you can pass your own wallet
as an argument for setupENS(wallet)
.
Also setupENS()
method saves ENS address in the provider’s networks.
Creating top level domain¶
Use createTopLevelDomain
function to create a top level domain:
await ens.createTopLevelDomain('test');
Creating sub domain¶
Use createSubDomain
function for creating a sub domain:
await ens.createSubDomain('ethworks.test');
Creating sub domain with options¶
Note
The feature was introduced in Waffle 3.0.0
It is also 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');
Setting address with options¶
Note
The feature was introduced in Waffle 3.0.0
It is also 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});