SID SDK
SIDjs integrates the SID contract & SPACE ID, and supports all the SIDjs APIs. You will only need one unified SDK to integrate all domains across multiple chains. SIDjs will hide all the complicated cross-chain details from partners, which makes the integration easy.
Currently, SIDjs supports both BNB Chain, Arbitrum, and Ethereum name-resolving services including .bnb Name Service, .arb Name Service and ENS.
npm install @siddomains/sidjs web3
.bnb Name Service
const SID = require('@siddomains/sidjs').default
const SIDfunctions = require('@siddomains/sidjs')
const Web3 = require('web3')
let sid
async function main(name) {
const rpc = "https://data-seed-prebsc-1-s1.binance.org:8545/"
const provider = new Web3.providers.HttpProvider(rpc)
const chainId = '97'
sid = new SID({ provider, sidAddress: SIDfunctions.getSidAddress(chainId) })
const address = await sid.name(name).getAddress() // 0x123
console.log("name: %s, address: %s", name, address)
}
main("felix.bnb")
main("newregister.bnb")
main("nft.bnb")
.arb Name Service
Sidjs supports domain resolution for both Arbitrum One and Arbitrum Nova." test.arb" is minted on Arbitrum Goerli Testnet for testing purposes.
We support arbitrum one now, and “test.arb” is minted on Arbitrum One for testing purposes. Switch the chain id and rpc to Arbitrum One correspondingly.
const SID = require('@siddomains/sidjs').default
const SIDfunctions = require('@siddomains/sidjs')
const Web3 = require('web3')
let sid
async function main(name) {
const rpc = "https://arb1.arbitrum.io/rpc" //Arbitrum One rpc
const provider = new Web3.providers.HttpProvider(rpc)
const chainId = 42161 //Arbitrum One chain id
sid = new SID({ provider, sidAddress:SIDfunctions.getSidAddress(chainId) })
const arbitrum1_address = await sid.name(name).getAddress("ARB1")
const arbirum_nova_address = await sid.name(name).getAddress("ARB_NOVA")
console.log("name: %s,arb1 address: %s", name, arbitrum1_address)
console.log("name: %s,arb_nova address: %s", name, arbirum_nova_address)
}
main("test.arb")
Note:
- When ARB ID goes on mainnet, the .arb domain name NFT will be minted on Arbitrum One, and user’s Arbitrum One and Arbitrum Nova address data will both be recorded on Arbitrum One.
- For domain resolution on mainnet, the SDK will require Arbitrum One’s rpc to resolve domain names on both Arbitrum One and Arbitrum Nova.
Reverse Resolution will resolve an address to a domain name if it is a valid reverse domain name in the SPACE ID protocol.
.bnb Name Service
// bsc domain example
const SID = require('@siddomains/sidjs').default
const SIDfunctions = require('@siddomains/sidjs')
const Web3 = require('web3')
let sid
async function main(address) {
const rpc = "https://data-seed-prebsc-1-s1.binance.org:8545/"
const provider = new Web3.providers.HttpProvider(rpc)
const chainId = '97'
sid = new SID({ provider, sidAddress: SIDfunctions.getSidAddress(chainId) })
const name = await sid.getName(address)
console.log("name: %s, address: %s", name, address)
}
main("0x88dC0cc038bF0A1D9a79E3E3Bb958A55882a838B")
.arb Name Service
// .arb domain example
const SID = require('@siddomains/sidjs').default
const SIDfunctions = require('@siddomains/sidjs')
const Web3 = require('web3')
let sid
async function main(address) {
const rpc = "https://arb1.arbitrum.io/rpc"
const provider = new Web3.providers.HttpProvider(rpc)
const chainId = 42161 //Arbitrum One chain id
sid = new SID({ provider, sidAddress: SIDfunctions.getSidAddress(chainId) })
const name = await sid.getName(address)
console.log("name: %s, address: %s", name, address)
}
main("0xB522E32b6B49363f420d2546E13479c05fF27201")
Note: Arbitrum One and Arbitrum Nova have the same reverse domain name.
rpc variable configures which blockchain to connect with.
Blockchain | Default RPC |
---|---|
BSC | |
BSC TESTNET | |
ETH MAINNET | - |
*Note: If Dapp is connecting to a wallet (ex: Trustwallet or Metamask), rpc can be retrieved directly through the connected wallet by using 'ethers' library. Sample code is provided.
import {providers} from "ethers";
import SID, {getSidAddress} from '@siddomains/sidjs'
export async function main(name) {
if (typeof window.ethereum !== 'undefined') {
const provider = new providers.Web3Provider(window.ethereum);
const sid = new SID({provider, sidAddress: getSidAddress('56')})
const address = await sid.name(name).getAddress() // 0x123
console.log("name: %s, address: %s", name, address)
}
}
main('felix.bnb')
chainId uniquely identifies a blockchain and all related contracts deployed on that chain.
Blockchain | Chain Id |
---|---|
BSC | 56 |
BSC TESTNET | 97 |
ETH MAINNET | 1 |
Last modified 23d ago