or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

account-management.mdcore-web3.mdens.mdethereum-interaction.mdindex.mdproviders.mdsmart-contracts.mdutilities.md

ens.mddocs/

0

# ENS Integration

1

2

The ENS (Ethereum Name Service) module provides comprehensive functionality for resolving human-readable domain names to Ethereum addresses and vice versa. It supports forward resolution, reverse resolution, record management, and registry interactions with full support for ENS standards.

3

4

## Capabilities

5

6

### Domain Resolution

7

8

Resolve ENS domain names to Ethereum addresses and other records.

9

10

```typescript { .api }

11

/**

12

* Get Ethereum address for ENS name

13

* @param name - ENS domain name (e.g., 'vitalik.eth')

14

* @returns Ethereum address or null if not found

15

*/

16

getAddress(name: string): Promise<string>;

17

18

/**

19

* Get content hash for ENS name

20

* @param name - ENS domain name

21

* @returns Content hash or null if not found

22

*/

23

getContenthash(name: string): Promise<string>;

24

25

/**

26

* Get public key for ENS name

27

* @param name - ENS domain name

28

* @returns Public key coordinates or null if not found

29

*/

30

getPubkey(name: string): Promise<{ x: string; y: string }>;

31

32

/**

33

* Get text record for ENS name

34

* @param name - ENS domain name

35

* @param key - Text record key (e.g., 'email', 'url', 'avatar')

36

* @returns Text record value or null if not found

37

*/

38

getText(name: string, key: string): Promise<string>;

39

```

40

41

**Usage Examples:**

42

43

```typescript

44

// Resolve ENS name to address

45

const address = await web3.eth.ens.getAddress('vitalik.eth');

46

console.log('Address:', address); // '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'

47

48

// Get content hash

49

const contentHash = await web3.eth.ens.getContenthash('vitalik.eth');

50

console.log('Content hash:', contentHash);

51

52

// Get public key

53

const pubkey = await web3.eth.ens.getPubkey('vitalik.eth');

54

console.log('Public key:', pubkey.x, pubkey.y);

55

56

// Get text records

57

const email = await web3.eth.ens.getText('vitalik.eth', 'email');

58

const twitter = await web3.eth.ens.getText('vitalik.eth', 'com.twitter');

59

const avatar = await web3.eth.ens.getText('vitalik.eth', 'avatar');

60

```

61

62

### Reverse Resolution

63

64

Resolve Ethereum addresses back to ENS domain names.

65

66

```typescript { .api }

67

/**

68

* Get ENS name for Ethereum address (reverse resolution)

69

* @param address - Ethereum address

70

* @returns ENS domain name or null if not found

71

*/

72

getName(address: string): Promise<string>;

73

74

/**

75

* Check if address has reverse record set

76

* @param address - Ethereum address

77

* @returns Boolean indicating if reverse record exists

78

*/

79

hasReverseRecord(address: string): Promise<boolean>;

80

```

81

82

**Usage Examples:**

83

84

```typescript

85

// Reverse resolve address to ENS name

86

const name = await web3.eth.ens.getName('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');

87

console.log('ENS name:', name); // 'vitalik.eth'

88

89

// Check if address has reverse record

90

const hasReverse = await web3.eth.ens.hasReverseRecord('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');

91

console.log('Has reverse record:', hasReverse);

92

```

93

94

### Resolver Management

95

96

Interact with ENS resolvers and registry contracts.

97

98

```typescript { .api }

99

/**

100

* Get resolver address for ENS name

101

* @param name - ENS domain name

102

* @returns Resolver contract address

103

*/

104

getResolver(name: string): Promise<string>;

105

106

/**

107

* Get TTL (Time To Live) for ENS name

108

* @param name - ENS domain name

109

* @returns TTL value in seconds

110

*/

111

getTTL(name: string): Promise<string>;

112

113

/**

114

* Get owner of ENS name

115

* @param name - ENS domain name

116

* @returns Owner address

117

*/

118

getOwner(name: string): Promise<string>;

119

120

/**

121

* Check if ENS name exists

122

* @param name - ENS domain name

123

* @returns Boolean indicating if name exists

124

*/

125

recordExists(name: string): Promise<boolean>;

126

```

