# @opennamedid/onjs

> OpenName js sdk

Latest version **1.0.1** (published 2024-04-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install @opennamedid/onjs
pnpm add @opennamedid/onjs
yarn add @opennamedid/onjs
bun add @opennamedid/onjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2024-04-02 |
| First published | 2024-04-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 138.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | openname |

## Links

- npm: https://www.npmjs.com/package/@opennamedid/onjs
- npm.io page: https://npm.io/package/@opennamedid/onjs

## Dependencies (14)

- [web3](https://npm.io/package/web3.md) 1.8.2
- [axios](https://npm.io/package/axios.md) ^1.3.4
- [ethers](https://npm.io/package/ethers.md) ^5.0.13
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.4
- [rimraf](https://npm.io/package/rimraf.md) ^5.0.1
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [content-hash](https://npm.io/package/content-hash.md) ^2.5.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.4
- [@siddomains/sid](https://npm.io/package/@siddomains/sid.md) 0.1.2
- [@siddomains/resolver](https://npm.io/package/@siddomains/resolver.md) 0.1.1
- [@ensdomains/ens-validation](https://npm.io/package/@ensdomains/ens-validation.md) ^0.1.0
- [@siddomains/address-encoder](https://npm.io/package/@siddomains/address-encoder.md) ^0.0.4
- [@ensdomains/eth-ens-namehash](https://npm.io/package/@ensdomains/eth-ens-namehash.md) ^2.0.15

## Recent versions

- 1.0.1 (latest) — 2024-04-02
- 1.0.0 — 2024-04-02

## README

# 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.
```shell
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.

```javascript
const ON = require('onjs/dist/index').default
const nameHash = require('onjs/dist/index').nameHash

let onInst = new ON()  // or 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

```javascript
async getReverse(chainId:number, address:EvmAddress) => Promise<Name>
```

Retrieve a domain name by Evm address.

### Name Interface

```javascript
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. |

```javascript
async getAddr(coinType: number) => Promise<Address>
```

Returns the address for the current ON name for the coinType provided.

### Other Interface

```javascript
nameHash(name: string) => string
```

Returns the tokenId for the domain name provided. 

The usage is as follows.

```javascript
const nameHash = require('onjs/dist/index').nameHash
let tokenId =  nameHash('open.name')
console.log(tokenId)  // 0x109dc...6a69
```

## Appendix

###  Supported Chain List & Coin Type List

Please visit https://docs.open.name/developer-guide/sdk

---
_Source: https://npm.io/package/@opennamedid/onjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
