An API Wrapper library for RISE
Clone or download
Pull request Compare This branch is 10 commits ahead of vekexasia:master.
Latest commit 32f0fbc Sep 28, 2018

README.md

npm Build Status Coverage Status

RISE Javascript Library

A JavaScript API Wrapper for interacting with a rise node. The library works both in the browser and Node.js.

Table of Contents

API Reference

All available methods are available in the API reference at https://risevision.github.io/rise-ts

Installation

Package Manager

Install via your favorite package manager

npm install --save risejs
# or using yarn
yarn add risejs

Include in your javascript

var rise = require('risejs').rise;
// or using es6
import { rise } from 'risejs'

Browser

Include via the unpkg CDN in your html

<script type="text/javascript" src="https://unpkg.com/risejs/dist/browser/index.js"></script>

rise is now globally available on the window object

<script>
    rise.nodeAddress = 'http://example.com:5566';
    // ...
</script>

Usage

Configuration

Set the node address on the RiseAPI object (note: omit any trailing slashes to the url)

rise.nodeAddress = 'http://localhost:5566';

To see other configuration options refer to the API reference

Examples

All API method responses can be handled with either a callback or a Promise. For example, to get the chain status using callbacks

rise.blocks.getStatus(function(err, res) {
    if (err) {
    return console.log('Error: ', err); // handle error
    }
    console.log(res); // { success: true, broadHash: "12aebd7b...
});

using Promises

rise.blocks.getStatus()
    .then(function(res) {
        console.log(res); // { success: true, broadHash: "12aebd7b...
    })
    .catch(function(err) {
        console.log('Error: ', err); // handle error
    });

using async / await

try {
    const res = await rise.blocks.getStatus()
    console.log(res) // { success: true, broadHash: "12aebd7b...
}
catch(err) {
    console.log('Error: ', err) // handle error
}

Error Handling

If rise.errorAsResponse is set to true (the default), application errors will be returned as an object in the response

{
    "success": false,
    "error": "Message"
}

So that handling errors is as follows

rise.blocks.getStatus()
    .then(function(res) {
        if (!res.success) {
            return console.log('Application Error: ', res.error); // handle Application Error
        }
        console.log(res); // { success: true, broadHash: "12aebd7b...
    })
    .catch(function(err) {
        console.log('HTTP Error: ', err); // handle HTTP error
    });

TypeScript

Our Libraries are written in typescript so that you can use types in your applications

import { rise, BlockStatusResponse } from 'risejs';

function handleStatus(err: Error, status: BlockStatusResponse) {
    console.log(status);
};
rise.blocks.getStatus(handleStatus);

All available types are available in the API reference as well at http://risevision.github.io/rise-ts

Advanced Usage

Additional APIWrapper objects can be made using the newWrapper method

var node1 = rise.newWrapper('http://node1:1234');
var node2 = rise.newWrapper('http://node2:1234', { timeout: 5000 });

Compatibility

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 8+ ✔

Browser Matrix

Node support

Node >= 4.x is fully supported :)

Contributing

Read the Contributing Guide for guidelines as well as local development instructions. And thank you to all of our contributors.

Discussion

Feel free to join the Slack!

License

MIT