Registration Integration

Currently, SPACE ID provides an easy way for partners to integrate .bnb, .arb, and .eth domain name registrations. Partners can use our web3-name-sdk with their own designed front-end interfaces to allow their customers to smoothly own a unique web3 domain name. Additionally, qualified partners can also earn commission fees when users register .arb and .bnb domains on their own integrated registration portal.

Installation

Use npm or yarn to install our web3-name-sdk along with ethers v5. Ethers v6 has breaking changes and it has not been widely adopted so far. Therefore, we choose to stick with ethers v5.

npm install @web3-name-sdk/register ethers@5.7.2
yarn add @web3-name-sdk/register ethers@5.7.2

If you are using next.js, please add the following configuration in your next.config.js in order to transpile commonjs dependencies:

const nextConfig = {
  transpilePackages: ['@web3-name-sdk/register'],
}

Registration Steps

Domain registration has 3 steps. The first step is to check the availability of a specific domain. If the domain is valid and available, the second step would be querying the registration fee of the domain. The fee depends on the length and registration duration of a domain. The third step is to let users call the registration function with all the necessary parameters and registration fees.

Code Examples

BNB Registration

import SIDRegister from ‘@web3-name-sdk/register’
import { providers } from ‘ethers’

async function registerDomain(label: String) {
  // detect provider
  if (window.ethereum) {
    const provider = new providers.Web3Provider(window.ethereum)
    // switch to bsc
    await provider.send('wallet_switchEthereumChain', [{ chainId: '0x38' }])
    // connect wallet
    await provider.send('eth_requestAccounts', [])
    // get signer
    const signer = provider.getSigner()
    // get address
    const address = await signer.getAddress()
    // init SIDRegister
    const register = new SIDRegister({ signer, chainId: 56 })
    // check if available
    const available = await register.getAvailable(label)
    // get price. params:{label, duration}
    const price = await register.getRentPrice(label, 1)
    // register for one year. params:{label, address, duration, {setPrimaryName, referrer}}
    await register.register(label, address, 1, {
      setPrimaryName: true, // set as primary name, default is false,
      referrer: 'test.bnb' // referrer domain, default is null
    })
  }
}

ARB Registration

import SIDRegister from '@web3-name-sdk/register'
import { providers } from 'ethers'

async function registerDomain(label: String) {
  // detect provider
  if (window.ethereum) {
    const provider = new providers.Web3Provider(window.ethereum)
    // switch to arbitrum one
    await provider.send('wallet_switchEthereumChain', [{ chainId: '0xA4B1' }])
    // connect wallet
    await provider.send('eth_requestAccounts', [])
    // get signer
    const signer = provider.getSigner()
    // get address
    const address = await signer.getAddress()
    // init SIDRegister
    const register = new SIDRegister({ signer, chainId: 42161 })
    // check if available
    const available = await register.getAvailable(label)
    // get price
    const price = await register.getRentPrice(label, 1, {
      setPrimaryName: true, // set as primary name, default is false,
      referrer: 'test.bnb' // referrer domain, default is null
    })
    // register for one year
    await register.register(label, address, 1)
  }
}

*Notice:

  • Label is the domain name without TLD subfix.(eg: test is the label of domain test.bnb)

  • ARB chain id is 42161, BNB chain id is 56.

  • Primary Name is the name that will be displayed on the front end for any dapp that integrates our name-resolving SDK. setPrimaryName can be passed as a parameter as new users register domain. Its default value should be set to false.

  • Referrer is the referrer's domain name. The commission fee will be sent to the address that this domain name resolves to. Be sure to set up both the primary name and resolving address before using the domain as the referrer.

ETH Registraion

import SIDRegister from '@web3-name-sdk/register'
import { providers } from 'ethers'

async function registerEthDomain(label: String) {
  // detect provider
  if (window.ethereum) {
    const provider = new providers.Web3Provider(window.ethereum)
    // switch to bsc
    await provider.send('wallet_switchEthereumChain', [{ chainId: '0x1' }])
    // connect wallet
    await provider.send('eth_requestAccounts', [])
    // get signer
    const signer = provider.getSigner()
    // get address
    const address = await signer.getAddress()
    // init SIDRegister
    const register = new SIDRegister({ signer, chainId: 1 })
    // check if available
    const available = await register.getAvailable(label)
    // get price
    const price = await register.getRentPrice(label, 1)
    // register for one year
    await register.register(label, address, 1, {
      // wait for commit to be valid, waitTime = 60 in milliseconds
      onCommitSuccess: (waitTime) => {
        return new Promise(resolve => {
          setTimeout(resolve, waitTime * 1000)
        })
      }
    })
  }
}

*Notice:

  • Label is the domain name without TLD subfix.(eg: test is the label of domain test.bnb).

  • ETH chain id is 1.

  • Referrer cannot be applied to eth registration and SetPrimaryName does not apply either.

  • ETH Registration has one additional step. Users need to commit a message before registering domains. Our SDK has wrapped these two steps into a callback function. Once the first function call is successful, the function has to wait 60 seconds to make the callback.

More details can be referred from https://www.npmjs.com/package/@web3-name-sdk/register

Last updated