1.1.0 • Published 2 years ago

@rsksmart/rns-resolver.js v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Use this library to resolver RNS domains.

npm i @rsksmart/rns-resolver.js

Features

  • Resolve RSK addresses
  • Resolve other coins addresses
  • Common JS, DOM, Node.js and React Native support

Usage

import Resolver from '@rsksmart/rns-resolver.js'

const resolver = new Resolver.forRskMainnet()

resolver.addr('moneyonchain.rsk').then(console.log) // gets rsk address
// 0x135601C736ddB4C58a4b8fd3CD9F66dF244d28AA


resolver.addr('multichain.testing.rsk', 0).then(console.log) // gets btc address
// 1Ftu4C8VW18RkB8PZxXwwHocMLyEynLcrG

resolver.reverse('0xe9a4e6fae8217E032A08848E227d2b57D3E1e0A5').then(console.log) // gets address of a domain if reverse is set
// testing.rsk

Take a look at the sample apps!

Usage with other networks

For RSK Testnet:

const resolver = new Resolver.forRskTestnet()

For other networks:

const resolver = new Resolver({
  rpcUrl, // your custom network rpc url
  registryAddress: rnsRegistryContractAddress, // deployed on your custom network
  addrEncoder: (buff: Buffer) => `0x${buff.toString('hex')}`, // mock address encoder
})

To deploy RNS Registry contract in your local network you can either:

Usage in Node.js

This library uses fetch by default. To use the ibrary in Node.js please install node-fetch and set it up this way:

import Resolver from '@rsksmart/rns-resolver.js'
import nodeFetch from 'node-fetch'

const resolver = new Resolver.forRskMainnet({
  fetch: nodeFetch
})

Usage in React Native

The resolver uses some Node.js modules that are not implemented by React Native. You need to fill the globals.

  1. Install the resolver

    yarn add @rsksmart/rns-resolver.js
  2. It . Install them

    yarn add buffer big-integer
  3. Add a shim.js file

    if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer
    if (typeof BigInt === 'undefined') global.BigInt = require('big-integer')
  4. Import shim.js from index.js

    import './shim'

Integrations references

WalletTypePR
EdgeMobile wallet (React Native)EdgeApp/edge-react-gui#2505
rWalletMobile wallet (React Native)rsksmart/rwallet/#652

Develop

Install dependencies:

npm i

Run tests

Start a ganache-cli in a spearate terminal with

npm run ganache

Then run:

npm run test

Run linter

npm run lint