Socket
Socket
Sign inDemoInstall

web3-eth-ens

Package Overview
Dependencies
9
Maintainers
2
Versions
377
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-eth-ens


Version published
Maintainers
2
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

Changelog

Source

[1.2.8]

Added

  • Introduce review and release guidelines. (#3460)
  • Add EIP-1193 compatible provider to AbstractProvider interface. (#3499)
  • Add TypeScript definitions for contract methods and call. (#3454)
  • Update AbstractProvider and contract.methods TS definitions (#3521)
  • Add support for ENS contenthash methods. (#3392, #2782)

Changed

  • Change CI provider from Travis to GitHub Actions. (#3468)
  • Update web3-eth-abi ABICoder dependency. (#3490)
  • Update AbiCoder param formatting (#3522)
  • Improve code clarity of HttpProvider keepAlive option setting. (#3463)
  • Updated type definitions for Web3 HTTP Provider. (#3482)
  • Fix indentation of web3-eth documentation. (#3478)

Fixed

  • Fix intermittent CI build issues with dtslint. (#3479)
  • Fix WSS credentials Base64 encoding (for browser) (#3508)
  • Fire provider "error" and/or "end" events when Websocket provider disconnects. (#3485)
  • Remove web3-eth revert error return types to squash TS compilation errors. (#3496)
  • Backfill event subscriptions when WS connection dropped across multiple blocks. (#3491)
  • Stop swallowing errors when WS connection has died after exhausting reconnection attempts. (#3492)
  • Fix setContenthash docs formatting (#3511)

Readme

Source

web3-eth-ens

NPM Package Dependency Status Dev Dependency Status

This is a sub-package of web3.js.

This is the contract package to be used in the web3-eth package.

Please read the documentation for more.

Installation

Node.js

npm install web3-eth-ens

In the Browser

Build running the following in the web3.js repository:

npm run-script build-all

Then include dist/web3-eth-ens.js and dist/web3-eth.js in your html file. This will expose the EthEns object on the window object.

Usage

var eth = new Web3Eth(web3.currentProvider);
var ens = new EthEns(eth);

ens.getAddress('ethereum.eth').then(function(result) {
    console.log(result);
});

Types

All the TypeScript typings are placed in the types folder.

FAQs

Last updated on 20 May 2020

Did you know?

Socket

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc