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

nanode

v2.3.3

Published

Dead simple, promise-based client for interacting and building services on top of the NANO network.

Downloads

5

Readme

Nano Client by Nanode

Dead simple, promise-based client for interacting and building services on top of the NANO network, a next-generation cryptocurrency created by Colin LeMahieu with nearly instant transactions and no fees. Learn more in the Nanode docs. ⚡️

If you've worked with NANO before, you probably have experienced it's learning curve. The community is amazingly helpful and growing fast, but the documentation and guides to working with it currently leave a lot to be desired.

This library is designed to get anyone, even a total beginner, up and running building services on NANO in just a few minutes. At it's core, this package is a wrapper around the official RPC protocol that does a few things:

  1. abstracts away some of the idiosyncracies and quirks with the RPC API,
  2. exposes some easy top-level account methods like send() and recieve() that do everything automatically so you don't have to know about Proof of Work, creating, signing, publishing, etc
  3. allows you to specify amounts in Nano without dealing with "raw" 128-bit integers

This library works natively with the Nanode Node API as well as the official Nano node software, so there's no vendor lock-in.

Sign up for Node API to get 1,000 free API calls per month! It's the easiest way to build with Nano.

Install

npm install nanode

Getting Started

This library is built with TypeScript, and I highly reccommend you take advantage of your code editor's Intellisense features.

Nanode Node API

const {Nano} = require('nanode')
const nano = new Nano({apiKey: process.env.NANODE_API_KEY})

Your own Nano RPC server

const {Nano} = require('nanode')
const nano = new Nano({url: 'http://localhost:7076'})

Debug mode

To enable some helpful logs, pass debug: true as a paramater in the constructor object.

Working with accounts

Generate an account

It's easy to generate a new random account. You'll get the account's private and public keys along with its address.

const {privateKey, publicKey, address} = await nano.key.create()

Open account

In order to open an account and let the network know it exists, we'll need publish an open block. An account can't be opened with zero balance, so we'll first need to send some Nano to our account's address from our own wallet or NanoFaucet, then call open().

await nano.account(PRIVATE_KEY).open()

Send funds

await nano.account(PRIVATE_KEY).send(0.01, RECIPIENT_ADDRESS)

Receive funds

The receive() method will automatically receive the latest pending block for the given account.

await nano.account(PRIVATE_KEY).receive()

Full list of methods

All methods return native or Bluebird promises and are fully compatible with async/await.

Working with a specific account

If you're just looking to transact with Nano, these methods will cover 90% of your use case.

const account = nano.account(PRIVATE_KEY)
  • account.open(representative?: string, hash?: string)
  • account.send(nanoAmount: string | number, address: string)
  • account.receive(hash?: string)
  • account.change(representative: string)
  • account.rawBalance()
  • account.nanoBalance()
  • account.blockCount()
  • account.history(count?: number)
  • account.info()
  • account.publicKey()
  • account.ledger(count?: number, details?: boolean)
  • account.pending(count?: number, minNanoThreshold?: string | number)
  • account.representative()
  • account.weight()

Keys

Used for generating accounts and extrapolating public keys/addresses from private keys.

  • nano.key.create()
  • nano.key.expand(privateKey: string)

Accounts

Account methods take a single account string or in some cases, an array of accounts.

  • nano.accounts.get(publicKey: string)
  • nano.accounts.rawBalance(account: string)
  • nano.accounts.nanoBalance(account: string)
  • nano.accounts.balances(accounts: string[])
  • nano.accounts.blockCount(account: string)
  • nano.accounts.frontiers(accounts: string[])
  • nano.accounts.history(account: string, count?: number)
  • nano.accounts.info(account: string)
  • nano.accounts.key(account: string)
  • nano.accounts.ledger(account: string, count?: number, details?: boolean)
  • nano.accounts.pending(account: string, count?: number, minNanoThreshold?: string | number)
  • nano.accounts.pendingMulti(accounts: string[], count?: number, minNanoThreshold?: string | number)
  • nano.accounts.representative(account: string)
  • nano.accounts.weight(account: string)

Blocks

Has methods to get information about blocks:

  • nano.blocks.account(hash: string)
  • nano.blocks.count(byType?: boolean)
  • nano.blocks.chain(hash: string, count?: number)
  • nano.blocks.history(hash: string, count?: number)
  • nano.blocks.info(hashOrHahes: string | string[], details?: boolean)
  • nano.blocks.pending(hash: string)
  • nano.blocks.successors(block: string, count?: number)

Methods to construct blocks:

  • nano.blocks.createOpen(block: OpenBlock)
  • nano.blocks.createSend(block: SendBlock)
  • nano.blocks.createReceive(block: ReceiveBlock)
  • nano.blocks.createChange(block: ChangeBlock)

And a method to publish a constructed block to the network:

  • nano.blocks.publish(block: string)

Convert

Allows you to convert rai, krai, and mrai amounts to and from their raw values.

  • nano.convert.toRaw(amount: string | number, denomination: 'rai' | 'krai' | 'mrai')
  • nano.convert.fromRaw(amount: string, denomination: 'rai' | 'krai' | 'mrai')

Work

Allows you to generate and validate Proof of Work for a given block hash.

  • nano.work.generate(hash: string)
  • nano.work.validate(work: string, hash: string)

Other

  • nano.available()
  • nano.representatives()
  • nano.deterministicKey(seed: string, index?: string | number)
  • nano.minimumReceive.get()
  • nano.minimumReceive.set(nanoAmount: string | number)

Calling RPC directly

If there's a method missing, or if you prefer to call RPC directly, you can use nano.rpc. You'll still get the full benefit of type checking and return types for applicable RPC calls.

await nano.rpc('account_info', {account})

Todos

  • TypeDoc site + add remaining method types
  • Tests!