Lightweight library with minimum dependencies to work with ENS (Ethereum Name Service).
- get owner/controller information
- get name date expiration
- resolve name to addresses and address to name
- get contenthash (IPFS/Swarm)
Works with both browser and Node.js.
Library used by WhoisENS.org
PLEASE NOTE: whoisens-lib doesn't work with old ENS registrar (names registered via auction). These names should be migrated to new ENS registrar by May 4, 2020.
- advanced output. You can debug what contract was used, what method was called, what payload was passed and more other info
resolve
method accept and resolves both names and addresses. You don't need to check it manually- content hash returns already decoded
- lightweight
- you can include it directly in your browser via
<script>
, for example you can't do it with Web3.js - thorough tests
For more information, please read ENS (Ethereum Name Service): How it works?
npm i whoisens-lib
// In case running on Node.js, install and export globally `fetch`
import fetch from 'node-fetch';
global.fetch = fetch;
// basic constructor
const ens = new ENS();
// pass custom networkURL
const ens = new ENS({networkURL: 'https://eth.gateway.whoisens.org'});
const ens = new ENS({networkURL: 'https://mainnet.infura.io/v3/<YOUR_KEY>'});
// pass custom eth contractAddress
const ens = new ENS({contractAddress: '0x314159265dd8dbb310642f98f50c066173c1259b'});
// get name owner (registrar)
const ens = new ENS();
ens.init('whoisens.eth');
const result = await ens.getOwner();
// get name expiration date
const result = await ens.getExpirationDate();
// get controller
const result = await ens.getController();
// resolve name or address
const result = await ens.resolve();
// get content hash
const result = await ens.getContentHash();
import ENS, {ResolveType, EthAddressType, utils} from 'whoisens-lib';
It'll include default ESM module.
const WhoisENS = require('whoisens-lib/cjs/index.js');
const ENS = WhoisENS.default;
const {ResolveType, EthAddressType, utils} = WhoisENS;
<script src="https://unpkg.com/whoisens-lib/dist/browser/main.js"></script>
<script>
const ENS = WhoisENS.default;
const {ResolveType, EthAddressType, utils} = WhoisENS;
</script>
If you don't willing to include any libraries, you can use WhoisENS REST API directly.
npm ci
npm build:watch
Will produce esm
, cjs
and bundle
modules.
npm run build
npm run test
Debug modules is used.