A library for interacting with blockchain domain names.
Supported domain zones:
Use the npm
or yarn
to install the resolution package.
yarn add @unstoppabledomains/resolution
npm install @unstoppabledomains/resolution --save
If you're interested in resolving domains via the command line, see CLI section.
Create a new project.
mkdir test-out-resolution && cd $_
yarn init -y
yarn add @unstoppabledomains/resolution
Make a file, script.js
.
const {default: Resolution} = require('@unstoppabledomains/resolution')
const resolution = new Resolution()
function resolve(domain, currency) {
resolution.address(domain, currency)
.then(address => console.log(domain, 'resolves to', address))
.catch(console.error)
}
resolve('brad.crypto', 'ETH')
resolve('brad.zil', 'ZIL')
Execute the script.
$ node script.js
brad.crypto resolves to 0x8aaD44321A86b170879d7A244c1e8d360c99DdA8
brad.zil resolves to zil1yu5u4hegy9v3xgluweg4en54zm8f8auwxu0xxj
Resolution library can help you out with resolving DWeb records, such as IPFS hashes for websites or GunDB usernames for p2p chat system.
const {default: Resolution} = require('@unstoppabledomains/resolution')
const resolution = new Resolution()
function resolveIpfsHash(domain) {
resolution.ipfsHash(domain)
.then(hash => console.log(`You can access the website via a public IPFS gateway: https://gateway.ipfs.io/ipfs/${hash}`))
.catch(console.error)
}
function resolveGunDbRecords(domain) {
resolution.chatId(domain)
.then(id => console.log(`Domain ${domain} has a GunDB chat ID: ${id}`))
.catch(console.error)
resolution.chatPk(domain)
.then(pk => console.log(`Domain ${domain} has a GunDB public key: ${pk}`))
.catch(console.error)
}
resolveIpfsHash("homecakes.crypto")
resolveGunDbRecords("homecakes.crypto")
If you want to use resolution CLI, install this package globally:
yarn global add @unstoppabledomains/resolution
npm install -g @unstoppabledomains/resolution
Once you have installed the CLI you can go ahead and use it without any extra configuration. By default the cli is using https://main-rpc.linkpool.io service as a gateway to blockchain. If you want to change it to some other providers including your own you can do so by utilizing resolution -C flag.
As an argument to -C type the following structure url:< https://.... >
Example of usage
resolution -C url:https://...
You can find all of the options for resolution cli within -h, --help flag.
Flag -m can retrieve all the metadata, so you don't need to query it separately if you just want an overview of domain records.
Example:
resolution -mc eth,btc,DODGE,unknown -d brad.zil
When resolution hits an error it returns the error code instead of throwing. So if you see something like RECORD_NOT_FOUND you know exactly that record was not found for this query.
Use next commands for setting up development environment. (macOS Terminal or Linux shell).
Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Install concrete version of node.js
nvm install 12.12.0
Install yarn
npm install -g yarn
Clone repo
git clone https://github.com/unstoppabledomains/resolution.git
cd resolution
Install dependencies
yarn install
Generated using TypeDoc