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]

Index

Element

Explanation

0

resolverAddr

address of resolver

1

expireTime

The expiration time of a domain name based on the unit timestamp, accurate to the second, for example, 1689738089.

2

name

domain name

3

chainId

the ID of the chain where the domain name resides

4

expireTime of grace

grace period expiration time. The format is the same as expireTime.

5

expireTime of auction

auction period expiration time. The format is the same as expireTime.

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

No

ChainId

ChainName

1

1

Ethereum

2

10

Optimism

3

56

BNB Chain

4

137

Polygon

5

324

zkSync Era

6

8453

Base

7

42161

Arbitrum

8

59144

Linea

9

1101

Polygon zkEvm

10

43114

Avalanche

11

204

opBNB

12

250

Fantom

13

534352

Scroll

14

1030

Conflux eSpace

15

5000

Mantle

16

122

Fuse

17

1088

Metis

18

169

Manta Network

19

42220

Celo

20

81457

Blast

21

34443

Mode

22

666666666

Degen

23

7777777

Zora

Supported CoinType List

No

CoinType

CoinName

1

0

Btc

2

2

Ltc

3

3

Doge

4

4

Rdd

5

5

Dash

6

6

Ppc

7

14

Via

8

17

Grs

9

20

Dgb

10

42

Dcr

11

43

Xem

12

57

Sys

13

60

Eth

14

74

Icx

15

77

Xvg

16

105

Strat

17

111

Ark

18

118

Atom

19

121

Zen

20

128

Xmr

21

133

Zec

22

134

Lsk

23

135

Steem

24

141

Kmd

25

144

Xrp

26

145

Bch

27

148

Xlm

28

156

Btg

29

175

Rvn

30

178

Poa

31

194

Eos

32

195

Trx

33

204

Bcn

34

246

Ewt

35

256

Nano

36

270

One

37

283

Algo

38

291

Iost

39

301

Divi

40

304

Iotx

41

308

Bts

42

309

Ckb

43

313

Zil

44

330

Luna

45

354

Dot

46

360

Vsys

47

367

Abbc

48

394

Cro

49

397

Near

50

415

Etn

51

425

Aion

52

434

Ksm

53

457

Ae

54

459

Kava

55

461

Fil

56

472

Ar

57

500

Theta

58

501

Sol

59

508

Egld

60

535

Xhv

61

539

Flow

62

566

Iris

63

573

Srm

64

589

Tfuel

65

592

Grin

66

614

Opt

67

714

Bnb

68

818

Vet

69

820

Clo

70

888

Neo

71

889

Tomo

72

904

Hnt

73

931

Rune

74

966

Matic

75

999

Bcd

76

1007

Ftm

77

1024

Ont

78

1729

Xtz

79

1815

Ada

80

2301

Qtum

81

2305

Ela

82

2718

Nas

83

3030

Hbar

84

4218

Iota

85

5757

Stx

86

6060

Go

87

8964

Nuls

88

9000

Avax

89

9001

Arb

90

9797

Nrg

91

16754

Ardr

92

52752

Celo

93

5655640

Vlx

94

5718350

Wan

95

5741564

Waves

96

8453

Base

97

59144

Linea

98

1101

Polygon_zkEVM

99

20400

Opbnb

100

534352

Scroll

101

1030

Cfx

102

5000

Mantle

103

122

FUSE

104

1088

Metis

105

169

MANTA

106

42220

CELO

107

81457

Blast

108

1686

Mint

109

34443

Mode

110

666666666

Degen

111

7777777

Zora

Last updated