Code Features Overview
This directory contains reusable code snippets and complete examples demonstrating specific BSV blockchain functionality. These code features are used as building blocks throughout the learning paths.
Purpose
Code Features provide:
Practical Examples: Working code that demonstrates real-world usage
Reusable Snippets: Copy-paste ready code for common tasks
Best Practices: Implementation patterns that follow BSV conventions
Modular Components: Code that can be combined for complex solutions
Organization
Features are organized by functionality and use case. Each feature includes:
Complete, runnable code examples
Explanation of what the code does
Prerequisites and dependencies
Common variations and extensions
Links to related SDK components
Available Code Features
Transaction Operations
Transaction Creation - Create basic transactions
Transaction Building - Build complex transactions
Transaction Signing - Sign transactions
Transaction Broadcasting - Broadcast transactions
Transaction Chains - Create transaction chains
Standard Transactions - Common transaction patterns
Batch Operations - Process multiple transactions
UTXO Management - Manage unspent outputs
Key Management & Signing
Generate Private Key - Create new private keys
BRC-42 Key Derivation - Derive protocol-specific keys
Sign Transaction - Sign with private keys
Message Signing - Sign arbitrary messages
Multi-Signature - Multi-signature transactions
Script Templates
P2PKH Template - Standard payment script
Custom Scripts - Build custom locking scripts
Custom Templates - Custom script templates
OP_RETURN - Data storage on-chain
Blockchain Verification
SPV - Simplified Payment Verification
SPV Verification - Verify merkle proofs
SPV Validation - Validate SPV proofs
Broadcasting
Broadcast with ARC - Send transactions via ARC
Wallet Operations
Create Wallet - Initialize new wallet
Advanced Features
Payment Channels - Bi-directional payment channels
Payment Distribution - Distribute payments
Payment Processing - Process payments
Atomic Swaps - Trustless token exchanges
Smart Contracts - Smart contract patterns
Double-Spend Detection - Detect double-spends
Content Paywall - Micropayment paywalls
E-commerce Integration - Online store integration
Marketplace - Peer-to-peer marketplace
How to Use
Each code feature directory contains:
README.md- Feature overview and explanationexample.ts- Complete TypeScript examplevariations.md- Alternative approaches (if applicable)
In Learning Paths
Features are referenced in learning modules:
See [Transaction Creation](../../code-features/transaction-creation/README.md) for a complete example.As Templates
Copy the example code and adapt to your needs:
// From code-features/transaction-creation/example.ts
import { Transaction } from '@bsv/sdk'
// ... rest of the codeCode Style
All examples follow these conventions:
TypeScript: Fully typed for clarity
Async/Await: Modern async patterns
Error Handling: Proper try/catch blocks
Comments: Explain key concepts
Imports: Show all required dependencies
Testing Examples
Most features include test cases showing expected behavior:
// example.test.ts
describe('Transaction Creation', () => {
it('should create a valid transaction', () => {
// test code
})
})Dependencies
Code features assume you have installed:
{
"@bsv/sdk": "^1.0.0"
}Additional dependencies are noted in each feature's README.
Contributing
When adding new code features:
Create a descriptive folder name (kebab-case)
Include working, tested code
Add comprehensive comments
Document prerequisites
Link related SDK components
Provide variations when useful
Feature Status
✅ Essential features documented
🚧 Additional features in progress
📋 Planned features
Related Documentation
SDK Components - API reference for components used in these examples
Learning Paths - Guided tutorials using these features
Last updated
