or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

account-chain-state.mdadvanced-features.mdblockchain-data-reading.mdconfiguration.mdconnection-management.mdcontract-interactions.mdens-operations.mdevent-watching.mdindex.mdsigning-verification.mdtanstack-query.mdtransaction-management.md

ens-operations.mddocs/

0

# ENS Operations

1

2

Ethereum Name Service resolution, reverse resolution, and metadata retrieval. Complete ENS integration.

3

4

## Capabilities

5

6

### Resolve ENS Name to Address

7

8

Resolves ENS names to Ethereum addresses.

9

10

```typescript { .api }

11

/**

12

* Resolves ENS name to address

13

* @param config - Wagmi configuration

14

* @param parameters - ENS address resolution parameters

15

* @returns Resolved address or null

16

*/

17

function getEnsAddress<config extends Config>(

18

config: config,

19

parameters: GetEnsAddressParameters<config>

20

): Promise<GetEnsAddressReturnType>;

21

22

interface GetEnsAddressParameters<config extends Config> {

23

/** ENS name to resolve */

24

name: string;

25

/** Chain ID (defaults to mainnet) */

26

chainId?: config['chains'][number]['id'];

27

/** Block number to query at */

28

blockNumber?: bigint;

29

/** Block tag */

30

blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';

31

/** Universal resolver address */

32

universalResolverAddress?: Address;

33

}

34

35

type GetEnsAddressReturnType = Address | null;

36

37

type GetEnsAddressErrorType = BaseErrorType;

38

39

/** @deprecated Use getEnsAddress instead */

40

const fetchEnsAddress = getEnsAddress;

41

```

42

43

**Usage Example:**

44

45

```typescript

46

import { getEnsAddress } from '@wagmi/core'

47

48

const address = await getEnsAddress(config, {

49

name: 'vitalik.eth',

50

})

51

console.log('vitalik.eth resolves to:', address)

52

53

// Handle null result

54

if (address) {

55

console.log('Resolved address:', address)

56

} else {

57

console.log('ENS name not found')

58

}

59

```

60

61

### Reverse Resolve Address to ENS Name

62

63

Performs reverse ENS resolution to get name from address.

64

65

```typescript { .api }

66

/**

67

* Reverse resolves address to ENS name

68

* @param config - Wagmi configuration

69

* @param parameters - ENS name resolution parameters

70

* @returns ENS name or null

71

*/

72

function getEnsName<config extends Config>(

73

config: config,

74

parameters: GetEnsNameParameters<config>

75

): Promise<GetEnsNameReturnType>;

76

77

interface GetEnsNameParameters<config extends Config> {

78

/** Address to reverse resolve */

79

address: Address;

80

/** Chain ID (defaults to mainnet) */

81

chainId?: config['chains'][number]['id'];

82

/** Block number to query at */

83

blockNumber?: bigint;

84

/** Block tag */

85

blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';

86

/** Universal resolver address */

87

universalResolverAddress?: Address;

88

}

89

90

type GetEnsNameReturnType = string | null;

91

92

type GetEnsNameErrorType = BaseErrorType;

93

94

/** @deprecated Use getEnsName instead */

95

const fetchEnsName = getEnsName;

96

```

97

98

**Usage Example:**

99

100

```typescript

101

import { getEnsName } from '@wagmi/core'

102

103

const name = await getEnsName(config, {

104

address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',

105

})

106

console.log('Address resolves to:', name) // "vitalik.eth"

107

```

108

109

### Get ENS Avatar

110

111

Retrieves avatar image for ENS name.

112

113

```typescript { .api }

114

/**

115

* Gets ENS avatar image

116

* @param config - Wagmi configuration

117

* @param parameters - ENS avatar parameters

118

* @returns Avatar URI or null

119

*/

120

function getEnsAvatar<config extends Config>(

121

config: config,

122

parameters: GetEnsAvatarParameters<config>

123

): Promise<GetEnsAvatarReturnType>;

124

125

interface GetEnsAvatarParameters<config extends Config> {

126

/** ENS name */

127

name: string;

128

/** Chain ID */

129

chainId?: config['chains'][number]['id'];

130

/** Block number to query at */

131

blockNumber?: bigint;

132

/** Block tag */

133

blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';

134

/** Universal resolver address */

135

universalResolverAddress?: Address;

136

/** Avatar gateway URLs */

137

gatewayUrls?: {

138

ipfs?: string;

139

arweave?: string;

140

};

141

}

142

143

type GetEnsAvatarReturnType = string | null;

144

145

type GetEnsAvatarErrorType = BaseErrorType;

146

147

/** @deprecated Use getEnsAvatar instead */

148

const fetchEnsAvatar = getEnsAvatar;

149

```

150

151

**Usage Example:**

152

153

```typescript

154

import { getEnsAvatar } from '@wagmi/core'

155

156

const avatar = await getEnsAvatar(config, {

157

name: 'vitalik.eth',

158

})

159

160

if (avatar) {

161

console.log('Avatar URL:', avatar)

162

// Use avatar in UI

163

// <img src={avatar} alt="vitalik.eth avatar" />

164

}

165

```

