> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Get Primary Name \[ens.getName]

Gets the primary ENS name for an address (via the ENS Universal Resolver's `reverseWithGateways`).

## Usage

This example gets the primary ENS name for an address (via the ENS Universal Resolver's `reverseWithGateways`).

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const name = await client.ens.getName({
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
// @log: 'wevm.eth'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

### Standalone Action

Call `Actions.ens.getName` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const name = await Actions.ens.getName(client, {
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
// @log: 'wevm.eth'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Recipes

### Resolve a Historical Name Strictly

Set a block number to resolve from historical state. Enable strict mode to surface Universal Resolver failures instead of returning `null`.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const name = await client.ens.getName({
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  blockNumber: 23_085_558n, // [!code focus]
  strict: true, // [!code focus]
})
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

## Return Value

`string | null`

The primary ENS name, or `null` when the address has no reverse record.

## Parameters

### address

* **Type:** `Address`

The address to reverse-resolve.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B', // [!code focus]
})
```

### blockNumber

* **Type:** `bigint`

Resolves against the state at a given block number.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  blockNumber: 23_085_558n, // [!code focus]
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
```

### blockTag

* **Type:** `'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'`
* **Default:** `'latest'`

Resolves against the state at a given block tag.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  blockTag: 'finalized', // [!code focus]
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
```

### coinType

* **Type:** `bigint`
* **Default:** `60n` (ETH)

The [ENSIP-9](https://docs.ens.domains/ensip/9) coin type of the reverse record to resolve.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { base, mainnet } from 'viem/chains'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  coinType: Ens.toCoinType(BigInt(base.id)), // [!code focus]
})
```

### gatewayUrls

* **Type:** `readonly string[]`

Universal Resolver gateway URLs for CCIP-read requests. Defaults to the client-side batch gateway.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  gatewayUrls: ['https://ccip.ens.xyz'], // [!code focus]
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
```

### strict

* **Type:** `boolean`
* **Default:** `false`

Whether to throw errors propagated from the Universal Resolver instead of returning `null`.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  strict: true, // [!code focus]
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
```

### universalResolverAddress

* **Type:** `Address`
* **Default:** `client.chain.contracts.ensUniversalResolver.address`

Address of the ENS Universal Resolver contract.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const name = await Actions.ens.getName(client, {
  universalResolverAddress: '0xeeeeeeee14d718c2b47d9923deab1335e144eeee', // [!code focus]
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
})
```

## Errors

| Error | Description |
| --- | --- |
| `ContractError.ContractFunctionExecutionError` | The Universal Resolver call failed (with [`strict`](#strict); resolver errors otherwise map to `null`). |
