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

rgb20

v0.0.4

Published

RGB20 contract creation library with StrictEncode and BAID64 integration

Readme

RGB20 Contract Creator

npm version License

A comprehensive RGB20 token contract creation library that combines StrictEncode deterministic binary serialization with BAID64 encoding to generate contract hashes and human-readable identifiers.

Features

  • 🎨 Complete RGB20 contract creation with validation
  • 🔧 StrictEncode integration for deterministic binary serialization
  • 🔐 SHA256 hashing of encoded contract data
  • 🆔 BAID64 encoding with contract: HRI prefix and checksums
  • 🖥️ Rich CLI interface with multiple output formats
  • Comprehensive validation of all contract parameters
  • 📦 Dual module support (ES modules + CommonJS)
  • 🧪 48 comprehensive tests ensuring reliability

Installation

npm install rgb20

Quick Start

Library Usage

import { RGB20Contract, createRGB20Contract } from 'rgb20';

// Create a contract
const contract = createRGB20Contract({
    ticker: 'MYTOKEN',
    name: 'My Token',
    precision: 8,
    contractTerms: 'Token contract terms',
    totalSupply: 1000000,
    genesisUtxo: 'abcd1234...ef56:0'
});

console.log('Contract ID:', contract.contractId);
console.log('Contract Hash:', contract.contractHash);

CLI Usage

# Create a contract
rgb20 create \
    --ticker "MYTOKEN" \
    --name "My Token" \
    --precision 8 \
    --terms "Token contract terms" \
    --supply 1000000 \
    --utxo "abcd1234...ef56:0"

# JSON output
rgb20 create --ticker "MYTOKEN" --name "My Token" \
    --precision 8 --terms "Terms" --supply 1000000 \
    --utxo "abcd...ef:0" --json

# Interactive mode
rgb20 interactive

# Show examples
rgb20 example

API Reference

RGB20Contract Class

Constructor

const contract = new RGB20Contract({
    ticker: string,        // Asset ticker symbol
    name: string,          // Asset name
    precision: number,     // Decimal precision (0-18)
    contractTerms: string, // Contract terms text
    totalSupply: number,   // Total token supply
    genesisUtxo: string   // Genesis UTXO (txid:vout format)
});

Methods

  • createAssetSpec() - Generate RGB20 AssetSpec structure
  • createContractTerms() - Generate RGB20 ContractTerms structure
  • encodeContract() - StrictEncode the complete contract
  • createContractHash() - Generate SHA256 hash of encoded data
  • createContractId() - Generate BAID64 contract ID with HRI prefix
  • generateContract() - Generate complete contract information

Helper Functions

import { createRGB20Contract, validateRGB20Params } from 'rgb20';

// Quick contract creation
const contract = createRGB20Contract(params);

// Validate parameters
const isValid = validateRGB20Params(params); // throws on invalid

CLI Commands

Contract Creation

rgb20 create [options]

Required Options:

  • --ticker <symbol> - Asset ticker symbol
  • --name <name> - Asset name
  • --precision <0-18> - Decimal precision
  • --terms <text> - Contract terms
  • --supply <amount> - Total supply
  • --utxo <txid:vout> - Genesis UTXO

Output Options:

  • --json - JSON format output
  • --hash-only - Show only contract hash
  • --id-only - Show only contract ID
  • --encoded-only - Show only encoded data
  • --compact - Compact JSON output

Other Commands

  • rgb20 validate [options] - Validate contract parameters
  • rgb20 example - Show example with test vectors
  • rgb20 interactive - Interactive contract creation
  • rgb20 help - Show help information

Example Output

{
  "ticker": "NIATCKR",
  "name": "NIA asset name", 
  "precision": 0,
  "contractTerms": "NIA terms",
  "totalSupply": "666",
  "genesisUtxo": "22f0538e...2ac0:1",
  "contractHash": "74e6a36a7ba3948c43ed4653c1723f8426bbc8c038016b9439e59e804fbf5c95",
  "contractId": "contract:dOajanujlIxD7UZTwXI~hCa7yMA4AWuUOeWegE_~XJXV9~e0",
  "encodedData": "074e494154434b52...",
  "encodedLength": 80
}

Technical Details

Contract Structure

RGB20 contracts consist of:

  1. AssetSpec - Ticker, name, precision, optional details
  2. ContractTerms - Legal terms, optional media attachments
  3. Amount - Total token supply (u64)
  4. Genesis UTXO - Transaction output reference

Encoding Process

  1. StrictEncode each component using deterministic binary serialization
  2. Concatenate all encoded components
  3. SHA256 hash the complete encoded data
  4. BAID64 encode the hash with contract: HRI prefix and embedded checksum

Dependencies

  • strictencode - Deterministic binary encoding
  • baid64 - Base64 variant with HRI and checksums

Test Vectors

The package includes comprehensive test vectors from the RGB20 specification:

# Run the specification test vector
rgb20 create \
    --ticker "NIATCKR" \
    --name "NIA asset name" \
    --precision 0 \
    --terms "NIA terms" \
    --supply 666 \
    --utxo "22f0538e189f32922e55daf6fa0b7120bc01de8520a9a4c80655fdaf70272ac0:1"

Expected Output:

  • Contract Hash: 74e6a36a7ba3948c43ed4653c1723f8426bbc8c038016b9439e59e804fbf5c95
  • Contract ID: contract:dOajanujlIxD7UZTwXI~hCa7yMA4AWuUOeWegE_~XJXV9~e0

Development

Running Tests

npm test                # Run all tests
npm run test:watch      # Watch mode  
npm run test:coverage   # With coverage

Building

npm run build:cjs       # Build CommonJS version
npm run lint           # Run linter

Project Structure

rgb20/
├── index.js           # Main ES module
├── index.cjs          # CommonJS build
├── cli.js             # Command-line interface
├── package.json       # Package configuration
├── test/             # Test files
│   ├── rgb20-contract.test.js
│   └── cli.test.js
└── README.md         # This file

Standards Compliance

  • RGB20 - RGB token standard specification
  • StrictEncode - Deterministic binary serialization
  • BAID64 - Base64 variant with HRI prefixes
  • Node.js ESM - Modern ES module support
  • Jest - Comprehensive test coverage

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

Apache-2.0 License - see LICENSE file for details.

Links


RGB Community | Building the future of Bitcoin smart contracts