SPV
Overview
Purpose
Basic Usage
Verify Transaction with Merkle Proof
import { MerklePath, Transaction, ChainTracker } from '@bsv/sdk';
// Parse merkle proof from hex
const merklePath = MerklePath.fromHex('fed7c509000a02fddd01...');
// Get the transaction
const tx = Transaction.fromHex('...');
// Attach merkle proof to transaction
tx.merklePath = merklePath;
// Verify the transaction is in the merkle tree
const txid = tx.id('hex');
const computedRoot = merklePath.computeRoot(txid);
console.log('Computed merkle root:', computedRoot);
console.log('Block height:', merklePath.blockHeight);Implement ChainTracker
Verify SPV Proof
Validate Block Headers
Key Features
1. ChainTracker Interface
2. Merkle Path Verification
3. Transaction SPV Envelope (BRC-8)
4. Header Chain Validation
API Reference
ChainTracker Interface
MerklePath Class
BlockHeader Class
Common Patterns
Pattern 1: SPV Client Implementation
Pattern 2: SPV Proof Service
Pattern 3: Multi-Source Chain Tracker
Security Considerations
Performance Considerations
Related Components
Best Practices
Troubleshooting
Issue: Merkle Root Mismatch
Issue: Missing Block Height
Further Reading
Status
Last updated
