> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# ENS Encoding

> ENS name hashing and encoding operations (namehash, labelhash)

> [card] [Try it Live](https://playground.tevm.sh?example=primitives/ens.ts)
>
> Run ENS examples in the interactive playground

# ENS Encoding

Cryptographic operations for ENS names implementing EIP-137 name hashing.

## Functions

### namehash(name)

Compute ENS namehash for a given name.

**Algorithm:** `namehash(name) = keccak256(namehash(parent) ‖ labelhash(label))`

Empty string has hash of 32 zero bytes.

> [tab] Functional API
>
> ```typescript theme={null}
> import { namehash } from '@tevm/voltaire/Ens';
>
> const hash = namehash("vitalik.eth");
> // Returns: "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
>
> // Empty name returns root hash
> const root = namehash("");
> // Returns: "0x0000000000000000000000000000000000000000000000000000000000000000"
>
> // Subdomain support
> const subhash = namehash("sub.vitalik.eth");
> ```

> [tab] Factory API
>
> ```typescript theme={null}
> import { Namehash } from '@tevm/voltaire/Ens';
> import { hash as keccak256 } from '@tevm/voltaire/Keccak256';
>
> const namehash = Namehash({ keccak256 });
>
> const hash = namehash("vitalik.eth");
> // Returns: "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835"
> ```
>
> **Tree-shakeable:** Crypto only included if you import it.
>
> **Dependencies:**
>
> * `keccak256: (data: Uint8Array) => Uint8Array` - Keccak256 hash function

### labelhash(label)

Compute ENS labelhash for a single label.

**Algorithm:** `labelhash(label) = keccak256(label)`

> [tab] Functional API
>
> ```typescript theme={null}
> import { labelhash } from '@tevm/voltaire/Ens';
>
> const hash = labelhash("vitalik");
> // Returns: "0xaf2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103cc"
>
> const ethHash = labelhash("eth");
> ```

> [tab] Factory API
>
> ```typescript theme={null}
> import { Labelhash } from '@tevm/voltaire/Ens';
> import { hash as keccak256 } from '@tevm/voltaire/Keccak256';
>
> const labelhash = Labelhash({ keccak256 });
>
> const hash = labelhash("vitalik");
> // Returns: "0xaf2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103cc"
> ```
>
> **Tree-shakeable:** Crypto only included if you import it.
>
> **Dependencies:**
>
> * `keccak256: (data: Uint8Array) => Uint8Array` - Keccak256 hash function

## Algorithm Details

### Namehash Recursion

```typescript theme={null}
namehash('') = 0x0000000000000000000000000000000000000000000000000000000000000000
namehash('eth') = keccak256(namehash('') ‖ labelhash('eth'))
namehash('vitalik.eth') = keccak256(namehash('eth') ‖ labelhash('vitalik'))
```

Process labels in **reverse order** (right-to-left).

### Bundle Size

Factory pattern enables tree-shaking:

* Functional API: \~15KB (includes keccak256)
* Factory API with custom crypto: Depends on your keccak256 implementation

## See Also

* [ENS Overview](https://voltaire.tevm.sh/primitives/ens.md)
* [ENS Normalization](https://voltaire.tevm.sh/primitives/ens/normalization.md)
* [EIP-137](https://eips.ethereum.org/EIPS/eip-137) - ENS name hash specification


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.