NNS Documents
  • 👋Welcome !
  • 📕Overview
    • Introduction
    • Roadmap
    • Incentives
    • Terminology
  • 🕹️Using NNS
    • Name Manager App
      • Registering new name
      • Manage names
      • Primary name
      • Avatar
      • Text records
      • NadCard
      • Discord profile sync
  • 💻Developers
    • Integrating into your dapps
      • Name processing
      • Query contract directly
      • Using NNS SDKs
      • Using REST APIs
      • Using NNS Adapter (soon)
    • Contracts
      • Contract addresses
      • Contract ABI
  • 📦Others
    • Contact
    • FAQs
Powered by GitBook
On this page
  • Name normalization
  • Namehash
  1. Developers
  2. Integrating into your dapps

Name processing

When interacting with Nad Name Service smart-contracts directly, note that names are not stored in their human readable format. We must process the name before it can be used by a smart-contract by execute below steps in order:

  • Name normalization

  • Name hash

Name normalization

Normalization is the process of standardizing a name before passing it through the Namehash algorithm. It's crucial to normalize all input consistently, as even a small variation, such as a difference between uppercase and lowercase letters, can result in a completely different namehash.

For example, Salmo.Nad normalizes to salmo.nad. This ensures that no matter how the user types in the name, the correct node is used.

Using viem:

import { normalize } from 'viem/ens'

const normalizedName = normalize('Salmo.Nad') 
// => salmo.nad

Using ethersjs(v6):

import { ensNormalize, namehash } from "ethers/hash";

const normalizedName = ensNormalize('Salmo.Nad')
// => salmo.nad

Namehash

You must normalize names before creating a namehash.

Using viem:

import { namehash, normalize } from "viem/ens";

const normalizedName = normalize('salmo.nad');
const node = namehash(normalizedName);

Using ethersjs(v6):

import { ensNormalize, namehash } from "ethers/hash";

const normalizedName = ensNormalize('salmo.nad')
const node = namehash(normalizedName)

PreviousIntegrating into your dappsNextQuery contract directly

Last updated 4 months ago

In NNS core smart-contracts, names are stored as a hash instead of the raw string for optimization purpose. The hashed value is called a node , which is a hex-encoded 32-byte value that is derived from the name using the namehash algorithm from ENS .

💻
ENSIP-1