Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

me3-eth/contracts

Repository files navigation

me3 Contracts

Setup

  1. Clone project and switch to contracts
    git clone https://github.com/me3-eth/contracts.git me3-eth-contracts
    cd me3-eth-contracts
  2. Optional: set node version with NVM
    nvm use
  3. Install dependencies
    npm install
  4. Create environment file
    touch .env
  5. Fill in environment value with template and your data
    # Template env file
    ALCHEMY_API_KEY=
    ENS_REGISTRY=0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
    WALLET_PK_ROPSTEN=
    COINMARKETCAP_API_KEY=

Deploy

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 ropsten

Local deployments will also deploy all of the necessary ENS contracts.

SiteManager

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.

SiteManager regstrar flow showing how the contract interacts with ENS registry and resolver

Usage

subdomainRegister

Current gas usage: 88247-880992

Signature:

function subdomainRegister (bytes32 label, bytes[] calldata data) external returns (bytes[] memory results);
  • label is the subdomain to be registered. For example, if the root domain is help.eth and the label is no then the subdomain will be no.help.eth.
  • data is 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 that multicall will 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

SiteManagerLite is a limited version of SiteManager. It:

  • registers a subdomain
  • sets a contenthash
  • transfers ownership from the SiteManagerLite contract to the requestor

Usage

subdomainRegister

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

Testing is done with hardhat:

npx hardhat test

About

Collection of contracts that power me3.eth

Resources

License

Stars

Watchers

Forks

Releases

No releases published