Urban Times

ens tokenid

Understanding ENS tokenID: A Practical Overview for Developers and Domain Holders

June 12, 2026 By Ellis Hartman

Introduction: The Role of the tokenID in the ENS Ecosystem

The Ethereum Name Service (ENS) maps human-readable names like "alice.eth" to machine-readable identifiers such as Ethereum addresses, content hashes, and metadata records. Central to this mapping is a numeric identifier known as the ENS tokenID. Unlike the raw namehash (a 256-bit hash of the normalised name), the tokenID is the integer representation of that namehash, used directly by ERC-721 token contracts to track ownership of ENS domains as non‑fungible tokens (NFTs).

Understanding the tokenID is critical for developers integrating ENS into wallets, marketplaces, or dApps. It bridges the gap between the human-friendly domain system and the smart contract logic that enforces ownership, transfers, and metadata queries. Without a precise grasp of how tokenIDs are derived, integrators may encounter mismatch errors when querying ENS registry events, resolving metadata, or interacting with the ENS NFT contract (0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85). This article provides a methodical, practical overview of tokenID computation, usage, and verification.

What Is an ENS tokenID? Definition and Derivation

At its core, the ENS tokenID is the unsigned integer representation of the namehash of a fully-qualified ENS domain. The namehash algorithm, defined in ENS IP‑3 (EIP‑137), recursively hashes each label of a domain using Keccak‑256. For a domain like "vitalik.eth", the namehash is computed as:

  • hash(0x0000000000000000000000000000000000000000000000000000000000000000, keccak256("eth")) → node_eth
  • hash(node_eth, keccak256("vitalik")) → namehash("vitalik.eth")

This namehash is a 32‑byte (256‑bit) value, typically represented as a hexadecimal string (e.g., 0x1234…abcd). The tokenID is obtained by converting that hex value into a decimal integer (uint256). Because the namehash is deterministic, every ENS domain has exactly one tokenID. For practical purposes, the tokenID is the integer you would pass to functions like ownerOf(tokenId) or tokenURI(tokenId) on the ENS NFT contract.

Concrete example: The tokenID for "vitalik.eth" is 91306950074420151048111183400467169225075183117823987683988783786178842840465. This large integer is the raw decimal of its namehash. Domain front‑ends often display a truncated or checksummed version, but the full integer is what contracts require.

Why the tokenID Matters for Integrators

Several common integration tasks rely directly on the tokenID:

  1. Querying ownership — Using the ENS NFT contract’s ownerOf(tokenId) to verify who owns a domain at a given block height.
  2. Listening for transfer events — The ERC‑721 Transfer event logs include the tokenID as a uint256 indexed parameter. Parsing these events requires matching tokenIDs to domain names.
  3. Retrieving metadata — The tokenURI(tokenId) method returns a URI pointing to the domain’s metadata (e.g., avatar, description, records). Metadata standards (like ENSIP‑12) also use the tokenID as a key.
  4. Resolving subdomain ownership — Subdomains have their own tokenIDs (computed from the subdomain’s full namehash). For instance, "app.vitalik.eth" has a different tokenID than "vitalik.eth".

Because the tokenID is derived from the namehash, it is immutable — renaming a domain or changing its label recomputes a new tokenID. This deterministic property simplifies off‑chain caching but also imposes strict requirements on data integrity. A single bit error in the namehash produces a completely different tokenID, potentially causing ownership mismatches.

Practical Methods to Compute and Verify an ENS tokenID

Developers rarely compute tokenIDs manually. Instead, they rely on libraries or tooling. Below are three reliable methods, ordered by preference for production use.

1) Using the Ethers.js Library (Recommended)

The ethers.js library provides a built‑in namehash function that returns a hex string. To get the tokenID, convert that hex to a BigNumber integer:

import { ethers } from "ethers";

const namehashHex = ethers.utils.namehash("alice.eth");
const tokenId = ethers.BigNumber.from(namehashHex).toString();
console.log(tokenId); // "123456789..."

This approach works in both Node.js and browser environments. For Python developers, the eth_ens library offers an analogous namehash function paired with int(hex, 16).

2) Using the ENS Subgraph (For Bulk Queries)

