Web3 Name SDK

Overview

The primary capabilities of the SDK include:

  1. Domain Name Resolution: It resolves Domain Names and Payment IDs to obtain essential information about the domain, including its associated crypto address, various records (such as avatars, IPFS links, social data), and metadata, etc.

  2. Reverse Resolution: The SDK facilitates reverse address resolution. This feature makes it possible to determine the Primary Domain Name associated with a given crypto address, across different blockchains or TLDs.

By default, all EVM-based Domain Names are supported for domain resolution in the Web3 Name SDK. Reverse resolution returns a Chain Primary Name for each EVM chain. Project administrators have the flexibility to choose whether to integrate support for all or only specific chains and TLDs. They can also configure custom settings for reverse resolution as needed. This adaptability allows projects to tailor the SDK's functionality to their specific requirements.

Get Started

Developers can integrate the resolution of web3 domain name <> crypto address using the Web3 Name SDK with zero configuration.

Install

npm install @web3-name-sdk/core viem@^2.23.12

If you are using next.js, please add the following configuration in your next.config.js in order to transpile commonjs dependencies:

const nextConfig = {
  transpilePackages: ['@web3-name-sdk/core'],
}

1. Setup client

2. Resolve a domain name

You can get address from domain name with a single request:

Multichain address resolution

Domain resolution for other chains can be provided by adding coinType param to getAddress().

3. Resolve an address

There are optional parameters in the method to select your target chain or TLD (top-level Domain).

By providing chain IDs, you can resolve addresses on selected chains and get an available domain name from all TLDs deployed on these chains.

By providing TLDs, address can be resolved from the selected TLDs and get an available TLD primary name.

4. Batch resolve addresses

You need to provide your target chain client and then provide optional parameters in the method. The method returns a list containing the address and its corresponding domain.

5. Record

Domain text records can be fetched by providing domain name and the key. For example, the avatar record of spaceid.bnb is returned from this method given key name avatar:

6. Metadata

Domain metadata can be fetched by SDK directly.

Payment ID Domains Support

Web3 Name SDK also supports the Payment ID domains (using @tld format) identifiers that map to addresses across multiple networks. It can simplify transactions by allowing users to send funds to easy-to-remember names.

Chain ID Table for PaymentID Resolution

When resolving PaymentID domains, you can specify a chainId parameter to get addresses for specific blockchains:

Type
ID

Bitcoin

0

EVM

1

Solana

2

Tron

3

Aptos

4

Sui

5

Non-EVM name services

As an all-in-one domain name SDK, non-EVM web3 domain name services are also included. Now we support SNS (Solana Name Service, .sol), Sei Name Service (.sei) and Injective Name Service (.inj).

1. Solana Name Service (.sol)

Install additional corresponding dependencies for the Solana environment:

Create client and query domains:

2. Sei Name Service (.sei)

Install additional corresponding dependencies for the Sei environment:

Create client and query domains:

3. Injective Name Service (.inj)

Install additional corresponding dependencies for the Injective environment:

Create client and query domains:

Note: Next.js Configuration for INJ and SEI Name Services

When using INJ or SEI name services with Next.js, you'll need additional webpack configuration to handle dynamic imports and polyfills. Due to the complexity of these dependencies, extra configuration is required.

Required dependencies:

View the complete Next.js configuration example: next.config.example.js

Use your own RPC

We are using popular public RPC services by default to make it easier to use. But in some cases developers may prefer to use arbitrary RPC, so we provide optional parameter rpcUrl for each function that allows developers to use their own RPC to make requests.

For example, you can put custom rpcUrl as a parameter in getAddress function.

For other functions, it's also possible to have a custom rpcUrl in the request.

Request Timeout Control

The SDK provides timeout control for all network requests. You can set timeouts in two ways:

1. Global Timeout

Set a global timeout when creating the client:

2. Function Request Timeout

Override the global timeout for specific requests:

If a request exceeds the timeout duration, it will throw an error with a message indicating the timeout. The timeout applies to all network operations, including name resolution, reverse lookups, and metadata fetches.

Last updated