1.1.0 • Published 4 years ago
@rsksmart/rns-resolver.js v1.1.0
Use this library to resolver RNS domains.
npm i @rsksmart/rns-resolver.jsFeatures
- 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.rskTake 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:
- Run the whole RNS Suite: https://github.com/rnsdomains/rns-suite
- Deploy just the RNS Registry: https://github.com/rnsdomains/rns-registry
- Deploy programatically as done in unit tests in this repo - see
test/resolver.test.ts
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.
Install the resolver
yarn add @rsksmart/rns-resolver.jsIt . Install them
yarn add buffer big-integerAdd a
shim.jsfileif (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer if (typeof BigInt === 'undefined') global.BigInt = require('big-integer')Import
shim.jsfromindex.jsimport './shim'
Integrations references
| Wallet | Type | PR |
|---|---|---|
| Edge | Mobile wallet (React Native) | EdgeApp/edge-react-gui#2505 |
| rWallet | Mobile wallet (React Native) | rsksmart/rwallet/#652 |
Develop
Install dependencies:
npm iRun tests
Start a ganache-cli in a spearate terminal with
npm run ganacheThen run:
npm run testRun linter
npm run lint