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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fiber-rpc-js

v0.1.0

Published

Node.js client library for the Nervos Fiber Network RPC

Readme

fiber-rpc-js

A Node.js client library for the Nervos Fiber Network RPC.

The Fiber Network is CKB's payment channel network — enabling near-instant, near-free micropayments that settle on CKB L1. This library provides a clean, idiomatic JavaScript interface to the Fiber node JSON-RPC API.

Installation

npm install fiber-rpc-js

Quick Start

const { FiberClient, toHex, shannonToCKB } = require('fiber-rpc-js');

const client = new FiberClient({ url: 'http://127.0.0.1:8227' });

// List open channels
const { channels } = await client.listChannels();
for (const ch of channels) {
  console.log(`Channel ${ch.channelId.slice(0,10)}... | ${ch.localBalanceCKB} CKB | ${ch.state}`);
}

// Create an invoice for 100 Shannon
const { invoiceAddress } = await client.newInvoice({
  amount: 100,
  description: 'Payment for service',
});
console.log('Invoice:', invoiceAddress);

// Send a payment
const payment = await client.sendPayment({ invoice: invoiceAddress });
console.log('Status:', payment.status);

Authentication

If your Fiber node has biscuit_public_key set in config (required for public addresses), pass the Biscuit token:

const client = new FiberClient({
  url: 'http://your-node:8227',
  biscuitToken: 'your-biscuit-token',
});

For nodes listening on 127.0.0.1 only, no authentication is required.

API

new FiberClient(options)

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | url | string | ✅ | — | Fiber node RPC URL | | biscuitToken | string | ❌ | — | Biscuit auth token | | timeoutMs | number | ❌ | 10000 | Request timeout in ms |

Channel Methods

listChannels({ peerId?, includeClosed? })

Returns all channels, optionally filtered by peer or including closed channels.

openChannel({ peerId, fundingAmount, isPublic?, isOneWay? })

Opens a payment channel with a peer. fundingAmount is in Shannon (1 CKB = 100,000,000 Shannon).

getChannel(channelId)

Convenience method — finds a channel by ID from listChannels.

Payment Methods

sendPayment({ invoice?, targetPubkey?, amount?, maxFeeAmount?, dryRun? })

Sends a payment. Use invoice (preferred) or targetPubkey + amount for keysend.

getPayment(paymentHash)

Gets the status of a payment by its hash.

Invoice Methods

newInvoice({ amount, description?, currency?, expirySeconds? })

Creates a new invoice. Returns { invoiceAddress, invoice }.

getInvoice(paymentHash)

Retrieves an invoice by payment hash. Returns { invoiceAddress, invoice, status }.

Node Methods

nodeInfo()

Returns node information (peer ID, addresses, version).

listPeers()

Returns connected peers.

Utility Functions

const { toHex, fromHex, shannonToCKB } = require('fiber-rpc-js');

toHex(100_000_000)    // → '0x5f5e100'
fromHex('0x5f5e100') // → BigInt(100000000)
shannonToCKB('0x5f5e100') // → 1.0

Error Handling

const { FiberRpcError, FiberConnectionError } = require('fiber-rpc-js');

try {
  await client.getInvoice('0x...');
} catch (err) {
  if (err instanceof FiberRpcError) {
    console.log('RPC error:', err.code, err.message);
  } else if (err instanceof FiberConnectionError) {
    console.log('Node unreachable:', err.url);
  }
}

Network Support

// Mainnet (default)
const client = new FiberClient({ url: 'http://127.0.0.1:8227' });

// Testnet
const client = new FiberClient({ url: 'http://127.0.0.1:8227', network: 'testnet' });

// Devnet
const client = new FiberClient({ url: 'http://127.0.0.1:8227', network: 'devnet' });

The network option auto-selects the correct currency enum for invoice creation (Fibb / Fibt / Fibd). You can still override manually with currency in newInvoice().

General Questions

Does Node.js need to run as a service?

No — fiber-rpc-js is a library, not a daemon. Drop it into any Node project with npm install. No background process, no service to manage.

If you're building an Electron app on top of it, Node runs inside the Electron process — users never see it or manage it directly.

Does it affect the trust model?

No. The library never holds private keys — it only speaks JSON-RPC to your Fiber node. The trust boundary is your Fiber node itself, which holds the wallet. That's the same trust surface you have without this library.

Do users need to know about Node.js?

For developers building on Fiber: yes, they're already in the Node/JS ecosystem.

For end users of an app built with this library: no — wrap it in Electron, a web UI, or any other interface and Node becomes invisible. Users shouldn't need to know it exists.

Running Tests

Tests run against a live Fiber node via SSH tunnel:

npm test

Requires SSH access to ckbnode (configured in ~/.ssh/config).

License

MIT