0.0.1-alpha.44 • Published 1 year ago

@monsterdomains/midjs v0.0.1-alpha.44

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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

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

...

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.

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
getOwnerByName(name: string) => Promise<string>
  • Set the owner of name, you must be the owner of the domain name to call this function
setOwnerByName(name: string, address: string) => Promise<void>
  • Get the resolver of name
getResolverByName(name: string) => Promise<string>
  • Set the resolver for name, you must be the owner of the domain name to call this function
setResolverByName(name: string, address: string) => Promise<void>
  • Get the TTL (Time To Live) of name
getTTLByName(name: string) => Promise<ethers.BigNumber>
  • Get the address of name. If coinType is not provided, it will be set to BNB coin type
getAddressByName(name: string, coinType?: CoinType) => Promise<string>
  • Batch call getAddressByName for name
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
setAddressByName(name: string, coinType: string, address: string)
  • Batch set the addresses for name
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...
getContentByName(name: string) => Promise<string>
  • Set the content for name
setContentByName(name: string, content: string)
  • Get the text of name
getTextByName(name: string, key: string)  => Promise<string>
  • Batch call getTextByName
getTextsByName(name: string, keys: string[]) => Promise<string[]>
  • Set text for name. You can specify the key for recordValue
setTextByName(name: string, key: string, recordValue: string)
  • Batch call setTextByName
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
setSubnodeOwnerByName(name: string, label: string, newOwner: string)
  • Create subdomain ${label}.${name} for the name domain, the label is the keccak256 hash of subdomain name
createSubdomainByName(name: string, label: string)
  • Delete the subdomain ${label}.${name} of the name domain, the label is the keccak256 hash of subdomain name
deleteSubdomainByName(name: string, label: string)
  • Check whether a name is available
available(name: string) => Promise<boolean>
  • Get the primary name of address
getPrimaryName(address: string) => Promise<string>
  • Set the primary name for address
setPrimaryName(name: string)
  • Get the expire date of name
getNameExpiry(name: string) => Promise<ethers.BigNumber>