whoisens-lib
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

WhoisENS library

https://www.npmjs.com/package/whoisens-lib https://travis-ci.org/whoisens/whoisens-lib https://david-dm.org/whoisens/whoisens-lib https://david-dm.org/whoisens/whoisens-lib?type=dev https://packagephobia.now.sh/result?p=whoisens-lib https://github.com/whoisens/whoisens-lib/blob/master/LICENSE

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`
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();

Include library

ECMAScript Modules (Node.js or webpack)

import ENS, {ResolveType, EthAddressType, utils} from 'whoisens-lib';

It'll include default ESM module.

CommonJS (Node.js)

const WhoisENS = require('whoisens-lib/cjs/index.js');
 
const ENS = WhoisENS.default;
const {ResolveType, EthAddressType, utils} = WhoisENS;

Script (browser)

<script src="https://unpkg.com/whoisens-lib/dist/browser/main.js"></script>
<script>
  const ENS = WhoisENS.default;
  const {ResolveType, EthAddressType, utils} = WhoisENS;
</script> 

REST API

If you don't willing to include any libraries, you can use WhoisENS REST API directly.

Build (development)

npm ci
npm build:watch

Build (production)

Will produce esm, cjs and bundle modules.

npm run build

Test

npm run test

Logs

Debug modules is used.

Package Sidebar

Install

npm i whoisens-lib

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

486 kB

Total Files

101

Last publish

Collaborators

  • industral