WhoisENS library
Lightweight library with minimum dependencies to work with ENS (Ethereum Name Service).
Features
- 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.
Advantages
- 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
How it works?
For more information, please read ENS (Ethereum Name Service): How it works?
Install
npm i whoisens-lib
Example of use
// In case running on Node.js, install and export globally `fetch`;globalfetch = fetch; // basic constructorconst ens = ; // pass custom networkURLconst ens = networkURL: 'https://eth.gateway.whoisens.org';const ens = networkURL: 'https://mainnet.infura.io/v3/<YOUR_KEY>'; // pass custom eth contractAddressconst ens = contractAddress: '0x314159265dd8dbb310642f98f50c066173c1259b'; // get name owner (registrar)const ens = ;ens;const result = await ens; // get name expiration dateconst result = await ens; // get controllerconst result = await ens; // resolve name or addressconst result = await ens; // get content hashconst result = await ens;
Include library
ECMAScript Modules (Node.js or webpack)
;
It'll include default ESM module.
CommonJS (Node.js)
const WhoisENS = ; const ENS = WhoisENSdefault;const ResolveType EthAddressType utils = WhoisENS;
Script (browser)
REST API
If you don't willing to include any libraries, you can use WhoisENS REST API directly.
Build (development)
npm cinpm build:watch
Build (production)
Will produce esm
, cjs
and bundle
modules.
npm run build
Test
npm run test
Logs
Debug modules is used.