getEnsAvatar
Gets the avatar of an ENS name.
Calls getEnsText
with key
set to 'avatar'
.
Usage
example.ts
import { normalize } from 'viem/ens'
import { publicClient } from './client'
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
})
// 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
Returns
string | null
The avatar URI for ENS name.
Returns null
if the avatar cannot be resolved from the ENS name.
Parameters
name
- Type:
string
ENS name to get Text for.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
})
assetGatewayUrls (optional)
- Type:
{ ipfs?: string; arweave?: string }
Gateway urls to resolve IPFS and/or Arweave assets.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
assetGatewayUrls: {
ipfs: 'https://cloudflare-ipfs.com'
}
})
blockNumber (optional)
- Type:
number
The block number to perform the read against.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
blockNumber: 15121123n,
})
blockTag (optional)
- Type:
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
- Default:
'latest'
The block tag to perform the read against.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
blockTag: 'safe',
})
gatewayUrls (optional)
- Type:
string[]
A set of Universal Resolver gateways, used for resolving CCIP-Read requests made through the ENS Universal Resolver Contract.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
gatewayUrls: ["https://ccip.ens.xyz"],
})
strict (optional)
- Type:
boolean
- Default:
false
A boolean value that when set to true will strictly propagate all ENS Universal Resolver Contract errors.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
strict: true,
})
universalResolverAddress (optional)
- Type:
Address
- Default:
client.chain.contracts.ensUniversalResolver.address
Address of ENS Universal Resolver Contract.
const ensText = await publicClient.getEnsAvatar({
name: normalize('wevm.eth'),
universalResolverAddress: '0x74E20Bd2A1fE0cdbe45b9A1d89cb7e0a45b36376',
})