RNS Resolver
npm install @rsksmart/rns-resolver.js
@rsksmart/rns-resolver.js
RNS Resolver
Use this library to resolver RNS domains.
```
npm i @rsksmart/rns-resolver.js
- Resolve RSK addresses
- Resolve other coins addresses
- Common JS, DOM, Node.js and React Native support
`ts
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!
For RSK Testnet:
`ts`
const resolver = new Resolver.forRskTestnet()
For other networks:
`ts0x${buff.toString('hex')}
const resolver = new Resolver({
rpcUrl, // your custom network rpc url
registryAddress: rnsRegistryContractAddress, // deployed on your custom network
addrEncoder: (buff: Buffer) => , // 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
This library uses fetch by default. To use the ibrary in Node.js please install node-fetch and set it up this way:
`ts
import Resolver from '@rsksmart/rns-resolver.js'
import nodeFetch from 'node-fetch'
const resolver = new Resolver.forRskMainnet({
fetch: nodeFetch
})
`
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
`js`
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
`js`
import './shim'
Integrations references
| Wallet | Type | PR |
| - | - | - |
| Edge | Mobile wallet (React Native) | EdgeApp/edge-react-gui#2505 |
| rWallet | Mobile wallet (React Native) | rsksmart/rwallet/#652 |
Install dependencies:
``
npm i
Start a ganache-cli in a spearate terminal with
``
npm run ganache
Then run:
``
npm run test
```
npm run lint