This document mainly introduces the related APIs and usage methods of the SDK.
Use onjs SDK to interact with OpenName contracts
onjs
onjs integrates the OpenName contract, you will only need one unified SDK to integrate all domains across multiple chains. onjs will hide all the complicated cross-chain detail from the partners, making the integration very easy.
Overview of the onjs
Installation
Install @opennamedid/onjs.
npminstall@opennamedid/onjs
This package exports bellows.
default - get instance of onjs
nameHash - get tokenId for name
Getting Started
First,you need to create a new ON instance.
constON=require('onjs/dist/index').defaultconstnameHash=require('onjs/dist/index').nameHash/*let defaultRPCUrls = { "7000": "https://zetachain-evm.blockpi.network/v1/rpc/public", "8453": "https://rpc.ankr.com/base", "56": "https://bsc-dataseed4.ninicoin.io", "43114": "https://api.avax.network/ext/bc/C/rpc", "666666666": "https://rpc.degen.tips", "5000": "https://rpc.mantle.xyz", "42220": "https://forno.celo.org", "1088": "https://andromeda.metis.io/?owner=1088", "59144": "https://1rpc.io/linea", "1030": "https://evm.confluxrpc.com", "250": "https://rpcapi.fantom.network", "534352": "https://rpc.scroll.io", "1": "https://rpc.payload.de", "122": "https://rpc.fuse.io", "81457": "https://rpc.blast.io", "169": "https://pacific-rpc.manta.network/http", "137": "https://polygon.llamarpc.com", "324": "https://mainnet.era.zksync.io", "34443": "https://mainnet.mode.network", "204": "https://opbnb-mainnet-rpc.bnbchain.org", "1101": "https://zkevm-rpc.com", "42161": "https://1rpc.io/arb", "10": "https://1rpc.io/op", "7777777": "https://rpc.zora.energy"}let onInst = new ON({ "rpcUrls": defaultRPCUrls}) // or let onInst = new ON()Among them, the rpc of each chain in rpcUrls can be replaced, and only one or more rpc can be passed, for example.let rpcUrls = { "7000": "your rpc1", //replace the default rpc with your rpc "1101": "your rpc2"}let onInst = new ON({ "rpcUrls": rpcUrls}) If you do not pass the rpc of a certain chain, the system will use the default configuration, which is defaultRPCUrls.*/let onInst =newON() asyncfunctiongetRecord(name) {constrecord=awaitonInst.name(name).getRecord()console.log("getRecord for "+name+": ", record)}asyncfunctiongetAddr(name, coinType) { // coinType refer to the appendixlet addr =awaitonInst.name(name).getAddr(coinType) console.log("getAddr for "+ name+": ", coinType, addr)}asyncfunctiongetReverse(chainId, addr) { // chainId refer to the appendixlet name =awaitonInst.getReverse(chainId, addr)console.log("getReverse for "+ addr +": ", name)}// test demogetRecord("open.name")getAddr("open.name",60) getReverse(1,'0x6817...oonn')
Returns a Record Object, The Record Object is an array object with a length of 6. [resolverAddr,expireTime,name,chainId,expireTime of grace,expire time of auction]