Resolving Domains in Web Applications
This page describes how to use UD Resolution to resolve blockchain domains in web applications. It assumes the reader has a basic understanding of UD Resolution.
Resolution is a library for interacting with blockchain domain names. It can be used to retrieve payment addresses, IPFS hashes for decentralized websites, and GunDB usernames for decentralized chat.
Resolution is built and maintained by Unstoppable Domains and supports decentralized domains across three main zones:
Name Service
Supported Domains
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
For more information on Unstoppable Domains Resolution, see Resolving Domain Records and the Resolution API Reference.To make domain resolution easier, we've written libraries for web, Android, and iOS.
ENS is not supported in the latest version of our libraries, and there will be no future updates to ENS. The older version of our libraries can still be used for resolution, or developers will need to integrate directly with ENS.

ENS Support

Ethereum Name Service requires installing additional packages to avoid errors thrown by the library when trying to resolve ENS domain.
Required packages:
  • "bip44-constants": "^8.0.5"
  • "@ensdomains/address-encoder": ">= 0.1.x <= 0.2.x"
  • "content-hash": "^2.5.2"
ENS is not supported in the latest version of our libraries, and there will be no future updates to ENS. The older version of our libraries can still be used for resolution, or developers will need to integrate directly with ENS.

Installing Resolution

Resolution can be installed with either yarn or npm.
1
yarn add @unstoppabledomains/resolution
Copied!
1
npm install @unstoppabledomains/resolution --save
Copied!
If you're interested in resolving domains via the command line, see the CLI section below.

Using Resolution

Create a new project.
1
mkdir resolution && cd $_
2
yarn init -y
3
yarn add @unstoppabledomains/resolution
Copied!

Look up a domain's crypto address

Create a new file in your project, address.js.
1
const { default: Resolution } = require('@unstoppabledomains/resolution');
2
const resolution = new Resolution();
3
4
function resolve(domain, currency) {
5
resolution
6
.addr(domain, currency)
7
.then((address) => console.log(domain, 'resolves to', address))
8
.catch(console.error);
9
}
10
11
function resolveMultiChain(domain, currency, chain) {
12
resolution
13
.multiChainAddr(domain, currency, chain)
14
.then((address) => console.log(domain, 'resolves to', address, version))
15
.catch(console.error);
16
}
17
18
resolve('brad.crypto', 'ETH');
19
resolve('brad.zil', 'ZIL');
20
resolveMultiChain('brad.crypto', 'USDT', 'ERC20');
21
resolveMultiChain('brad.crypto', 'USDT', 'OMNI');
Copied!
Execute the script.
1
$ node address.js
2
brad.crypto resolves to 0x8aaD44321A86b170879d7A244c1e8d360c99DdA8
3
brad.zil resolves to zil1yu5u4hegy9v3xgluweg4en54zm8f8auwxu0xxj
Copied!

Find the IPFS hash for a decentralized website

Create a new file in your project, ipfs_hash.js.
1
const { default: Resolution } = require('@unstoppabledomains/resolution');
2
const resolution = new Resolution();
3
4
function resolveIpfsHash(domain) {
5
resolution
6
.ipfsHash(domain)
7
.then((hash) =>
8
console.log(
9
`You can access this website via a public IPFS gateway: https://gateway.ipfs.io/ipfs/${hash}`,
10
),
11
)
12
.catch(console.error);
13
}
14
15
resolveIpfsHash('homecakes.crypto');
Copied!
Execute the script.
1
$ node ipfs_hash.js
2
You can access this website via a public IPFS gateway: https://gateway.ipfs.io/ipfs/QmVJ26hBrwwNAPVmLavEFXDUunNDXeFSeMPmHuPxKe6dJv
Copied!

Find a custom record

Create a new file in your project, custom-resolution.js.
1
const { default: Resolution } = require('@unstoppabledomains/resolution');
2
const resolution = new Resolution();
3
4
function resolveCustomRecord(domain, record) {
5
resolution
6
.records(domain, [record])
7
.then((value) => console.log(`Domain ${domain} ${record} is: ${value}`))
8
.catch(console.error);
9
}
10
11
resolveCustomRecord('homecakes.crypto', 'custom.record.value');
Copied!

Command Line Interface

To use resolution via the command line install the package globally.
1
yarn global add @unstoppabledomains/resolution
Copied!
1
npm install -g @unstoppabledomains/resolution
Copied!
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:
1
resolution --ethereum-url https://mainnet.infura.io/v3/${secret} -d udtestdev-usdt.crypto -a
Copied!
Use the -h or --help flag to see all the available CLI options.

Default Ethereum Providers

Resolution 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 Resolution 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:
1
await Resolution.autonetwork({
2
cns: {provider},
3
ens: {url}
4
});
Copied!

Error Handling

When resolution 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. 1.
    Install nvm
    1
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
    Copied!
  2. 2.
    Install concrete version of node.js
    1
    nvm install 12.12.0
    Copied!
  3. 3.
    Install yarn
    1
    npm install -g yarn
    Copied!
  4. 4.
    Clone the repository
    1
    git clone https://github.com/unstoppabledomains/resolution.git
    2
    cd resolution
    Copied!
  5. 5.
    Install dependencies
    1
    yarn install
    Copied!

Internal Config

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

Support

If you have any questions or need assistance with using UD Resolution CLI, join our Discord channel for real-time support from us and the community.
Last modified 10d ago