SDK

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.

npm install @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.

const ON = require('onjs/dist/index').default
const nameHash = 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 = new ON()                             
async function getRecord(name) {
    const record = await onInst.name(name).getRecord()
    console.log("getRecord for "+name+ ": ", record)
}

async function getAddr(name, coinType) {  // coinType refer to the appendix
    let addr = await onInst.name(name).getAddr(coinType) 
    console.log("getAddr for " + name+ ": ", coinType, addr)
}

async function getReverse(chainId, addr) { // chainId refer to the appendix
    let name = await onInst.getReverse(chainId, addr)
    console.log("getReverse for " + addr + ": ", name)
}
// test demo
getRecord("open.name")
getAddr("open.name", 60) 
getReverse(1, '0x6817...oonn')

ON Interface

async getReverse(chainId:number, address:EvmAddress) => Promise<Name>

Retrieve a domain name by Evm address.

Name Interface

getRecord() => Record

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]

async getAddr(coinType: number) => Promise<Address>

Returns the address for the current ON name for the coinType provided.

Other Interface

nameHash(name: string) => string

Returns the tokenId for the domain name provided.

The usage is as follows.

const nameHash = require('onjs/dist/index').nameHash
let tokenId =  nameHash('open.name')
console.log(tokenId)  // 0x109dc...6a69

Appendix

Supported Chain List

Supported CoinType List

Last updated