npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dev-ptera/nano-node-rpc

v2.1.0

Published

A typescript nanocurrency client used to make node RPC calls.

Downloads

85

Readme

@dev-ptera/nano-node-rpc

This is a Nanocurrency remote procedure call (RPC) client written in Typescript with a singular dependency on axios.

Use this package to fetch Nanocurrency data from either a local Nano Node, a Nano Node Proxy server, or My Nano Ninja.

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

Getting Started

Install

npm install @dev-ptera/nano-node-rpc

or

yarn add @dev-ptera/nano-node-rpc

Usage

Typescript

import { NanoClient } from "@dev-ptera/nano-node-rpc";

/* Below are three potential nano clients; pick one. */

/* Localhost Nano Node */
const localClient = new NanoClient({url: "http://[::1]:7076"});

/* Web API */
const remoteClient = new NanoClient({url: "[URL]"});

/* My Nano Ninja */
const myNanoNinjaClient = new NanoClient({
    url: "https://mynano.ninja/api/node",
    requestHeaders: {
        "Authorization": process.env.NINJA_API_KEY
    }
});

Javascript

const NanoClient = require("@dev-ptera/nano-node-rpc").NanoClient;
/* Same client configuration as typescript example. */

Fetching Node Data

import { NanoClient } from "@dev-ptera/nano-node-rpc";
import * as RPC from "@dev-ptera/nano-node-rpc/types"
import { AxiosError } from "axios";

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

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

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

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

See examples.js file for more examples.

Supported Methods

The method calls are the same as the original RPC actions defined on the Nano.org Docs.
E.g. the Nano block_count RPC method would be accessible via client.block_count().

If a method is not available as a method on NanoClient, you can use the _send method below:

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.
});

Generic Typing

Some RPC response types will change depending on the optional parameters included in the request. peers is an example of a request that can conditionally include PeersResponseDetails when the flag peer_details is true.

Local Development

yarn build > creates output in the /dist folder

yarn test > runs test suite; requires a local Banano node to pass

yarn prettier > run code formatting