Created
July 13, 2021 15:45
-
-
Save is/42d67300dcf7f9700f655921101bfa41 to your computer and use it in GitHub Desktop.
deploy ens contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations | |
https://docs.ens.domains/deploying-ens-on-a-private-chain | |
https://www.trufflesuite.com/docs/truffle/reference/truffle-commands#migrate | |
*/ | |
const utils = require('web3-utils'); | |
const namehash = require('eth-ens-namehash'); | |
const tld = "test"; | |
const ENS = artifacts.require("@ensdomains/ens/ENSRegistry"); | |
const FIFSRegistrar = artifacts.require("@ensdomains/ens/FIFSRegistrar"); | |
const ReverseRegistrar = artifacts.require("@ensdomains/ens/ReverseRegistrar"); | |
const PublicResolver = artifacts.require("@ensdomains/resolver/PublicResolver"); | |
async function setupResolver(ens, resolver, accounts) { | |
const resolverNode = namehash.hash("resolver"); | |
const resolverLabel = utils.sha3("resolver"); | |
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", resolverLabel, accounts[0]); | |
await ens.setResolver(resolverNode, resolver.address); | |
await resolver.setAddr(resolverNode, resolver.address); | |
} | |
async function setupRegistrar(ens, registrar) { | |
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", utils.sha3(tld), registrar.address); | |
} | |
async function setupReverseRegistrar(ens, resolver, reverseRegistrar, accounts) { | |
await ens.setSubnodeOwner("0x0000000000000000000000000000000000000000", utils.sha3("reverse"), accounts[0]); | |
await ens.setSubnodeOwner(namehash.hash("reverse"), utils.sha3("addr"), reverseRegistrar.address); | |
} | |
module.exports = async (deployer, network, accounts) => { | |
await deployer.deploy(ENS) | |
const ens = await ENS.deployed() | |
await deployer.deploy(PublicResolver, ens.address) | |
const resolver = await PublicResolver.deployed() | |
await setupResolver(ens, resolver, accounts) | |
await deployer.deploy(FIFSRegistrar, ens.address, namehash.hash(tld)) | |
const registrar = await FIFSRegistrar.deployed() | |
await setupRegistrar(ens, registrar, accounts) | |
await deployer.deploy(ReverseRegistrar, ens.address, resolver.address) | |
const reverseRegistrar = await ReverseRegistrar.deployed() | |
await setupReverseRegistrar(ens, resolver, reverseRegistrar, accounts) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment