An isomorphic async library that interfaces with the RaiBlocks RPC protocol https://github.com/clemahieu/raiblocks/wiki/RPC-protocol
Optimized for version 8+
yarn add raiblocks-js
To test locally, you'll need to setup your own node. See instructions here: https://github.com/clemahieu/raiblocks/wiki/Docker-node
https://gist.github.com/orrybaram/b1c4b724b134c8b7fb0cafe52cb5f6c6
import Rai from 'raiblocks-js';
const rai = new Rai(); // creates default connection to localhost:7076
const blockCount = rai.blocks.count(); // returns Promise with a response object
blockCount.then(res => console.log(res)) // => { count: '1000', unchecked: '10' }
const accountWeight = rai.account.weight({ account: 'xrb_35jjmmmh81kydepzeuf9oec8hzkay7msr6yxagzxpcht7thwa5bus5tomgz9' });
accountWeight.then(res => console.log(res)) // => 1000000
const rai = new Rai();
const blockCount = rai.rpc('block_count'); // returns Promise with a response object
blockCount.then(res => console.log(res)) // => { count: '1000', unchecked: '10' }
const accountWeight = rai.rpc('account_weight', { account: 'xrb_35jjmmmh81kydepzeuf9oec8hzkay7msr6yxagzxpcht7thwa5bus5tomgz9' });
accountWeight.then(res => console.log(res)) // => 1000000
const rai = new Rai('https://xrb.example-node.io:3000');
If you are not using es modules, you'll need to reference the default value:
const { default: Rai } = require('raiblocks-js');
RPC improvement progress here: nanocurrency/nano-node#29