Defichain Domain as NFT

Defichain Domains are ERC721 compliant non-fungible tokens, meaning that .dfi domains can be transferred in the same fashion as other NFTs.

Deriving tokenId from Defichain Domain name

The tokenId of Defichain Domain name is simply the uint256 representation of the hash of the label (stefano for stefano.dfi).

const ethers = require("ethers");
const BigNumber = ethers.BigNumber;
const utils = ethers.utils;
const name = "stefano";
const labelHash = utils.keccak256(utils.toUtf8Bytes(name));
const tokenId = BigNumber.from(labelHash).toString();

In the example above, 41131809834712302827435754041642146671014829310876022445023625856466056975581 is the tokenId of stefano.dfi

Deriving Defichain Domain name from tokenId

Unlike deriving tokenId, deriving Defichain Domain name from tokenId is not as easy. This is because all Defichain Domain 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 Defichain Domain smart contracts to return Defichain Domain name using tokenId.

Our recommended way is to query via Defichain Domain 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 =
// Should return 0xaf2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103cc
const labelHash = BigNumber.from(tokenId).toHexString();

const url =""
const GET_LABEL_NAME = gql`
  domains(first:1, where:{labelhash:"${labelHash}"}){

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

NFT Subdomain NFT

Currently, all the subdomains are not NFTs.


.dfi does not have .tokenURI . However, we created a separate metadata service which NFT marketplaces can fetch metadata for Defichain Domain such as registration data, name length, etc.

Last updated