- Clone project and switch to contracts
git clone https://github.com/me3-eth/contracts.git me3-eth-contracts cd me3-eth-contracts - Optional: set node version with NVM
nvm use
- Install dependencies
npm install
- Create environment file
touch .env
- Fill in environment value with template and your data
# Template env file ALCHEMY_API_KEY= ENS_REGISTRY=0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e WALLET_PK_ROPSTEN= COINMARKETCAP_API_KEY=
There is a deploy script in the scripts/ folder, it can be run like this:
# for local
npx hardhat run scripts/deploy.js
# for ropsten
npx hardhat run scripts/deploy.js --network ropstenLocal deployments will also deploy all of the necessary ENS contracts.
SiteManager is a custom registrar that provides subnode for a single node, updates a resolver with provided information, and assigns ownership of the subnode to the sender.
Current gas usage: 88247-880992
Signature:
function subdomainRegister (bytes32 label, bytes[] calldata data) external returns (bytes[] memory results);labelis the subdomain to be registered. For example, if the root domain is help.eth and thelabelis no then the subdomain will be no.help.eth.datais a collection of contract calls on the stored ENS resolver. Default deployment uses the ENS PublicResolver so any properly encoded functions used here will be called on PublicResolver. Note thatmulticallwill fail. See available functions in ENS PublicResolver docs.
To use this function from Javascript (in a browser), here is a brief example using ethers.
import { ethers } from 'ethers'
import { Resolver } from '@ensdomains/ens-contracts'
const RESOLVER_ADDRESS = ''
const SITE_MANAGER_ADDRESS = ''
const rootNodeName = 'somedemo.eth'
const labelHash = label => ethers.utils.namehash(`${ethers.utils.id(label)}.${rootNodeName}`)
const provider = new ethers.providers.Web3Provider(window.ethereum)
async function createSubdomain (label) {
// Get signer from metamask
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
// Create contract insances
const resolver = new ethers.Contract(RESOLVER_ADDRESS, Resolver, signer)
const siteManagerAbi = [
'function subdomainRegister(bytes32 label, bytes[] calldata data) external returns (bytes[] memory)'
]
const siteManager = new ethers.Contract(SITE_MANAGER_ADDRESS, siteManagerAbi, signer)
// Register a subdomain
const encodedFunctions = [
resolver.interface.encodeFunctionData('setText', [labelHash(label), 'com.github', '0xcharchar']),
]
const regTx = await siteManager.subdomainRegister(ethers.utils.id(label), encodedFunctions, { gasLimit: 500000 })
const txResult = await regTx.wait()
console.log('Registration result', txResult)
}
createSubdomain('mysub')SiteManagerLite is a limited version of SiteManager. It:
- registers a subdomain
- sets a contenthash
- transfers ownership from the SiteManagerLite contract to the requestor
Current gas usage: 167647
Signature:
function subdomainRegister (bytes32 label, bytes32 fullAddress, bytes calldata hash) external;To use this function from Javascript (in a browser), here is a brief example using ethers.
import { ethers } from 'ethers'
import { Resolver } from '@ensdomains/ens-contracts'
const RESOLVER_ADDRESS = ''
const SITE_MANAGER_ADDRESS = ''
const rootNodeName = 'somedemo.eth'
const labelHash = label => ethers.utils.namehash(`${ethers.utils.id(label)}.${rootNodeName}`)
const provider = new ethers.providers.Web3Provider(window.ethereum)
async function createSubdomain (label) {
// Get signer from metamask
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
// Create contract insances
const resolver = new ethers.Contract(RESOLVER_ADDRESS, Resolver, signer)
const siteManagerAbi = [
'function subdomainRegister(bytes32 label, bytes[] calldata data) external returns (bytes[] memory)'
]
const siteManager = new ethers.Contract(SITE_MANAGER_ADDRESS, siteManagerAbi, signer)
// Register a subdomain
const encodedFunctions = [
resolver.interface.encodeFunctionData('setText', [labelHash(label), 'com.github', '0xcharchar']),
]
const regTx = await siteManager.subdomainRegister(ethers.utils.id(label), encodedFunctions, { gasLimit: 500000 })
const txResult = await regTx.wait()
console.log('Registration result', txResult)
}
createSubdomain('mysub')Testing is done with hardhat:
npx hardhat test