npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ez-ens

v1.3.0

Published

Simple, zero configuration Ethereum Name Service resolver.

Downloads

10

Readme

npm package

ez-ens

Simple, zero-configuration Ethereum Name Service resolver with promises.

Works on main, ropsten, and rinkeby Ethereum networks.

Installation

npm install ez-ens
# or
yarn install ez-ens

Sample Usage

const ens = require('ez-ens');
// Resolve 'ethereum.eth' on the mainnet.
await ens.resolve('ethereum.eth') // '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
// Resolve 'ethereum.eth' on ropsten.
await ens.resolve('ethereum.eth', {network: 'ropsten'});
// Resolve 'ethereum.eth' using the provider at http://localhost:8545.
await ens.resolve('ethereum.eth', {providerURI: 'http://localhost:8545'});
// Resolve 'ethereum.eth' using an existing web3 instance (lower overhead).
await ens.resolve('ethereum.eth', {web3: new Web3(...)});
// Resolve 'ethereum.eth' on the mainnet at a specific block number.
await ens.resolve('ethereum.eth', {block: 3013041});
// Resolve 'ethereum.eth' on the mainnet and override the TTL (cache duration).
await ens.resolve('ethereum.eth', {ttl: 3000});

// Full resolve() options.
ens.resolve(ENS_ADDRESS, {
	// Manually specify how long, in ms, to keep the record in the cache.
	// If not set, the TTL specified by the registrar will be used.
	ttl: Number,
	// Block number to evaluate the ENS record at. Defaults to latest.
	block: Number,
	// Network to use. Either 'main', 'ropsten', or 'rinkeby'.
	// Defaults to 'main'
	network: String,
	// Custom provider URI. May be an http://, https://, ws://, or IPC path.
	providerURI: String,
	// If providerURI is an IPC path, set this to `require('net')`
	net: Object,
	// Custom provider instance to use (e.g., web3.currentProvider)
	provider: Object,
	// Custom Web3 instance to use. Lightest option if making lots of calls.
	web3: Object,
	// Infura project ID, if not using a custom provider.
	infuraKey: String
});

Resolver EIP support

ENS resolvers may implement extension EIPs, a few of which can be accessed through the following functions:

  • ens.getTextRecord(name, key): EIP-634 Text records.
  • ens.getContentHash(name): EIP-1577 IPFS content hashes.
  • ens.getBlockchainAddress(name): EIP-2304 Cross-blockchain support.
  • ens.getCanonicalName(name): EIP-181 Reverse resolution.

Minimum ENS cache duration

Once an address is resolved, the address will be cached for future calls. Each address record has a TTL, or time-to-live, defined, which specifies how long the cache should be retained. However, many ENS registrations unintentionally leave the TTL at the default of 0, which would imply no caching. So, by default, cache TTLs are clamped to be at least one hour. You can configure this behavior yourself by setting the ens.minTTL property to the minimum number of milliseconds to keep a cache entry. The maximum TTL can also be specified with the ens.maxTTL property.

Example

const ens = require('ez-ens');
// Set the minimum TTL to 10 seconds.
ens.minTTL = 10 * 1000;
// Set the maximum TTL to 8 hours.
ens.maxTTL = 8 * 60 * 60 * 1000