# @monsterdomains/midjs

> midjs makes Monster domain easy to be integrated

Latest version **0.0.1-alpha.44** (published 2023-02-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @monsterdomains/midjs
pnpm add @monsterdomains/midjs
yarn add @monsterdomains/midjs
bun add @monsterdomains/midjs
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.44 |
| Published | 2023-02-21 |
| First published | 2022-11-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 95.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | crypto_nonce |

## Links

- npm: https://www.npmjs.com/package/@monsterdomains/midjs
- Repository: @monsterdomains/midjs
- npm.io page: https://npm.io/package/@monsterdomains/midjs

## Dependencies (9)

- [ethers](https://npm.io/package/ethers.md) ^5.6.4
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [content-hash](https://npm.io/package/content-hash.md) ^2.5.2
- [@ensdomains/ens](https://npm.io/package/@ensdomains/ens.md) 0.1.2
- [@ensdomains/resolver](https://npm.io/package/@ensdomains/resolver.md) 0.1.1
- [@ensdomains/ens-validation](https://npm.io/package/@ensdomains/ens-validation.md) ^0.1.0
- [@ensdomains/address-encoder](https://npm.io/package/@ensdomains/address-encoder.md) ^0.2.18
- [@ensdomains/eth-ens-namehash](https://npm.io/package/@ensdomains/eth-ens-namehash.md) ^2.0.15
- [@monsterdomains/mid-contracts](https://npm.io/package/@monsterdomains/mid-contracts.md) 0.0.1-alpha.44

## Recent versions

- 0.0.1-alpha.44 (latest) — 2023-02-21
- 0.0.1-alpha.42 — 2023-02-16
- 0.0.1-alpha.41 — 2023-02-11
- 0.0.1-alpha.40 — 2023-02-10
- 0.0.1-alpha.38 — 2023-02-07
- 0.0.1-alpha.37 — 2023-02-07
- 0.0.1-alpha.36 — 2023-01-19
- 0.0.1-alpha.35 — 2023-01-14
- 0.0.1-alpha.34 — 2023-01-13
- 0.0.1-alpha.32 — 2023-01-12
- 0.0.1-alpha.31 — 2022-12-11
- 0.0.1-alpha.30 — 2022-12-11
- 0.0.1-alpha.28 — 2022-12-10
- 0.0.1-alpha.26 — 2022-12-08
- 0.0.1-alpha.25 — 2022-12-07
- … 14 more at https://npm.io/package/@monsterdomains/midjs/versions

## README

# Monster Domains TypeScript SDK

Monster Domains JavaScript SDK provides a way for developers to integrate the features and abilities in Monster Domains system with easy-to-use TypeScript interfaces.

## Installation

`npm install @monsterdomains/midjs@latest --save`

or

`yarn add @monsterdomains/midjs@latest`

## Example Usage

Set up the MID SDK with proper provider, or signer if you need to send transactions

```ts
import MID from "@monsterdomains/midjs";

const NETWORK_ID: number = xxx; // We are a cross-chain domain service, supported network IDs: 56
const provider: ethers.providers.Provider = xxxx;
const signer: ethers.Signer = xxxx;

// @NOTE: if the signer is undefined, you can't use the SDK to send transactions
const mid = new MID({ provider, signer, networkId: NETWORK_ID });

// Now you can call the functions on `mid`
...

```

You can query the basic mapping relations between names and addresses with SDK instance

```ts
...

await mid.getAddressByName("goodname.bnb"); // ==> "0x123..."
await mid.setAddressByName("goodname.bnb", "0x123123...") // You must be the owner of "goodname.bnb" to make this work

await mid.getOwnerByName("goodname.bnb"); // ==> "0x456..."
await mid.setOwnerByName("goodname.bnb", "0x678..."); // ==> You must be the owner of "goodname.bnb" to make this work

await mid.available("goodname.bnb"); // if a domain is taken, it will return `false`
...
```

You can also get the `ethers` contract instances if you want to make the low level calls by yourself and don't need to deal with the troublesome ABI files and contract initializations.

```ts
mid.mid; // The registry contract that stores all the data of nodes, which are the name hash of domain names, and their related owners
mid.controller; // Registrar controller instance for users to interact with
mid.baseRegistrar; // BaseRegistrar instances which is in charge of 'bnb' domain allocation and also the NFT contract
mid.publicResolver; // Public resolver for resolving names and their related metadata like texts, contents & addresses
mid.reverseRegistrar; // Reverse registrar for recording the primary name of domain names
```

## API References


- Get the owner of `name`

```ts
getOwnerByName(name: string) => Promise<string>
```


- Set the owner of `name`, **you must be the owner of the domain name to call this function**

```ts
setOwnerByName(name: string, address: string) => Promise<void>
```

- Get the resolver of `name`

```ts
getResolverByName(name: string) => Promise<string>
```

- Set the resolver for `name`, **you must be the owner of the domain name to call this function**

```ts
setResolverByName(name: string, address: string) => Promise<void>
```

- Get the TTL (Time To Live) of `name`

```ts
getTTLByName(name: string) => Promise<ethers.BigNumber>
```


- Get the address of `name`. If `coinType` is not provided, it will be set to BNB coin type

```ts
getAddressByName(name: string, coinType?: CoinType) => Promise<string>
```


- Batch call `getAddressByName` for `name`

```ts
getAddressesByName(name: string, coinTypes: (CoinType | undefined)[]) => Promise<string[]>
``` 

- Set the address for `name`. If `coinType` is not provided, it will be set to BNB coin type 

```ts
setAddressByName(name: string, coinType: string, address: string)
```

- Batch set the addresses for `name`

```ts
setAddressesByName(name: string, keys: string[], addresses: string[])
```

- Get the content of `name`. The returned value is the link pointing to the content, e.g: `ipfs://xxxxxyyyyy...`

```ts
getContentByName(name: string) => Promise<string>
```

- Set the content for `name`

```ts
setContentByName(name: string, content: string)
```

- Get the text of `name`

```ts
getTextByName(name: string, key: string)  => Promise<string>
```


- Batch call `getTextByName`

```ts
getTextsByName(name: string, keys: string[]) => Promise<string[]>
```

- Set text for `name`. You can specify the `key` for `recordValue`

```ts
setTextByName(name: string, key: string, recordValue: string)
```

- Batch call `setTextByName`

```ts
setTextsByName(name: string, keys: string[], recordValues: string[])
```

- Set subnode owner for `name`. The `label` is the keccak hash of subdomain name. For example:
By calling `setSubnodeOwnerByName(namehash("good.bnb"), keccak256("sub"), newOwner)`, you can set the owner of name: "sub.good.bnb" to `newOwner`. **You must be owner of the "good.bnb" to call this function**

```ts
setSubnodeOwnerByName(name: string, label: string, newOwner: string)
```


- Create subdomain `${label}.${name}` for the `name` domain, the label is the keccak256 hash of subdomain name

```ts
createSubdomainByName(name: string, label: string)
```


- Delete the subdomain `${label}.${name}` of the `name` domain, the label is the keccak256 hash of subdomain name

```ts
deleteSubdomainByName(name: string, label: string)
```


- Check whether a name is available

```ts
available(name: string) => Promise<boolean>
```

- Get the primary name of `address`

```ts
getPrimaryName(address: string) => Promise<string>
```
- Set the primary name for `address`

```ts
setPrimaryName(name: string)
```
- Get the expire date of `name`

```ts
getNameExpiry(name: string) => Promise<ethers.BigNumber>
```

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