Ethereum JavaScript API for interacting with the Ethereum blockchain with comprehensive TypeScript support, modular architecture, and plugin extensibility.
—
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.
Resolve ENS domain names to Ethereum addresses and other records.
/**
* Get Ethereum address for ENS name
* @param name - ENS domain name (e.g., 'vitalik.eth')
* @returns Ethereum address or null if not found
*/
getAddress(name: string): Promise<string>;
/**
* Get content hash for ENS name
* @param name - ENS domain name
* @returns Content hash or null if not found
*/
getContenthash(name: string): Promise<string>;
/**
* Get public key for ENS name
* @param name - ENS domain name
* @returns Public key coordinates or null if not found
*/
getPubkey(name: string): Promise<{ x: string; y: string }>;
/**
* Get text record for ENS name
* @param name - ENS domain name
* @param key - Text record key (e.g., 'email', 'url', 'avatar')
* @returns Text record value or null if not found
*/
getText(name: string, key: string): Promise<string>;Usage Examples:
// Resolve ENS name to address
const address = await web3.eth.ens.getAddress('vitalik.eth');
console.log('Address:', address); // '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
// Get content hash
const contentHash = await web3.eth.ens.getContenthash('vitalik.eth');
console.log('Content hash:', contentHash);
// Get public key
const pubkey = await web3.eth.ens.getPubkey('vitalik.eth');
console.log('Public key:', pubkey.x, pubkey.y);
// Get text records
const email = await web3.eth.ens.getText('vitalik.eth', 'email');
const twitter = await web3.eth.ens.getText('vitalik.eth', 'com.twitter');
const avatar = await web3.eth.ens.getText('vitalik.eth', 'avatar');Resolve Ethereum addresses back to ENS domain names.
/**
* Get ENS name for Ethereum address (reverse resolution)
* @param address - Ethereum address
* @returns ENS domain name or null if not found
*/
getName(address: string): Promise<string>;
/**
* Check if address has reverse record set
* @param address - Ethereum address
* @returns Boolean indicating if reverse record exists
*/
hasReverseRecord(address: string): Promise<boolean>;Usage Examples:
// Reverse resolve address to ENS name
const name = await web3.eth.ens.getName('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
console.log('ENS name:', name); // 'vitalik.eth'
// Check if address has reverse record
const hasReverse = await web3.eth.ens.hasReverseRecord('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
console.log('Has reverse record:', hasReverse);Interact with ENS resolvers and registry contracts.
/**
* Get resolver address for ENS name
* @param name - ENS domain name
* @returns Resolver contract address
*/
getResolver(name: string): Promise<string>;
/**
* Get TTL (Time To Live) for ENS name
* @param name - ENS domain name
* @returns TTL value in seconds
*/
getTTL(name: string): Promise<string>;
/**
* Get owner of ENS name
* @param name - ENS domain name
* @returns Owner address
*/
getOwner(name: string): Promise<string>;
/**
* Check if ENS name exists
* @param name - ENS domain name
* @returns Boolean indicating if name exists
*/
recordExists(name: string): Promise<boolean>;Usage Examples:
// Get resolver for domain
const resolver = await web3.eth.ens.getResolver('vitalik.eth');
console.log('Resolver:', resolver);
// Get TTL
const ttl = await web3.eth.ens.getTTL('vitalik.eth');
console.log('TTL:', ttl, 'seconds');
// Get owner
const owner = await web3.eth.ens.getOwner('vitalik.eth');
console.log('Owner:', owner);
// Check if record exists
const exists = await web3.eth.ens.recordExists('vitalik.eth');
console.log('Record exists:', exists);Configure ENS registry and network-specific settings.
/**
* ENS registry addresses for different networks
*/
const registryAddresses: {
main: string;
ropsten: string;
rinkeby: string;
goerli: string;
sepolia: string;
};
/**
* Set custom registry address
* @param address - Registry contract address
*/
setRegistryAddress(address: string): void;
/**
* Get current registry address
* @returns Registry contract address
*/
getRegistryAddress(): string;Usage Examples:
// Default registry addresses
console.log('Main registry:', registryAddresses.main);
console.log('Goerli registry:', registryAddresses.goerli);
// Set custom registry (for private networks)
web3.eth.ens.setRegistryAddress('0x1234567890123456789012345678901234567890');
// Get current registry
const currentRegistry = web3.eth.ens.getRegistryAddress();
console.log('Current registry:', currentRegistry);Resolve multiple ENS names or addresses in batch operations.
/**
* Resolve multiple ENS names to addresses
* @param names - Array of ENS domain names
* @returns Array of addresses (null for unresolved names)
*/
getAddresses(names: string[]): Promise<(string | null)[]>;
/**
* Reverse resolve multiple addresses to ENS names
* @param addresses - Array of Ethereum addresses
* @returns Array of ENS names (null for unresolved addresses)
*/
getNames(addresses: string[]): Promise<(string | null)[]>;Usage Examples:
// Batch resolve names to addresses
const names = ['vitalik.eth', 'nick.eth', 'nonexistent.eth'];
const addresses = await web3.eth.ens.getAddresses(names);
console.log('Addresses:', addresses);
// Batch reverse resolve addresses to names
const addressesToResolve = [
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
'0x0904Dac3347eA47d208F3Fd67402D039a3b99859'
];
const resolvedNames = await web3.eth.ens.getNames(addressesToResolve);
console.log('Names:', resolvedNames);Utility functions for ENS name processing and validation.
/**
* Check if string is valid ENS name
* @param name - String to validate
* @returns Boolean indicating validity
*/
isValidEnsName(name: string): boolean;
/**
* Normalize ENS name according to UTS46 standard
* @param name - ENS name to normalize
* @returns Normalized ENS name
*/
normalize(name: string): string;
/**
* Convert ENS name to name hash
* @param name - ENS domain name
* @returns Name hash as hex string
*/
namehash(name: string): string;
/**
* Get label hash for ENS name component
* @param label - ENS label
* @returns Label hash as hex string
*/
labelhash(label: string): string;Usage Examples:
// Validate ENS name
console.log(web3.eth.ens.isValidEnsName('vitalik.eth')); // true
console.log(web3.eth.ens.isValidEnsName('invalid..eth')); // false
// Normalize ENS name
const normalized = web3.eth.ens.normalize('VITALIK.ETH');
console.log('Normalized:', normalized); // 'vitalik.eth'
// Generate name hash
const nameHash = web3.eth.ens.namehash('vitalik.eth');
console.log('Name hash:', nameHash);
// Generate label hash
const labelHash = web3.eth.ens.labelhash('vitalik');
console.log('Label hash:', labelHash);Support for advanced ENS record types and multi-format resolution.
/**
* Get address for specific cryptocurrency
* @param name - ENS domain name
* @param coinType - Cryptocurrency coin type (SLIP-0044)
* @returns Address for specified cryptocurrency
*/
getAddr(name: string, coinType?: number): Promise<string>;
/**
* Get interface implementation address
* @param name - ENS domain name
* @param interfaceID - Interface identifier
* @returns Implementation address
*/
getInterfaceImplementer(name: string, interfaceID: string): Promise<string>;
/**
* Check if resolver supports interface
* @param resolver - Resolver address
* @param interfaceID - Interface identifier
* @returns Boolean indicating support
*/
supportsInterface(resolver: string, interfaceID: string): Promise<boolean>;Usage Examples:
// Get Bitcoin address
const btcAddress = await web3.eth.ens.getAddr('vitalik.eth', 0); // Bitcoin
console.log('Bitcoin address:', btcAddress);
// Get Ethereum address (default)
const ethAddress = await web3.eth.ens.getAddr('vitalik.eth', 60); // Ethereum
console.log('Ethereum address:', ethAddress);
// Check interface support
const resolver = await web3.eth.ens.getResolver('vitalik.eth');
const supportsAddr = await web3.eth.ens.supportsInterface(resolver, '0x3b3b57de');
console.log('Supports ADDR interface:', supportsAddr);interface ENSRegistryAddresses {
main: string;
ropsten: string;
rinkeby: string;
goerli: string;
sepolia: string;
}
interface PublicKey {
x: string;
y: string;
}
interface ENSOptions {
registryAddress?: string;
provider?: SupportedProviders;
}
// Common text record keys
type CommonTextKeys =
| 'email'
| 'url'
| 'avatar'
| 'description'
| 'notice'
| 'keywords'
| 'com.discord'
| 'com.github'
| 'com.reddit'
| 'com.twitter'
| 'org.telegram';
// SLIP-0044 coin types
type CoinType =
| 0 // Bitcoin
| 2 // Litecoin
| 3 // Dogecoin
| 60 // Ethereum
| 61 // Ethereum Classic
| 118 // Cosmos
| 144 // Ripple
| number;Install with Tessl CLI
npx tessl i tessl/npm-web3