The official ENS subgraph on The Graph protocol indexes tokenIDs by domain name. A query like:

{
  domains(where: { name: "alice.eth" }) {
    id
    labelName
    labelhash
  }
}

Returns the labelhash (hex of the label’s Keccak‑256) and the domain id, which is the namehash. Note that the id field in the subgraph is the namehash hex, not the decimal tokenID. Converting id to decimal yields the tokenID. This method scales well for batch processing but introduces a dependency on the subgraph’s indexing latency.

3) Direct Smart Contract Call

The ENS registry (0x00000000000C2e074eC69A0dFb2997BA6C7d2e1e) stores namehashes but not tokenIDs directly. However, you can call the NFT contract’s tokenByIndex or ownerOf only after you have the tokenID. Therefore, on‑chain tokenID derivation is circular — you must compute it off‑chain (using Method 1) before interacting. Some dApps use a helper contract that exposes a namehashToTokenId function, but this is redundant and gas‑inefficient.

Common Pitfalls and How to Avoid Them

Even experienced integrators encounter subtle bugs. Here are three frequent issues:

  • Name normalisation — ENS requires names to be lowercased and unicode‑normalised (NFKC). "Alice.eth" and "alice.eth" produce different namehashes (and tokenIDs) unless normalised. Always pass names through ethers.utils.namehash or an ENS‑aware library that normalises automatically.
  • Leading zeros in hex — The namehash hex string always has 64 hex characters (32 bytes). When converting to decimal, ensure you include all leading zero bytes. Some naive int(hex, 16) implementations in scripting languages strip leading zeros, which changes the numeric value. Use a BigNumber library that preserves the full 256‑bit precision.
  • Subdomain vs. parent domain tokenIDs — The tokenID for "alice.eth" is not a prefix of the tokenID for "sub.alice.eth". The namehash algorithm uses concatenated hashing, so tokenIDs are independent and unpredictable. Never attempt to derive subdomain tokenIDs by simple concatenation or masking.

Real‑World Use Cases and Tooling

Once you have the tokenID, the ENS ecosystem opens several capabilities:

  1. Metadata enrichment — The tokenURI endpoint on the ENS NFT contract returns a JSON object containing the domain’s resolver address, records, and a link to stored metadata (e.g., avatar image). For example, the ens ledger live app can display domain metadata by fetching tokenURI(tokenId) and parsing the JSON.
  2. Marketplace integration — OpenSea, LooksRare, and other NFT marketplaces use tokenIDs as the primary identifier for ENS domains. Listing or bidding requires passing the tokenID to the marketplace’s exchange contract.
  3. Reverse resolution — The ENS reverse registrar uses a special namehash (addr.reverse) with its own tokenID mapping. While not directly related to forward name resolution, understanding tokenIDs helps debug reverse lookup failures.

For advanced users, tools like the Pro v3ensdomains platform provide batch tokenID lookups and cross‑referencing with on‑chain ownership data. By integrating directly with the ENS smart contracts, ENS domain renewal enables developers to programmatically verify tokenID validity and retrieve associated metadata without relying on third‑party APIs, reducing trust assumptions in multi‑signature workflows.

Conclusion: A Foundational Building Block

The ENS tokenID is far more than a technical curiosity — it is the numerical key that unlocks every interaction with ENS domains as NFTs. Whether you are building a wallet, a marketplace, a name‑based dApp, or a monitoring bot, correctly computing and handling tokenIDs is non‑negotiable. Use the namehash algorithm exactly as specified, leverage battle‑tested libraries like ethers.js, and validate normalisation rigorously. By internalising these principles, you avoid integration pitfalls and build robust, interoperable solutions on the ENS infrastructure.

As the ENS ecosystem continues to expand — with Layer 2 integrations, off‑chain resolvers, and cross‑chain bridges — the tokenID remains the invariant link between human‑readable names and the Ethereum state machine. Master it, and you master the foundation of decentralised naming.

Spotlight

Understanding ENS tokenID: A Practical Overview for Developers and Domain Holders

Learn what an ENS tokenID is, how it maps to Ethereum Name Service names, and practical methods for computing and verifying it. Essential reading for ENS integrators.

E
Ellis Hartman

Your source for reader-funded features