> **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 Avatar \[ens.getAvatar]

Gets the avatar image URI for an ENS name.

Resolves the `avatar` text record, including [CAIP-22/CAIP-29](https://github.com/ChainAgnostic/CAIPs) NFT records. Viem fetches the NFT token URI and metadata when required.

Viem converts IPFS and Arweave URIs to gateway URLs. Unresolvable or invalid records return `null`.

## Usage

This example gets the avatar image URI for an ENS name.

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

const avatar = await client.ens.getAvatar({
  name: Ens.normalize('wevm.eth'),
})
// @log: 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
```

```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.getAvatar` directly by passing the Client as the first argument.

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

const avatar = await Actions.ens.getAvatar(client, {
  name: Ens.normalize('wevm.eth'),
})
// @log: 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
```

```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

### Use Custom Avatar Gateways

Set `gatewayUrls` for CCIP Read and `assetGatewayUrls` for the resolved IPFS or Arweave asset.

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

const avatar = await client.ens.getAvatar({
  assetGatewayUrls: { ipfs: 'https://cloudflare-ipfs.com' }, // [!code focus]
  gatewayUrls: ['https://ccip.ens.xyz'], // [!code focus]
  name: Ens.normalize('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())
```
:::

## Return Value

`string | null`

The avatar image URI, or `null` when the name has no `avatar` record or the record cannot be resolved to a valid image.

## Parameters

### assetGatewayUrls

* **Type:** `{ ipfs?: string; arweave?: string }`

Gateway URL overrides for resolving offchain asset URIs.

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

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  assetGatewayUrls: { ipfs: 'https://cloudflare-ipfs.com' }, // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

### 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'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  blockNumber: 23_085_558n, // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

### 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'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  blockTag: 'finalized', // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

### 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'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  gatewayUrls: ['https://ccip.ens.xyz'], // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

### name

* **Type:** `string`

The ENS name to resolve.

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

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  name: Ens.normalize('wevm.eth'), // [!code focus]
})
```

### 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'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  strict: true, // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

### 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'
import { Ens } from 'viem/utils'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const avatar = await Actions.ens.getAvatar(client, {
  universalResolverAddress: '0xeeeeeeee14d718c2b47d9923deab1335e144eeee', // [!code focus]
  name: Ens.normalize('wevm.eth'),
})
```

## Errors

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