LogoLogo
  • Introduction
    • Terminology
  • Frequently Asked Questions
  • Domains Deployments
  • Registrar Frequently Asked Questions
  • Deploying Domains on a Private Chain
  • DNS Registrar guide
  • Domains Improvement Proposals
    • DomainsIP-1: Domains
    • DomainsIP-2: Initial Hash Registrar
    • DomainsIP-3: Reverse Resolution
    • DomainsIP-4: Support for contract ABIs
    • DomainsIP-5: Text Records
    • DomainsIP-6: DNS-in-Domains
    • DomainsIP-7: Interface Discovery
    • DomainsIP-8: Multichain Address Resolution
    • DomainsIP-9: Wildcard Resolution
    • DomainsIP-10: EVM compatible Chain Address Resolution
    • DomainsIP-11: Avatar Text Records
    • DomainsIP-12: SAFE Authentication for Domains
    • DomainsIP-13: On-chain Source Parameter
  • DAPP DEVELOPER GUIDE
    • Domains Enabling your DApp
    • Domains Libraries
    • Working with Domains
    • Resolving Names
    • Managing Names
    • Registering & Renewing Names
    • Domains Front-End Design Guidelines
    • Domains AS NFT
    • Domains Layer2 and offchain data support
    • Domains Data guide
  • CONTRACT API REFERENCE
    • Name Processing
  • Registry
  • ReverseRegistrar
  • TestRegistrar
  • PublicResolver
  • .tomi Permanent Registrar
    • Registrar
    • Controller
  • DNS Registrar
  • Subgraph
    • Query Examples
  • CONTRACT DEVELOPER GUIDE
    • Resolving Names On-chain
    • Writing a Resolver
    • Writing a Registrar
    • TOMI DISCUSSION FORUM
    • TOMI SUPPORT CHAT
  • TOMI MIGRATION (FEBRUARY 2020)
    • Guide for DApp Developers
    • Technical Description
Powered by GitBook
On this page
  • Deriving tokenId from Domains name
  • Deriving Domains name from tokenId
  • Turning subdomain into NFT
  • Metadata
  1. DAPP DEVELOPER GUIDE

Domains AS NFT

PreviousDomains Front-End Design GuidelinesNextDomains Layer2 and offchain data support

Last updated 1 year ago

When Domains .tomi registrar migrated in May 2022, the .tomi registrar became an ERC721 compliant non-fungible token contract, meaning that .tomi registrations can be transferred in the same fashion as other NFTs.

Deriving tokenId from Domains name

The tokenId of Domains name is simply the uint256 representation of the hash of the label (xyzfor xyz.tomi).

const ethers = require('ethers')
const BigNumber = ethers.BigNumber
const utils = ethers.utils
const name = 'xyz'
const labelHash = utils.keccak256(utils.toUtf8Bytes(name))
const tokenId = BigNumber.from(labelHash).toString()

In the example above, is the tokenId of xyz.tomi

Deriving Domains name from tokenId

Unlike deriving tokenId, deriving Domains name from tokenId is not as easy. This is because all Domains names are stored as fixed-length hash to allow registering infinite length of names. The downside of this architecture is that you cannot directly query Domains smart contracts to return Domains name using tokenId.

Our recommended way is to query via Domains subgraph. The graph decodes the hash to name as it indexes. The example code to query is as follows.

const ethers = require('ethers')
const BigNumber = ethers.BigNumber
const gr = require('graphql-request')
const { request, gql } = gr
const tokenId = '79233663829379634837589865448569342784712482819484549289560981379859480642508'
// Should return 0xaf2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103cc
const labelHash = BigNumber.from(tokenId).toHexString()

const url = 'https://api.thegraph.com/subgraphs/name/tdnsdomains/tdns'
const GET_LABEL_NAME = gql`
query{
  domains(first:1, where:{labelhash:"${labelHash}"}){
    labelName
  }
}`

request(url, GET_LABEL_NAME).then((data) => console.log(data))
// { domains: [ { labelName: 'vitalik' } ] }

If you prefer not to rely on a third party like TheGraph, the team open-sourced tdns-rainbow containing a link to the original dataset (6GB with 133 million entities) so that you can host your own Domains name decoding service.

Turning subdomain into NFT

Currently, all the subdomains nor non .tomi domains are not NFT, unless the domain registrar itself supports NFT such as (dcl.tomi, and .kred). If you want to turn all subdomains which you own, you have to create a registrar

  1. Create a registrar contract as ERC721 compliant

  2. Set Domains registry address (mostly when you deploy the registrar)

  3. Create register function which calls registry.setSubnodeOwner then mint the token making the subdomain label hash as tokenId

contract DCLRegistrar is ERC721Full, Ownable {
    constructor(
        ITDNSRegistry _registry,
    ) public ERC721Full("DCL Registrar", "DCLENS") {
        // tDNS registry
        updateRegistry(_registry);
    }

    function register(
        string memory _subdomain,
        bytes32 subdomainLabelHash,
        address _beneficiary,
        uint256 _createdDate
    ) internal {
        // Create new subdomain and assign the _beneficiary as the owner
        registry.setSubnodeOwner(domainNameHash, subdomainLabelHash, _beneficiary);
        // Mint an ERC721 token with the subdomain label hash as its id
        _mint(_beneficiary, uint256(subdomainLabelHash));
    }
}

Once deployed, then you have to transfer the controller address to the contract.

For non-technical users, we are currently working on upgrading our SubdomainRegistrar which allows you to turn your subdomain into NFT without any coding.

Metadata

.tomi does not have .tokenURI . However, we created a separate metadata service which NFT marketplaces like OpenSea can fetch metadata for tDNS such as registration data, expiration date, name length, etc. For more detail, please refer to the metadata documentation site.

79233663829379634837589865448569342784712482819484549289560981379859480642508
https://thegraph.com