ethereum-ens-resolver
v1.0.1
Published
A JavaScript package for resolving Ethereum addresses from domain names and vice versa using the Ethereum Name Service (ENS).
Downloads
3
Readme
Ethereum Name Service (ENS) Resolver
A JavaScript package for resolving Ethereum addresses from domain names and vice versa using the Ethereum Name Service (ENS).
Installation
npm install ethereum-ens-resolver
Usage
const ENSResolver = require('ethereum-ens-resolver');
const Web3 = require('web3');
// Initialize Web3 with the provider of your choice
const web3Provider = 'https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID';
const web3 = new Web3(web3Provider);
// Create a new instance of the ENS Resolver
const ensResolver = new ENSResolver(web3);
// Resolve a domain name to an Ethereum address
const domainName = 'example.eth';
ensResolver.resolveAddress(domainName)
.then((address) => {
console.log(`Resolved ${domainName} to address:`, address);
})
.catch((error) => {
console.error('Error occurred while resolving address:', error);
});
// Resolve an Ethereum address to a domain name
const address = '0x123456789abcdef...';
ensResolver.resolveName(address)
.then((name) => {
console.log(`Resolved address ${address} to name:`, name);
})
.catch((error) => {
console.error('Error occurred while resolving name:', error);
});
API
resolveAddress(domainName)
Resolves a domain name to an Ethereum address using the Ethereum Name Service (ENS).
domainName
: The domain name to resolve.
Returns a promise that resolves to the Ethereum address corresponding to the domain name.
resolveName(address)
Resolves an Ethereum address to a domain name using the Ethereum Name Service (ENS).
address
: The Ethereum address to resolve.
Returns a promise that resolves to the domain name corresponding to the Ethereum address.
License
This project is licensed under the MIT License - see the LICENSE file for details.