Edit this page

Resolve Using Matic.js SDK

The Unstoppable Domains resolution plugin is natively integrated into the official Matic SDK utils namespace, so you can access all Unstoppable's library functions using the same syntax as web3.js and ethers.js. This allows developers building Polygon-based applications to easily integrate Unstoppable domain resolution functionalities.

info

The resolution plugin has the same API as the Resolution Library, so all the functions that are in the JavaScript library are available via the resolution plugin and Matic SDK.

Prerequisites

Use Case: Retrieve a Domain Record

To run the snippet below you need to install the following packages:

Copy
Copied
npm install @truffle/hdwallet-provider
npm install @maticnetwork/maticjs
npm install @maticnetwork/maticjs-web3
npm install @unstoppabledomains/maticjs-resolution

Retrieve any record of a domain. Applications sometimes set custom records for a domain to use within their application.

Copy
Copied
const HDWalletProvider = require('@truffle/hdwallet-provider')
const { POSClient, use } = require('@maticnetwork/maticjs')
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3")
const {
  UnstoppableDomainsClientPlugin
} = require("@unstoppabledomains/maticjs-resolution")

// plugins for matic.js
use(Web3ClientPlugin);
use(UnstoppableDomainsClientPlugin);

async function resolveWithUnstoppableExample() {
    const privateKey = '<key>'
    const userAddress = '<address>'

    // Client setup
    const posClient = new POSClient();
    await posClient.init({
        log: true,
        network: 'testnet',
        version: 'mumbai',
        parent: {
          provider: new HDWalletProvider(privateKey, '<provider url>'),
          defaultConfig: {
            from : userAddress
          }
        },
        child: {
          provider: new HDWalletProvider(privateKey, '<provider url>'),
          defaultConfig: {
            from : userAddress
          }
        }
    });
    const client = posClient.client;

    // Resolution examples

    // Resolve a token address from a domain
    const addr = await client.resolution.addr('brad.crypto', 'ETH');
    console.log(`Ethereum address for brad.crypto is ${addr}`);

    // Resolve all records from a domain
    const records = await client.resolution.allRecords('brad.crypto');
    console.log(`All records for brad.crypto are ${JSON.stringify(records)}`);

    // Resolve an ipfs hash from a domain
    const ipfsHash = await client.resolution.ipfsHash('homecakes.crypto');
    console.log(`IPFS hash for homecakes.crypto is ${ipfsHash}`);
}

resolveWithUnstoppableExample()

Asking For Help

Please don't be shy; we're here to help. Join our Discord channel for real-time support from UD and the community if you need assistance integrating your app.