rgbtest

RGB Protocol JavaScript Implementation

A comprehensive, modular JavaScript implementation of the RGB protocol, focusing on RGB20 non-inflatable assets. Built with a test-driven approach for learning and production use.

๐ŸŒˆ Features

๐Ÿš€ Quick Start

Interactive Demo

๐ŸŒˆ Try the Live Demo - Interactive RGB20 contract creation with real-time visualization

Code Example

import { RGB20Contract } from 'rgbtest';

// Create a simple RGB20 asset
const contract = RGB20Contract.create({
  ticker: 'SBTC',
  name: 'Synthetic Bitcoin',
  precision: 8,
  terms: 'Bitcoin-backed synthetic asset',
  supply: 2100000000000000, // 21M BTC in satoshis
  utxoRef: '1a2b3c4d5e6f78901234567890abcdef1234567890abcdef1234567890abcdef:0'
});

console.log(`Contract ID: ${contract.getFormattedContractId()}`);
console.log(`Total Supply: ${contract.getTotalSupply().toNumber()} satoshis`);

๐Ÿ“ฆ Installation

npm install rgbtest

๐Ÿ—๏ธ Architecture

The library is organized into 5 development stages:

Stage 1: Core Utilities

Stage 2: Type System

Stage 3: Genesis Components

Stage 4: Contract Management

Stage 5: Integration

๐Ÿ“š Examples

Creating Different Asset Types

import { RGB20Contract } from 'rgbtest';

// Stablecoin (6 decimals like USDC)
const stablecoin = RGB20Contract.create({
  ticker: 'SUSD',
  name: 'Synthetic USD',
  precision: 6,
  terms: 'USD-backed stablecoin',
  supply: 1000000000000, // 1M USD
  utxoRef: 'abc123...def:1'
});

// NFT-like collection (0 decimals)
const nft = RGB20Contract.create({
  ticker: 'RARE',
  name: 'Digital Art Collection',
  precision: 0,
  terms: 'Limited edition digital art',
  supply: 100,
  utxoRef: 'def456...abc:2'
});

Validating Transfers

// Check if a transfer is valid
try {
  const validation = contract.validateTransfer(
    'source_utxo:0',
    1000, // amount
    'destination_utxo:1'
  );
  console.log(`Transfer valid: ${validation.amount} tokens`);
} catch (error) {
  console.log(`Transfer failed: ${error.message}`);
}

Working with Precision

const btcAsset = RGB20Contract.create({
  ticker: 'BTC',
  name: 'Bitcoin',
  precision: 8, // 8 decimal places
  // ... other params
});

// Convert between atomic and decimal amounts
const atomic = btcAsset.getAssetInfo().totalSupply; // in satoshis
const decimal = atomic / Math.pow(10, btcAsset.getPrecision()); // in BTC

๐Ÿงช Testing

Run the comprehensive test suite:

# Run all tests
npm test

# Run specific test files
npm test test/types/asset-spec.test.js
npm test test/genesis/genesis.test.js
npm test test/contract/rgb20.test.js

๐Ÿ”ง Development

# Clone and install
git clone https://github.com/rgbjs/rgbtest.git
cd rgbtest
npm install

# Run examples
node examples/stage1-utilities.js
node examples/stage2-types.js
node examples/complete-rgb20-example.js

# Run all tests
npm test

๐Ÿ“– API Reference

RGB20Contract

Main contract interface:

Core Types

AssetSpec

Amount

ContractTerms

๐Ÿ”’ Security

๐ŸŽฏ Use Cases

๐Ÿ“‹ Roadmap

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality
  4. Ensure all tests pass (npm test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments


Built with โค๏ธ for the RGB ecosystem