127

128

**Usage Examples:**

129

130

```typescript

131

// Get resolver for domain

132

const resolver = await web3.eth.ens.getResolver('vitalik.eth');

133

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

134

135

// Get TTL

136

const ttl = await web3.eth.ens.getTTL('vitalik.eth');

137

console.log('TTL:', ttl, 'seconds');

138

139

// Get owner

140

const owner = await web3.eth.ens.getOwner('vitalik.eth');

141

console.log('Owner:', owner);

142

143

// Check if record exists

144

const exists = await web3.eth.ens.recordExists('vitalik.eth');

145

console.log('Record exists:', exists);

146

```

147

148

### Registry Configuration

149

150

Configure ENS registry and network-specific settings.

151

152

```typescript { .api }

153

/**

154

* ENS registry addresses for different networks

155

*/

156

const registryAddresses: {

157

main: string;

158

ropsten: string;

159

rinkeby: string;

160

goerli: string;

161

sepolia: string;

162

};

163

164

/**

165

* Set custom registry address

166

* @param address - Registry contract address

167

*/

168

setRegistryAddress(address: string): void;

169

170

/**

171

* Get current registry address

172

* @returns Registry contract address

173

*/

174

getRegistryAddress(): string;

175

```

176

177

**Usage Examples:**

178

179

```typescript

180

// Default registry addresses

181

console.log('Main registry:', registryAddresses.main);

182

console.log('Goerli registry:', registryAddresses.goerli);

183

184

// Set custom registry (for private networks)

185

web3.eth.ens.setRegistryAddress('0x1234567890123456789012345678901234567890');

186

187

// Get current registry

188

const currentRegistry = web3.eth.ens.getRegistryAddress();

189

console.log('Current registry:', currentRegistry);

190

```

191

192

### Batch Resolution

193

194

Resolve multiple ENS names or addresses in batch operations.

195

196

```typescript { .api }

197

/**

198

* Resolve multiple ENS names to addresses

199

* @param names - Array of ENS domain names

200

* @returns Array of addresses (null for unresolved names)

201

*/

202

getAddresses(names: string[]): Promise<(string | null)[]>;

203

204

/**

205

* Reverse resolve multiple addresses to ENS names

206

* @param addresses - Array of Ethereum addresses

207

* @returns Array of ENS names (null for unresolved addresses)

208

*/

209

getNames(addresses: string[]): Promise<(string | null)[]>;

210

```

211

212

**Usage Examples:**

213

214

```typescript

215

// Batch resolve names to addresses

216

const names = ['vitalik.eth', 'nick.eth', 'nonexistent.eth'];

217

const addresses = await web3.eth.ens.getAddresses(names);

218

console.log('Addresses:', addresses);

219

220

// Batch reverse resolve addresses to names

221

const addressesToResolve = [

222

'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',

223

'0x0904Dac3347eA47d208F3Fd67402D039a3b99859'

224

];

225

const resolvedNames = await web3.eth.ens.getNames(addressesToResolve);

226

console.log('Names:', resolvedNames);

227

```

228

229

### Utility Functions

230

231

Utility functions for ENS name processing and validation.

232

233

```typescript { .api }

234

/**

235

* Check if string is valid ENS name

236

* @param name - String to validate

237

* @returns Boolean indicating validity

238

*/

239

isValidEnsName(name: string): boolean;

240

241

/**

242

* Normalize ENS name according to UTS46 standard

243

* @param name - ENS name to normalize

244

* @returns Normalized ENS name

245

*/

246

normalize(name: string): string;

247

248

/**

249

* Convert ENS name to name hash

250

* @param name - ENS domain name

251

* @returns Name hash as hex string

252

*/

253

namehash(name: string): string;

254

255

/**

256

* Get label hash for ENS name component

257

* @param label - ENS label

258

* @returns Label hash as hex string

259

*/

260

labelhash(label: string): string;

261

```

