Skip to content
On this page

getEnsText โ€‹

Gets a text record for specified ENS name.

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', 
})

Released under the MIT License.