# Resolve ENS Names

## Overview

[`Ens`](/api/Ens) provides the local primitives of ENS resolution: normalizing names, hashing
them into registry keys, and computing multichain coin types. The onchain half — querying the
registry and resolver contracts — needs a transport or client; for a batteries-included flow, use
[Viem's ENS actions](https://viem.sh/docs/ens/actions/getEnsAddress).

## Recipes

### Normalize a Name

User input must be normalized per [ENSIP-15](https://docs.ens.domains/ensip/15) before hashing or
display. [`Ens.normalize`](/api/Ens/normalize) applies UTS-46 normalization and throws on
disallowed characters.

```ts twoslash
import { Ens } from 'ox'

const name = Ens.normalize('WEVM.eth')
// @log: 'wevm.eth'
```

### Compute Namehash & Labelhash

[`Ens.namehash`](/api/Ens/namehash) hashes a full name into the node used as the key of the ENS
registry; [`Ens.labelhash`](/api/Ens/labelhash) hashes a single label (e.g. for registrar token
IDs).

```ts twoslash
import { Ens } from 'ox'

const node = Ens.namehash('wevm.eth')
// @log: '0x08c85f2f4059e930c45a6aeff9dcd3bd95dc3c5c1cddef6a0626b31152248560'

const label = Ens.labelhash('wevm')
// @log: '0xcca19c3b64f2cbc38b510a15f4c577cb455225ed774a1e100cd539af6d3f2eb7'
```

Pass the `namehash` output to registry and resolver calls such as `resolver(bytes32)` and
`addr(bytes32)`.

### Coin Types for Multichain Addresses

Multichain resolvers key addresses by [ENSIP-11](https://docs.ens.domains/ensip/11) coin type.
[`Ens.toCoinType`](/api/Ens/toCoinType) converts an EVM chain ID into its coin type.

```ts twoslash
import { Ens } from 'ox'

const coinType = Ens.toCoinType(10n)
// @log: 2147483658n

const mainnet = Ens.toCoinType(1n)
// @log: 60n
```

Mainnet maps to the SLIP-44 Ether coin type (`60`); other EVM chains set the most significant
bit over their chain ID.

## Best Practices

### Normalize Before Hashing

`namehash` and `labelhash` operate on raw strings — hashing an unnormalized name produces a
different node than wallets and resolvers expect. Run every user-supplied name through
`Ens.normalize` first.

### Never Trust a Name Without Forward Resolution

When displaying a reverse-resolved name, resolve it forward again and check that it maps back to
the original address before treating the name as verified.

## See More

<Cards>
  <Card icon="lucide:wallet" title="Derive & Validate Addresses" description="Checksum and validate the addresses that names resolve to." to="/guides/accounts/addresses" />

  <Card icon="lucide:hash" title="Hash Data" description="The keccak256 hashing that powers namehash and labelhash." to="/guides/crypto/hashing" />

  <Card icon="lucide:network" title="Send JSON-RPC Requests" description="Call registry and resolver contracts over raw JSON-RPC." to="/guides/rpc/requests" />
</Cards>
