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

rgb-api-sdk

v1.0.8

Published

RGB API SDK for RGB Lightning Node

Downloads

36

Readme

RGB API JavaScript SDK

A JavaScript/TypeScript SDK for interacting with RGB Lightning Node APIs. This SDK provides a simple and intuitive interface for managing RGB assets, lightning network operations, and on-chain transactions.

Features

  • Modular Architecture: Organized into logical modules (node, onchain, RGB, lightning, swaps)
  • Full TypeScript Support: Complete type definitions for all APIs
  • Promise-based: Modern async/await API
  • Error Handling: Comprehensive error handling with meaningful messages
  • Flexible Configuration: Support for custom headers, base URLs, and axios configurations

Installation

npm install @lnfi-network/rgb-api-js-sdk

or

yarn add @lnfi-network/rgb-api-js-sdk

Quick Start

import { RgbApiClient } from '@lnfi-network/rgb-api-js-sdk';

// Initialize the client
const client = new RgbApiClient({
  baseUrl: 'http://localhost:3001'
});

// Check node status
const nodeInfo = await client.node.getNodeInfo();
console.log('Node Info:', nodeInfo);

// List RGB assets
const assets = await client.rgb.listAssets();
console.log('Assets:', assets);

Configuration

Basic Configuration

const client = new RgbApiClient({
  baseUrl: 'http://localhost:3001'
});

Advanced Configuration

const client = new RgbApiClient({
  baseUrl: 'https://your-rgb-node.com',
  headers: {
    'Authorization': 'Bearer your-api-key',
    'Custom-Header': 'value'
  },
  axiosConfig: {
    timeout: 10000,
    proxy: false
  }
});

API Modules

Node Operations

// Get node information
const nodeInfo = await client.node.getNodeInfo();

// Check node state (0: NON_EXISTING, 1: LOCKED, 4: SERVER_ACTIVE)
const state = await client.node.getNodeState();

// Get network information
const networkInfo = await client.node.getNetworkInfo();

// Validate indexer URL
await client.node.checkIndexerUrl({ 
  indexer_url: 'electrs:50001' 
});

// Sign a message
const signature = await client.node.signMessage({ 
  message: 'Hello RGB' 
});

RGB Asset Operations

// List all assets
const assets = await client.rgb.listAssets();

// Get asset balance
const balance = await client.rgb.getAssetBalance({
  asset_id: 'rgb1qyfe883hey6jrgj2xvk5g3dfmfqfzm7a4wez4pd2krf7ltsxffd6u6nqcg'
});

// Get asset metadata
const metadata = await client.rgb.getAssetMetadata({
  asset_id: 'rgb1qyfe883hey6jrgj2xvk5g3dfmfqfzm7a4wez4pd2krf7ltsxffd6u6nqcg'
});

// Send assets
await client.rgb.sendAssets({
  recipient_map: {
    'asset_id': [{
      recipient: 'recipient_address',
      amount: 1000
    }]
  }
});

// Convert hex to RGB asset ID
const rgbId = await client.rgb.assetIdFromHexBytes({
  hex_bytes: '9266c8ffd37caee3809ebe465d9eb29666613eb47737f3f27444c56720b58d74'
});
console.log('RGB Asset ID:', rgbId.asset_id);
// Output: rgb:kmbI~9N8-ruOAnr5-GXZ6ylm-ZhPrR3N-~PydETF-ZyC1jXQ

// Convert RGB asset ID to hex
const hexBytes = await client.rgb.assetIdToHexBytes({
  asset_id: 'rgb:kmbI~9N8-ruOAnr5-GXZ6ylm-ZhPrR3N-_PydETF-ZyC1jXQ'
});
console.log('Hex Bytes:', hexBytes.hex_bytes);
// Output: 9266c8ffd37caee3809ebe465d9eb29666613eb47737e3f27444c56720b58d74

Lightning Network Operations

// List channels
const channels = await client.lightning.listChannels();

// Create invoice
const invoice = await client.lightning.createInvoice({
  amount_msat: 10000,
  description: 'Payment for services'
});

// Decode RGB Lightning invoice
const decoded = await client.lightning.decodeRGBLNInvoice(
  'lnbcrt30u1p5f9szd...'
);

// Pay invoice
await client.lightning.payInvoice({
  invoice: 'lnbcrt30u1p5f9szd...'
});

On-chain Operations

// Get new address
const address = await client.onchain.getAddress();

// List transactions
const transactions = await client.onchain.listTransactions();

// Send Bitcoin
await client.onchain.sendBtc({
  address: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
  amount: 100000 // satoshis
});

Swap Operations

// List swaps
const swaps = await client.swaps.listSwaps();

// Create swap
await client.swaps.createSwap({
  // swap parameters
});

TypeScript Support

The SDK includes comprehensive TypeScript definitions:

import { RgbApiClient, NodeState, AssetSchema } from '@lnfi-network/rgb-api-js-sdk';

const client = new RgbApiClient({ 
  baseUrl: 'http://localhost:3001' 
});

// Type-safe operations
const state: number = await client.node.getNodeState();
if (state === 4) { // SERVER_ACTIVE
  console.log('Node is active and ready');
}

// Filter assets by schema
const assets = await client.rgb.listAssets({
  filter_asset_schemas: [AssetSchema.NIA, AssetSchema.CFA]
});

Error Handling

The SDK provides structured error handling:

try {
  const nodeInfo = await client.node.getNodeInfo();
} catch (error) {
  if (error.message.includes('Network Error')) {
    console.error('Unable to connect to RGB node');
  } else if (error.message.includes('API Error')) {
    console.error('API returned an error:', error.message);
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Development

Building

npm run build

Testing

# Run all tests
npm test

# Run specific test file
npm test test/rgb.integration.test.js

Development Mode

npm run dev

Examples

Check the examples/ directory for complete usage examples:

API Reference

For detailed API documentation, refer to:

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.