getEnsText
Gets a text record for specified ENS name.
Calls resolve(bytes, bytes)
on ENS Universal Resolver Contract.
Usage
ts
import { normalize } from 'viem/ens'
import { publicClient } from './client'
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
})
// 'wagmi_sh'
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
WARNING
Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress
. You can use the built-in normalize
function for this.
Returns
string | null
The text record for ENS name.
Returns null
if name does not have text assigned.
Parameters
name
- Type:
string
ENS name to get Text for.
ts
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
})
key
- Type:
string
ENS key to get Text for.
ts
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
})
blockNumber (optional)
- Type:
number
The block number to perform the read against.
ts
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
blockNumber: 15121123n,
})
blockTag (optional)
- Type:
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
- Default:
'latest'
The block tag to perform the read against.
ts
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
blockTag: 'safe',
})
universalResolverAddress (optional)
- Type:
Address
- Default:
client.chain.contracts.ensUniversalResolver.address
Address of ENS Universal Resolver Contract.
ts
const ensText = await publicClient.getEnsText({
name: normalize('wagmi-dev.eth'),
key: 'com.twitter',
universalResolverAddress: '0x74E20Bd2A1fE0cdbe45b9A1d89cb7e0a45b36376',
})