Giter Site home page Giter Site logo

joltwallet / nano-node-rpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitdesert/nano-node-rpc

0.0 1.0 0.0 34 KB

๐Ÿ”— Super simple promise-based client for the Nano Cryptocurrency Node RPC API

Home Page: https://mynano.ninja

License: MIT License

JavaScript 100.00%

nano-node-rpc's Introduction

๐Ÿ”— Nano Node RPC Client

npm version

Nano RPC client written in Javascript with no external dependencies. It produces JSON objects or strings as output, wrapped in native promises.

All RPC calls are defined in the Nano.org Docs.

Getting Started

Install

npm install nano-node-rpc

My Nano Ninja Node API

const NanoClient = require('nano-node-rpc');
const client = NanoClient({apiKey: process.env.NINJA_API_KEY})

Your own Nano RPC server

const NanoClient = require('nano-node-rpc');
const client = NanoClient({url: 'http://localhost:7076'})

Use methods attached to client to send RPC calls

Examples

Head to the examples.js file for even more!

const client = NanoClient({url: 'http://localhost:7076'})

// Some methods do not require arguments:
client
  .block_count()
  .then(count => {
    console.log(count);
    /**
     * {
     *   "count": "1826834",
     *   "unchecked": "3385205"
     * }
     */
  })
  .catch(e => {
    // Deal with your errors here.
  });

// Some methods require arguments:
client
  .account_balance("nano_1ninja7rh37ehfp9utkor5ixmxyg8kme8fnzc4zty145ibch8kf5jwpnzr3r")
  .then(balance => {
    console.log(balance);
    /**
     * {
     *   "balance": "325586539664609129644855132177",
     *   "pending": "2309370929000000000000000000000000"
     * }
     */
  })
  .catch(e => {
    // Deal with your errors here.
  });

Promise-wrapped responses

All method calls return native NodeJS promises. You need to use the then() / catch() pattern shown above. If the call was succesful, the data will be passed to then(), otherwise the error will be passed to catch().

Methods Names

The method calls are the same as the original RPC actions defined on the Nano.org Docs.

Example1: on the Nano wiki account_balance is called with account. For the NodeJS client, the method is account_balance and the argument is the account string.

If a method is not available with a method you can use the _send method like this:

client._send('block_info', {
  "json_block": true,
  "hash": "87434F8041869A01C8F6F263B87972D7BA443A72E0A97D7A3FD0CCC2358FD6F9"
}).then(block_info => {
  console.log(block_info);
  /**
   * {
   *   "block_account": "nano_1ipx847tk8o46pwxt5qjdbncjqcbwcc1rrmqnkztrfjy5k7z4imsrata9est",
   *   "amount": "30000000000000000000000000000000000",
   *   "balance": "5606157000000000000000000000000000000",
   *   "height": "58",
   *   "local_timestamp": "0",
   *   "confirmed": "true",
   *   "contents": {
   *     ...
   *   },
   *   "subtype": "send"
   * }
   */
})
.catch(e => {
  // Deal with your errors here.
});

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.