Socket
Socket
Sign inDemoInstall

web3-eth-ens

Package Overview
Dependencies
1
Maintainers
4
Versions
376
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    web3-eth-ens

This package has ENS functions for interacting with Ethereum Name Service.


Version published
Maintainers
4
Created

Package description

What is web3-eth-ens?

The web3-eth-ens package is a part of the Web3.js library that provides functionality for interacting with the Ethereum Name Service (ENS). ENS is a distributed, open, and extensible naming system based on the Ethereum blockchain. It allows users to resolve human-readable names like 'myname.eth' into machine-readable identifiers such as Ethereum addresses, content hashes, and metadata.

What are web3-eth-ens's main functionalities?

Resolving ENS Names to Ethereum Addresses

This feature allows you to resolve a human-readable ENS name to an Ethereum address. The code sample demonstrates how to use the web3-eth-ens package to resolve 'myname.eth' to its corresponding Ethereum address.

const Web3 = require('web3');
const ENS = require('web3-eth-ens');

const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const ens = new ENS(web3);

async function resolveENSName(name) {
  try {
    const address = await ens.getAddress(name);
    console.log(`Address for ${name}: ${address}`);
  } catch (error) {
    console.error(`Error resolving ENS name: ${error}`);
  }
}

resolveENSName('myname.eth');

Reverse Resolution (Address to ENS Name)

This feature allows you to perform a reverse resolution, converting an Ethereum address back to its associated ENS name. The code sample demonstrates how to use the web3-eth-ens package to reverse resolve an Ethereum address to its ENS name.

const Web3 = require('web3');
const ENS = require('web3-eth-ens');

const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const ens = new ENS(web3);

async function reverseResolveAddress(address) {
  try {
    const name = await ens.getName(address);
    console.log(`ENS name for ${address}: ${name}`);
  } catch (error) {
    console.error(`Error reverse resolving address: ${error}`);
  }
}

reverseResolveAddress('0x1234567890abcdef1234567890abcdef12345678');

Setting ENS Records

This feature allows you to set ENS records, such as associating an ENS name with an Ethereum address. The code sample demonstrates how to use the web3-eth-ens package to set the address for 'myname.eth' to a specified Ethereum address.

const Web3 = require('web3');
const ENS = require('web3-eth-ens');

const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const ens = new ENS(web3);

async function setENSRecord(name, address) {
  try {
    const accounts = await web3.eth.getAccounts();
    await ens.setAddress(name, address, { from: accounts[0] });
    console.log(`Set address for ${name} to ${address}`);
  } catch (error) {
    console.error(`Error setting ENS record: ${error}`);
  }
}

setENSRecord('myname.eth', '0x1234567890abcdef1234567890abcdef12345678');

Other packages similar to web3-eth-ens

Readme

Source

web3.js

web3.js - ENS

ES Version Node Version NPM Package Downloads

This is a sub-package of web3.js.

web3-eth-ens This package has ENS functions for interacting with Ethereum Name Service.

Installation

You can install the package either using NPM or using Yarn

Using NPM

npm install web3-eth-ens

Using Yarn

yarn add web3-eth-ens

Getting Started

  • :writing_hand: If you have questions submit an issue or join us on Discord Discord

Prerequisites

Package.json Scripts

ScriptDescription
cleanUses rimraf to remove dist/
buildUses tsc to build package and dependent packages
lintUses eslint to lint package
lint:fixUses eslint to check and fix any warnings
formatUses prettier to format the code
testUses jest to run unit tests
test:integrationUses jest to run tests under /test/integration
test:unitUses jest to run tests under /test/unit

FAQs

Last updated on 30 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc