in the project of GitHub - ensdomains/ens-contracts: The core contracts of the ENS protocol
const hre = require("hardhat");
const namehash = require('eth-ens-namehash');
const tld = "test";
const ethers = hre.ethers;
const utils = ethers.utils;
const labelhash = (label) => utils.keccak256(utils.toUtf8Bytes(label))
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
console.log("start deploy in own chain")
async function main() {
const ENSRegistry = await ethers.getContractFactory("ENSRegistry")
const FIFSRegistrar = await ethers.getContractFactory("FIFSRegistrar")
const ReverseRegistrar = await ethers.getContractFactory("ReverseRegistrar")
const PublicResolver = await ethers.getContractFactory("PublicResolver")
const signers = await ethers.getSigners();
const accounts = signers.map(s => s.address)
const ens = await ENSRegistry.deploy()
console.log("ens begin ENSRegistry deploy")
await ens.deployed()
console.log("ens end ENSRegistry deploy")
console.log("ens.address",ens.address)
const resolver = await PublicResolver.deploy(ens.address, ZERO_ADDRESS);
console.log("ens begin resolver deploy")
await resolver.deployed()
console.log("ens end resolver deploy")
await setupResolver(ens, resolver, accounts)
console.log("ens end setupResolver")
const registrar = await FIFSRegistrar.deploy(ens.address, namehash.hash(tld));
console.log("ens start FIFSRegistrar deploy")
await registrar.deployed()
console.log("ens end FIFSRegistrar deploy")
await setupRegistrar(ens, registrar);
console.log("ens end setupRegistrar")
const reverseRegistrar = await ReverseRegistrar.deploy(ens.address, resolver.address);
console.log("ens start reverseRegistrar deploy")
await reverseRegistrar.deployed()
console.log("ens end reverseRegistrar deploy")
await setupReverseRegistrar(ens, registrar, reverseRegistrar, accounts);
console.log("ens end setupReverseRegistrar")
};
async function setupResolver(ens, resolver, accounts) {
const resolverNode = namehash.hash("resolver");
const resolverLabel = labelhash("resolver");
await ens.setSubnodeOwner(ZERO_HASH, resolverLabel, accounts[0]);
await ens.setResolver(resolverNode, resolver.address);
await resolver['setAddr(bytes32,address)'](resolverNode, resolver.address);
}
async function setupRegistrar(ens, registrar) {
await ens.setSubnodeOwner(ZERO_HASH, labelhash(tld), registrar.address);
}
async function setupReverseRegistrar(ens, registrar, reverseRegistrar, accounts) {
await ens.setSubnodeOwner(ZERO_HASH, labelhash("reverse"), accounts[0]);
await ens.setSubnodeOwner(namehash.hash("reverse"), labelhash("addr"), reverseRegistrar.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});```
and run
npx hardhat run scripts/deploy.js
The output is
![image|568x220](upload://joD8B0ghDrdIxg5TtKbW1ln0X7K.png)