0.1.18 • Published 20 hours ago

@web3-name-sdk/core v0.1.18

Weekly downloads
-
License
MIT
Repository
-
Last release
20 hours ago

web3-name-sdk

Web3 Name SDK is an universal web3 identity solution for domain name resolution. Developers can easily get access to .eth, .bnb, .arb, .lens, .crypto names and more.

Get Started

Developers can resolve web3 domain name or reverse resolve address with web3 name SDK with zero configuration.

Install

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

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'],
}

Quick Start

1. Setup client

import { createWeb3Name } from '@web3-name-sdk/core'

const web3name = createWeb3Name()

2. Resolve a domain name

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

const address = await web3name.getAddress('spaceid.bnb')
// expect: '0xb5932a6b7d50a966aec6c74c97385412fb497540'

const address = await web3name.getAddress('bts_official.lens')
// expect: '0xd80efa68b50d21e548b9cdb092ebc6e5bca113e7'

const address = await web3name.getAddress('beresnev.crypto')
// expect: '0x6ec0deed30605bcd19342f3c30201db263291589'

const address = await web3name.getAddress('registry.gno')
// expect: '0x2886D6792503e04b19640C1f1430d23219AF177F'
Multichain address resolution

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

import { convertEVMChainIdToCoinType } from '@ensdomains/address-encoder'
const address = await web3name.getAddress('gnome.gno', {coinType: convertEVMChainIdToCoinType(1)})
// expect: 0x4348d45967552d0176d465170b7375ed22dc627b

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.

// Resolve an address from Gnosis Chiado
const name = await web3name.getDomainName({
  address: '0x2886D6792503e04b19640C1f1430d23219AF177F',
  queryChainIdList: [10200],
})
// expect: lydia.gno

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

// Resolve an address from .gno TLD
const name = await web3name.getDomainName({
  address: '0x2886D6792503e04b19640C1f1430d23219AF177F',
  queryTldList: ['gno'],
})
// expect: genome.gno

4. 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:

const record = await sid.getDomainRecord({ name: 'spaceid.bnb', key: 'avatar' })

5. Metadata

Domain metadata can be fetched by SDK directly.

// requesting
const metadata = await web3Name.getMetadata({ name: 'public.gno' })

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 Solana environment:

npm install @solana/web3 @bonfida/spl-name-service

Create client and query domains:

import { createSolName } from '@web3-name-sdk/core/solName'

const web3Name = createSolName()
const domain = await web3Name.getDomainName({
  address: 'Crf8hzfthWGbGbLTVCiqRqV5MVnbpHB1L9KQMd6gsinb',
}) // expect: bonfida

2. Sei Name Service (.sei)

Install additional corresponding dependencies for Sei environment:

npm install @sei-js/core @siddomains/sei-sidjs

Create client and query domains:

import { createSeiName } from '@web3-name-sdk/core/seiName'

const web3Name = createSeiName()
const domain = await web3Name.getDomainName({
  address: 'sei1tmew60aj394kdfff0t54lfaelu3p8j8lz93pmf',
}) // expect: allen.sei

3. Injective Name Service (.inj)

Install additional corresponding dependencies for Injective environment:

npm install @siddomains/injective-sidjs '@injectivelabs/networks' '@injectivelabs/ts-types'

Create client and query domains:

import { createInjName } from '@web3-name-sdk/core/injName'

const web3Name = createInjName()
const domain = await web3Name.getDomainName({
  address: 'inj10zvhv2a2mam8w7lhy96zgg2v8d800xcs7hf2tf',
}) // expect: testtest.inj

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.

const web3name = createWeb3Name({rpcUrl: 'eth mainnet rpc url'})

// Use custom RPC url (https://arb1.arbitrum.io/rpc)
const address = await web3name.getAddress('registry.arb', {
  rpcUrl: 'https://arb1.arbitrum.io/rpc',
})
// expect: '0x8d27d6235d9d8EFc9Eef0505e745dB67D5cD2918'

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

// Use custom RPC url (https://arb1.arbitrum.io/rpc)
const address = await web3name.getMetaData('registry.arb', {
  rpcUrl: 'https://arb1.arbitrum.io/rpc',
})
// expect: '0x8d27d6235d9d8EFc9Eef0505e745dB67D5cD2918'
0.1.18

20 hours ago

0.1.17

4 days ago

0.1.16

1 month ago

0.1.14

3 months ago

0.1.15

3 months ago

0.1.13

5 months ago

0.1.11

5 months ago

0.1.12

5 months ago

0.1.10

5 months ago

0.1.9

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.6

5 months ago

0.1.5

6 months ago

0.1.4

6 months ago

0.0.1-beta.15

6 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.1-beta.14

6 months ago

0.0.1-beta.13

6 months ago

0.0.1-beta.12

6 months ago

0.0.1-beta.11

6 months ago

0.0.1-beta.10

7 months ago

0.0.1-beta.9

7 months ago

0.0.1-beta.8

7 months ago

0.0.1-beta.7

7 months ago

0.0.1-beta.6

7 months ago

0.0.1-beta.5

7 months ago

0.0.1-beta.4

7 months ago

0.0.1-beta.3

7 months ago

0.0.1-beta-3

7 months ago

0.0.1-beta.2

7 months ago

0.0.1-beta.1

7 months ago

0.0.1-beta.0

7 months ago