ethereum-ens-resolver

1.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i ethereum-ens-resolver

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

2.85 kB

Total Files

3

Last publish

Collaborators

  • detoxicmind