262

263

**Usage Examples:**

264

265

```typescript

266

// Validate ENS name

267

console.log(web3.eth.ens.isValidEnsName('vitalik.eth')); // true

268

console.log(web3.eth.ens.isValidEnsName('invalid..eth')); // false

269

270

// Normalize ENS name

271

const normalized = web3.eth.ens.normalize('VITALIK.ETH');

272

console.log('Normalized:', normalized); // 'vitalik.eth'

273

274

// Generate name hash

275

const nameHash = web3.eth.ens.namehash('vitalik.eth');

276

console.log('Name hash:', nameHash);

277

278

// Generate label hash

279

const labelHash = web3.eth.ens.labelhash('vitalik');

280

console.log('Label hash:', labelHash);

281

```

282

283

### Advanced Record Types

284

285

Support for advanced ENS record types and multi-format resolution.

286

287

```typescript { .api }

288

/**

289

* Get address for specific cryptocurrency

290

* @param name - ENS domain name

291

* @param coinType - Cryptocurrency coin type (SLIP-0044)

292

* @returns Address for specified cryptocurrency

293

*/

294

getAddr(name: string, coinType?: number): Promise<string>;

295

296

/**

297

* Get interface implementation address

298

* @param name - ENS domain name

299

* @param interfaceID - Interface identifier

300

* @returns Implementation address

301

*/

302

getInterfaceImplementer(name: string, interfaceID: string): Promise<string>;

303

304

/**

305

* Check if resolver supports interface

306

* @param resolver - Resolver address

307

* @param interfaceID - Interface identifier

308

* @returns Boolean indicating support

309

*/

310

supportsInterface(resolver: string, interfaceID: string): Promise<boolean>;

311

```

312

313

**Usage Examples:**

314

315

```typescript

316

// Get Bitcoin address

317

const btcAddress = await web3.eth.ens.getAddr('vitalik.eth', 0); // Bitcoin

318

console.log('Bitcoin address:', btcAddress);

319

320

// Get Ethereum address (default)

321

const ethAddress = await web3.eth.ens.getAddr('vitalik.eth', 60); // Ethereum

322

console.log('Ethereum address:', ethAddress);

323

324

// Check interface support

325

const resolver = await web3.eth.ens.getResolver('vitalik.eth');

326

const supportsAddr = await web3.eth.ens.supportsInterface(resolver, '0x3b3b57de');

327

console.log('Supports ADDR interface:', supportsAddr);

328

```

329

330

## Types

331

332

```typescript { .api }

333

interface ENSRegistryAddresses {

334

main: string;

335

ropsten: string;

336

rinkeby: string;

337

goerli: string;

338

sepolia: string;

339

}

340

341

interface PublicKey {

342

x: string;

343

y: string;

344

}

345

346

interface ENSOptions {

347

registryAddress?: string;

348

provider?: SupportedProviders;

349

}

350

351

// Common text record keys

352

type CommonTextKeys =

353

| 'email'

354

| 'url'

355

| 'avatar'

356

| 'description'

357

| 'notice'

358

| 'keywords'

359

| 'com.discord'

360

| 'com.github'

361

| 'com.reddit'

362

| 'com.twitter'

363

| 'org.telegram';

364

365

// SLIP-0044 coin types

366

type CoinType =

367

| 0 // Bitcoin

368

| 2 // Litecoin

369

| 3 // Dogecoin

370

| 60 // Ethereum

371

| 61 // Ethereum Classic

372

| 118 // Cosmos

373

| 144 // Ripple

374

| number;

375

```