TypeScript SDK for scanning, parsing, validating, and transferring TSB (Token Standard Bitcoin) tokens on Bitcoin.
TSB is a token standard for Bitcoin that enables:
- Token Creation - Create custom tokens on Bitcoin
- Token Transfers - Transfer tokens between addresses
- Atomic Transactions - 3-transaction sequence ensures atomicity
- Witness Scripts - Token data embedded in Taproot witness scripts
- Bitcoin-Native - No external state, fully on-chain
- β Token Scanning - Scan Bitcoin addresses for TSB tokens
- β Token Parsing - Extract token data from Taproot witness scripts
- β Token Validation - Verify token structure and compliance
- β Balance Aggregation - Sum balances by token ID
- β Display Formatting - Format tokens for UI display
- β Token Enrichment - Add metadata for UI rendering
- β Fee Estimation - Calculate fees for 3-transaction sequence
- β UTXO Selection - Choose wallet UTXOs for transfers
- β Transaction Building - Build atomic transfer sequence
- β Comprehensive Testing - 240 tests, 76% coverage
- β API Documentation - Auto-generated with TypeDoc
- β Quick Start Guide - Getting started examples
- β Troubleshooting - Common issues & solutions
- π Transaction Broadcasting - Send transfers to Bitcoin network
- π Witness Script Signing - Sign witness scripts with keys
- π Multi-Signature Support - Support for multisig addresses
- π Advanced Compliance - Frozen/sanctioned token checks
- π Performance Optimization - Cache & batch operations
npm install @tsb-protocol/sdkRequirements:
- Node.js 16+
- TypeScript 4.9+
- Bitcoin Core 0.17+ (for RPC)
import { BitcoinRPC, TSBClient } from '@tsb-protocol/sdk';
const rpc = new BitcoinRPC({
host: 'localhost',
port: 18332, // testnet
username: 'admin',
password: 'password',
network: 'testnet',
});
const client = new TSBClient({ rpc });import { TokenScanner } from '@tsb-protocol/sdk';
const scanner = new TokenScanner(rpc);
const tokens = await scanner.scanAddresses([
'tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6x5dqh',
]);
console.log(`Found ${tokens.length} tokens`);import { TokenValidator, TokenFormatter } from '@tsb-protocol/sdk';
const validator = new TokenValidator();
const formatter = new TokenFormatter();
tokens.forEach(token => {
const result = validator.validateToken(token);
const display = formatter.formatAmount(Number(token.amount));
console.log(`${token.tokenId}: ${display} (valid: ${result.valid})`);
});import { FeeEstimator } from '@tsb-protocol/sdk';
const bitcoinNeeded = FeeEstimator.calculateBitcoinNeeded(
2, // satoshis per vByte
1, // input count
0 // output count (no change)
);
console.log(`Bitcoin needed: ${bitcoinNeeded} satoshis`);- Quick Start Guide - Complete usage examples
- Troubleshooting - Common issues & solutions
- API Reference - Complete API documentation
- Architecture - System design & components
βββββββββββββββββββββββββββββββββββββββββββββββ
β TSB SDK (TypeScript) β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ β
β β Scanner βββββΆβ Parser β β
β ββββββββββββββββ ββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββ β
β β Validator βββββΆβ Aggregator β β
β ββββββββββββββββ ββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββ β
β β Formatter βββββΆβ Enricher β β
β ββββββββββββββββ ββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββ β
β β Transfer Module β β
β β - FeeEstimator β β
β β - UTXOSelector β β
β β - TransactionBuilder β β
β ββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ β
β β Bitcoin RPC β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
| Class | Purpose |
|---|---|
| BitcoinRPC | Communicate with Bitcoin node |
| TSBClient | Main SDK entry point |
| TokenScanner | Scan addresses for tokens |
| TokenParser | Parse token data from scripts |
| TokenValidator | Validate token structure |
| TokenFormatter | Format tokens for display |
| TokenEnricher | Add UI metadata |
| BalanceAggregator | Sum balances by ID |
| FeeEstimator | Calculate transfer fees |
| UTXOSelector | Select UTXOs for transfers |
| TransactionBuilder | Build transfer transactions |
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test
npm test -- TokenScanner
# Watch mode
npm test -- --watch- 240 tests total
- 76.11% code coverage
- Unit tests - 130 tests
- Edge cases - 72 tests
- Integration tests - 10 tests
- E2E workflow - 24 tests
const rpc = new BitcoinRPC(config);
// Make RPC calls
const result = await rpc.call('getblockcount', []);const scanner = new TokenScanner(rpc);
// Scan addresses
const tokens = await scanner.scanAddresses(addresses);const validator = new TokenValidator();
// Validate token
const result = validator.validateToken(token);// Calculate fees
const bitcoinNeeded = FeeEstimator.calculateBitcoinNeeded(
feeRate, // satoshis per vByte
inputCount, // number of inputs
outputCount // number of outputs
);For detailed API docs, see docs/api/README.md
npm run buildnpm run lintnpm run docstsb-sdk/
βββ src/
β βββ core/ # Bitcoin RPC, main client
β βββ scanner/ # Token scanning & parsing
β βββ transfer/ # Transfer module
β βββ display/ # Formatting & enrichment
β βββ utils/ # Utilities (scripts, addresses, hashing)
β βββ types/ # TypeScript types
β βββ errors/ # Error classes
βββ tests/
β βββ unit/ # Unit tests
β βββ edge-cases/ # Edge case tests
β βββ integration/ # Integration tests
βββ docs/
β βββ api/ # Generated API docs
βββ QUICKSTART.md # Quick start guide
βββ TROUBLESHOOTING.md # Troubleshooting guide
βββ README.md # This file
- Bitcoin Core 0.17+
- RPC enabled
- Testnet or Mainnet
# bitcoin.conf
server=1
rpcuser=admin
rpcpassword=password
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
- Node 16+
- npm 7+
import {
BitcoinRPC,
TokenScanner,
TokenValidator,
TokenFormatter,
FeeEstimator,
} from '@tsb-protocol/sdk';
async function workflow() {
// Setup
const rpc = new BitcoinRPC({
host: 'localhost',
port: 18332,
username: 'admin',
password: 'password',
network: 'testnet',
});
// Scan
const scanner = new TokenScanner(rpc);
const tokens = await scanner.scanAddresses(['tb1ptest']);
// Validate
const validator = new TokenValidator();
tokens.forEach(token => {
const result = validator.validateToken(token);
console.log(`Valid: ${result.valid}`);
});
// Format
const formatter = new TokenFormatter();
tokens.forEach(token => {
console.log(formatter.formatAmount(Number(token.amount)));
});
// Estimate fees
const fees = FeeEstimator.calculateBitcoinNeeded(2, 1, 0);
console.log(`Fees: ${fees} satoshis`);
}
workflow().catch(console.error);Having issues? Check the Troubleshooting Guide for common problems and solutions.
| Phase | Component | Status |
|---|---|---|
| 1-5 | Core Infrastructure | β Complete |
| 6-7 | Transfer Module | β Complete |
| 8 | Testing & QA | β Complete |
| 9 | Documentation | β Complete |
| 10-15 | Launch & Post-Launch | π Planned |
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Run
npm testto verify - Submit a pull request
MIT - See LICENSE file
- Issues: GitHub Issues
- Docs: API Reference
- Guide: Quick Start
- Help: Troubleshooting
Version: 0.1.0
Last Updated: October 26, 2025
Status: π§ Under Development (Pre-Release)
Tests: 240 passing β
Coverage: 76.11% β
Build: Passing β