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

denames

v1.4.1

Published

An all-in-one library to resolve decentralized accounts/domains

Downloads

282

Readme

Denames

NPM version CI Bundle Size Minified Bundle Size Minified Zipped Get help in Issues

Denames is a library to interact with Web3 accounts and domains. It can be used to retrieve crypto addresses on blockchain, users social contacts and custom records.

Denames supports decentralized accounts/domains across below zones:

  • .bit (Previously DAS)

    • .bit
  • Zilliqa Name Service (ZNS)

    • .zil
  • Ethereum Name Service (ENS)

    • .eth
    • .kred
    • .xyz
    • .luxe
  • Unstoppable Name Service (UNS)

    • .crypto
    • .nft
    • .blockchain
    • .bitcoin
    • .coin
    • .wallet
    • .888
    • .dao
    • .x
    • ...

Background

The Denames is currently built on top of @unstoppabledomain/resolution version v5.0.1, and added support for .bit alongside with ENS, UNS, ZNS.

Denames introduced a method which will return a list of crypto addresses for the given chain:

import { Resolution } from 'denames'

const resolution = new Resolution()
const account = 'dastodamoon.bit'

interface DasAccountRecord {
  key: string; // This will always be the corresponding key for each account systems
  value: string;
  label: string; // This will always be empty string `''` for all accounts other than .bit
  ttl: number; // This will always be 0 for all accounts other than .bit
  avatar: string; // This will always be empty string `''` for all accounts other than .bit
}

resolution.addrList(account, 'ckb').then(records => {
  console.log(`account ${account} has ${records.length} CKB address records as below:`)
  
  records.forEach((record: DasAccountRecord, i) => {
    const { key, value, label, ttl, avatar } = record
    console.log(`CKB address ${i}: ${value}, label: ${label}, with a ttl ${ttl}`)
  })
})

output:

account dastodamoon.bit has 2 CKB address records as below:
CKB address 0: ckb1qyqzeajw8xtqgvw0d6q8ey7sysvv7evxvwqqvnvmwu, label: BusinessAddress, with a ttl 300
CKB address 1: ckb1qyq9j48k60dll8xjw04u2uu6vvd0fypqjkhqq84pmt, label: PersonalAddress, with a ttl 300

It will return an empty list [] when no records are set.

For other methods from @unstoppabledomain/resolution, please see @unstoppabledomains/resolution API Reference

Installing Denames

Denames can be installed with either yarn or npm.

yarn add denames
npm install denames

If you're interested in resolving domains via the command line, see our CLI section.

Using Denames

Create a new project.

mkdir denames && cd $_
yarn init -y
yarn add denames

Look up account's crypto addresses

Create a new file in your project, address.js.

It is recommended that developers set up their own .bit Indexer, see .bit Backend Integration for details.

const { Resolution } = require('denames');
const resolution = new Resolution({
  sourceConfig: {
    das: {
      url: 'https://indexer-v1.did.id', // .bit indexer JSON-RPC endpoint. You can use the indexer provided by .bit team for test.
      network: 'mainnet',
    }
  }
});

function resolve(domain, currency) {
  resolution
    .addrList(domain, currency)
    .then((records) => console.log(domain, 'resolves to', records[0]?.value))
    .catch(console.error);
}

resolve('dastodamoon.bit', 'CKB');
resolve('brad.zil', 'ZIL');

Execute the script.

$ node address.js
dastodamoon.bit resolves to ckb1qyqzeajw8xtqgvw0d6q8ey7sysvv7evxvwqqvnvmwu
brad.zil resolves to zil1yu5u4hegy9v3xgluweg4en54zm8f8auwxu0xxj

Command Line Interface

To use denames via the command line install the package globally.

yarn global add denames
npm install -g denames

By default, the CLI uses Infura as its primary gateway to the Ethereum blockchain. If you'd like to override this default and set another provider you can do so using the --ethereum-url flag.

For example:

denames --ethereum-url https://mainnet.infura.io/v3/${secret} -d udtestdev-usdt.crypto -a

Use the -h or --help flag to see all the available CLI options.

Default Ethereum Providers

Denames provides zero-configuration experience by using built-in production-ready Infura endpoint by default.
Default Ethereum provider is free to use without restrictions and rate-limits for CNS (.crypto domains) resolution.
To resolve ENS domains on production it's recommended to change Ethereum provider.
Default provider can be changed by changing constructor options new Resolution(options) or by using one of the factory methods:

  • Resolution.infura()
  • Resolution.fromWeb3Version1Provider()
  • Resolution.fromEthersProvider()
  • etc.

To see all constructor options and factory methods check Unstoppable API reference.

Autoconfiguration of blockchain network

In some scenarios system might not be flexible enough to easy distinguish between various Ethereum testnets on compile time. For this case Denames library provide a special async constructor which should be waited for await Resolution.autonetwork(options). This method makes a JSON RPC "net_version" call to the provider to get the network id.

This method configures only Ens and Cns, Zns is supported only on Zilliqa mainnet which is going to be used in any cases. You can provide a configured provider or a blockchain url as in the following example:

await Resolution.autonetwork({
  cns: {provider},
  ens: {url}
});

Error Handling

When denames encounters an error it returns the error code instead of stopping the process. Keep an eye out for return values like RECORD_NOT_FOUND.

Development

Use these commands to set up a local development environment (macOS Terminal or Linux shell).

  1. Install nvm

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
  2. Install concrete version of node.js

    nvm install 12.12.0
  3. Install yarn

    npm install -g yarn
  4. Clone the repository

    git clone https://github.com/dotbitHQ/denames.git
    cd denames
  5. Install dependencies

    yarn install

Internal config

To update:

  • Network config: $ yarn network-config:pull
  • Supported keys: $ yarn supported-keys:pull
  • Both configs: $ yarn config:pull

Get help

Join our discord community and ask questions.