GithubHelp home page GithubHelp logo

newtmex / rise-ts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vekexasia/dpos-api-wrapper

0.0 1.0 0.0 730 KB

An API Wrapper library for RISE

License: MIT License

JavaScript 4.10% TypeScript 95.90%

rise-ts's Introduction

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

rise-ts's People

Contributors

vekexasia avatar jpopesculian avatar mcventure avatar

Watchers

Levi Chimezie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.