Usage

1.1 initialize the SDK

Default :

Initialize the SDK without constructor arguments (Uses default RPCs from the SDK, Users may face latency due to public RPC)

Example:

const dotnames = new DotNamesSDK();

Custom :

Initialize the SDK with constructor arguments

Parameters:

  • RPC URLS (string): RPC url for blockchains where the SDK is taken in use.

  • Types:

ethRPC: string;
polygonRPC: string;
bnbRPC: string;
suiRPC: string;
seiRPC: string;
osmosisRPC: string;

Example:

const dotnames = new DotNamesSDK(param : {RPC_URLS});
  • Supported Name Service:

    • ENS

    • SpaceId

    • UnstoppableDomains

    • DotBit

    • Zkns

    • ICNS

    • StargazeDomains

    • Bonfida

    • SuiNs

    • AptosNs

    • SeiNS

1.2 Resolve Domain Name

The resolveName method allows you to resolve a domain name from a wallet address on a specified domain naming service. It returns a Promise that resolves with the domain name or rejects with an error if the resolution fails.

Parameters:

  • walletAddress (0x${string}): The wallet address you want to resolve.

  • NameService (SupportedNs): The name of the domain naming service on which the resolution should occur (e.g., ENS, UnstoppableDomains, DotBit, etc.).

Example:

const dotnames = new DotNamesSDK();
const new walletAddress = "RESOLVE_WALLET_ADDRESS"
dotnames
  .resolveName(walletAddress, SupportedNs.UnstoppableDomains) // Second parameter can be any name service provider which are supported by SDK
  .then((res) => {
    console.log(`Resolved Domain Name: ${res}`);
  })
  .catch((err) => {
    console.error(`Error: ${err}`);
  });

1.3 Resolve Address

The resolveAddress method allows you to resolve a wallet address from a given domain name. It returns a Promise that resolves with the wallet address or rejects with an error if the resolution fails.

Parameters:

  • domainName (string): The domain name you want to resolve to a wallet address.

  • nameService (optional): The name service provider

Example 1 : Without providing Name Service

const dotnames = new DotNamesSDK();
dotnames
  .resolveAddress("vitalik.eth")
  .then((res) => {
    console.log(`Resolved Address: ${res}`);
  })
  .catch((err) => {
    console.error(`Error: ${err}`);
  });

Example 2: Providing Name Service

const dotnames = new DotNamesSDK();
dotnames
  .resolveAddress('sandy.crypto', SupportedNS.UnstoppableDomains)
  .then((res) => {
    console.log(`Resolved Address: ${res}`);
  })
  .catch((err) => {
    console.error(`Error: ${err}`);
  });

1.4 Fetch records for a specified domain name

The getRecords method allows you to fetch the records of a domain name. It returns a Promise that resolves with the content or rejects with an error if the resolution fails.

Parameter:

  • domainName (string): The domain name you want to fetch content.

  • nameService (optional): The name service provider.

Example 1: Without providing Name Service

import { DotNamesSDK } from "@dotnames/dotnames-js/dist/src/index";
import { SupportedNS } from "@dotnames/dotnames-js/dist/src/types";

const dotnames = new DotNamesSDK();

dotnames
    .getRecords('homecakes.crypto')
    .then((records: any) => {
        console.log(records);
    })
    .catch((err) => {
        console.error(`Error: ${err}`);
    });

Example 2: Providing Name Service

import { DotNamesSDK } from "@dotnames/dotnames-js/dist/src/index";
import { SupportedNS } from "@dotnames/dotnames-js/dist/src/types";

const dotnames = new DotNamesSDK();

dotnames
    .getRecords('homecakes.crypto', SupportedNS.UnstoppableDomains)
    .then((records: any) => {
        console.log(records);
    })
    .catch((err) => {
        console.error(`Error: ${err}`);
    });