![npm package](https://badge.fury.io/js/ez-ens.svg)
ez-ens
Simple, zero-configuration Ethereum Name Service resolver with promises.
Works on main, ropsten, and rinkeby Ethereum networks.
Installation
npm install ez-ens
yarn install ez-ens
Sample Usage
const ens = require('ez-ens');
await ens.resolve('ethereum.eth')
await ens.resolve('ethereum.eth', {network: 'ropsten'});
await ens.resolve('ethereum.eth', {providerURI: 'http://localhost:8545'});
await ens.resolve('ethereum.eth', {web3: new Web3(...)});
await ens.resolve('ethereum.eth', {block: 3013041});
await ens.resolve('ethereum.eth', {ttl: 3000});
ens.resolve(ENS_ADDRESS, {
ttl: Number,
block: Number,
network: String,
providerURI: String,
net: Object,
provider: Object,
web3: Object,
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');
ens.minTTL = 10 * 1000;
ens.maxTTL = 8 * 60 * 60 * 1000