166

167

### Get ENS Resolver

168

169

Gets the resolver contract for an ENS name.

170

171

```typescript { .api }

172

/**

173

* Gets ENS resolver contract address

174

* @param config - Wagmi configuration

175

* @param parameters - ENS resolver parameters

176

* @returns Resolver address or null

177

*/

178

function getEnsResolver<config extends Config>(

179

config: config,

180

parameters: GetEnsResolverParameters<config>

181

): Promise<GetEnsResolverReturnType>;

182

183

interface GetEnsResolverParameters<config extends Config> {

184

/** ENS name */

185

name: string;

186

/** Chain ID */

187

chainId?: config['chains'][number]['id'];

188

/** Block number to query at */

189

blockNumber?: bigint;

190

/** Block tag */

191

blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';

192

/** Universal resolver address */

193

universalResolverAddress?: Address;

194

}

195

196

type GetEnsResolverReturnType = Address | null;

197

198

type GetEnsResolverErrorType = BaseErrorType;

199

200

/** @deprecated Use getEnsResolver instead */

201

const fetchEnsResolver = getEnsResolver;

202

```

203

204

### Get ENS Text Records

205

206

Retrieves text records for ENS names.

207

208

```typescript { .api }

209

/**

210

* Gets ENS text record

211

* @param config - Wagmi configuration

212

* @param parameters - ENS text parameters

213

* @returns Text record value or null

214

*/

215

function getEnsText<config extends Config>(

216

config: config,

217

parameters: GetEnsTextParameters<config>

218

): Promise<GetEnsTextReturnType>;

219

220

interface GetEnsTextParameters<config extends Config> {

221

/** ENS name */

222

name: string;

223

/** Text record key */

224

key: string;

225

/** Chain ID */

226

chainId?: config['chains'][number]['id'];

227

/** Block number to query at */

228

blockNumber?: bigint;

229

/** Block tag */

230

blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';

231

/** Universal resolver address */

232

universalResolverAddress?: Address;

233

}

234

235

type GetEnsTextReturnType = string | null;

236

237

type GetEnsTextErrorType = BaseErrorType;

238

```

239

240

**Usage Example:**

241

242

```typescript

243

import { getEnsText, getEnsResolver } from '@wagmi/core'

244

245

// Get common text records

246

const email = await getEnsText(config, {

247

name: 'vitalik.eth',

248

key: 'email',

249

})

250

251

const twitter = await getEnsText(config, {

252

name: 'vitalik.eth',

253

key: 'com.twitter',

254

})

255

256

const github = await getEnsText(config, {

257

name: 'vitalik.eth',

258

key: 'com.github',

259

})

260

261

const url = await getEnsText(config, {

262

name: 'vitalik.eth',

263

key: 'url',

264

})

265

266

console.log('ENS records:', {

267

email,

268

twitter,

269

github,

270

url,

271

})

272

273

// Get resolver for advanced usage

274

const resolver = await getEnsResolver(config, {

275

name: 'vitalik.eth',

276

})

277

console.log('Resolver contract:', resolver)

278

```

279

280

## Complete ENS Profile Example

281

282

Here's a comprehensive example showing how to build a complete ENS profile:

283

284

```typescript

285

import {

286

getEnsAddress,

287

getEnsName,

288

getEnsAvatar,

289

getEnsText

290

} from '@wagmi/core'

291

292

async function getEnsProfile(nameOrAddress: string) {

293

let ensName: string | null = null

294

let address: Address | null = null

295

296

// Determine if input is name or address

297

if (nameOrAddress.endsWith('.eth')) {

298

ensName = nameOrAddress

299

address = await getEnsAddress(config, { name: nameOrAddress })

300

} else {

301

address = nameOrAddress as Address

302

ensName = await getEnsName(config, { address })

303

}

304

305

if (!ensName || !address) {

306

return null

307

}

308

309

// Get all profile data in parallel

310

const [avatar, email, twitter, github, url, description] = await Promise.all([

311

getEnsAvatar(config, { name: ensName }),

312

getEnsText(config, { name: ensName, key: 'email' }),

313

getEnsText(config, { name: ensName, key: 'com.twitter' }),

314

getEnsText(config, { name: ensName, key: 'com.github' }),

315

getEnsText(config, { name: ensName, key: 'url' }),

316

getEnsText(config, { name: ensName, key: 'description' }),

317

])

318

319

return {

320

name: ensName,

321

address,

322

avatar,

323

email,

324

twitter,

325

github,

326

url,

327

description,

328

}

329

}

330

331

// Usage

332

const profile = await getEnsProfile('vitalik.eth')

333

if (profile) {

334

console.log('ENS Profile:', profile)

335

}

336

337

const profileByAddress = await getEnsProfile('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')

338

if (profileByAddress) {

339

console.log('Profile from address:', profileByAddress)

340

}

341

```