Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
web3-eth-ens
Advanced tools
This package has ENS functions for interacting with Ethereum Name Service.
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.
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');
The eth-ens-namehash package provides utilities for working with ENS names, including namehashing and normalization. It is more focused on the technical aspects of ENS name processing, whereas web3-eth-ens provides higher-level functionality for interacting with the ENS system.
The ethers package is a complete Ethereum library and includes support for ENS. It provides functionalities for resolving ENS names, reverse resolution, and interacting with ENS records. Compared to web3-eth-ens, ethers is a more comprehensive library that covers a broader range of Ethereum-related functionalities.
This is a sub-package of web3.js.
web3-eth-ens
This package has ENS functions for interacting with Ethereum Name Service.
You can install the package either using NPM or using Yarn
npm install web3-eth-ens
yarn add web3-eth-ens
Script | Description |
---|---|
clean | Uses rimraf to remove dist/ |
build | Uses tsc to build package and dependent packages |
lint | Uses eslint to lint package |
lint:fix | Uses eslint to check and fix any warnings |
format | Uses prettier to format the code |
test | Uses jest to run unit tests |
test:integration | Uses jest to run tests under /test/integration |
test:unit | Uses jest to run tests under /test/unit |
[4.0.1-rc.1]
net
and fs
modules (#5978)web3-providers-ipc
and instantiate provider yourself (#5978)data
property is passed to txInputOptionsFormatter
, it will now be replaced with input
(#5915)TransactionTypeParser
and TransactionBuilder
are now utilizing the type Transaction
for the transaction object. (#5993)net
and fs
modules (#5978)web3-providers-ipc
and instantiate provider yourself (#5978)gasLimit
is no longer accepted as a parameter for MissingGasError
and `TransactionGasMismatchError, and is also no longer included in error message (#5915)signTransaction
will now return gas
instead of gasLimit
for returned transaction object regardless of what property name the provider uses (#5915)formatTransaction
will now replace data
transaction property with input
(#5915)isTransactionCall
will now check if value.input
isHexStrict
if provided (#5915)defaultTransactionBuilder
and transactionBuilder
are now utilizing the type Transaction
for the transaction object. (#5993)signTransaction
returned by privateKeyToAccount
is now accepting the type Transaction
for its argument. (#5993)getSendTxParams
will now return input
instead of data
in returned transaction parameters object (#5915)Contract
constructor will now thrown new ContractTransactionDataAndInputError
if both data
and input
are passed in ContractInitOptions
for Contract
constructor (#5915)ContractInitOptions
, NonPayableCallOptions
and PayableCallOptions
are moved to web3-types
. (#5993)data
property in TransactionOutput
was renamed to input
(#5915)signTransaction
inside Web3BaseWalletAccount
is now utilizing the type Transaction
for its argument. (#5993)FMT_NUMBER
, NumberTypes
, FMT_BYTES
, ByteTypes
, DataFormat
, DEFAULT_RETURN_FORMAT
, ETH_DATA_FORMAT
and FormatType
moved from web3-utils
. (#5993)ContractInitOptions
, NonPayableCallOptions
and PayableCallOptions
are moved from web3-eth-contract
. (#5993)FMT_NUMBER
, NumberTypes
, FMT_BYTES
, ByteTypes
, DataFormat
, DEFAULT_RETURN_FORMAT
, ETH_DATA_FORMAT
and FormatType
moved to web3-types
. (#5993)input
is now an acceptable property for ContractInitOptions
in place of data
(either can be used, but input
is used withing the Contract
class) (#5915)isHexString
, isHexPrefixed
, validateNoLeadingZeroes
(#5963)getConfig
method from Web3Config
class, config
is now public and accessible using Web3Config.config
(#5950)formatDecodedObject
function (#5934)data
was removed as a property of ContractOptions
type (#5915)checkNetwork
in ENS (#5988)FAQs
This package has ENS functions for interacting with Ethereum Name Service.
The npm package web3-eth-ens receives a total of 361,899 weekly downloads. As such, web3-eth-ens popularity was classified as popular.
We found that web3-eth-ens demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.