ts-sdk

SPV Verification

Understanding Simplified Payment Verification and how it enables lightweight Bitcoin applications.

What is SPV?

SPV allows verification of Bitcoin transactions without downloading the entire blockchain:

How SPV Works

1. Block Headers

Download only block headers (80 bytes each) instead of full blocks:

// Block header contains merkle root
const header = await chainTracker.getBlockHeader(blockHash)

2. Merkle Proofs

Verify transaction inclusion using merkle proofs:

import { MerklePath } from '@bsv/sdk'

// Verify transaction is in block
const proof = MerklePath.fromHex(proofHex)
const isValid = proof.verify(txid, merkleRoot)

3. Transaction Verification

Combine proofs with block headers for full verification:

import { Transaction } from '@bsv/sdk'

// Verify transaction with SPV
const isValid = await Transaction.verify(
  transaction,
  chainTracker,
  { merkleProof: proof }
)

Merkle Trees

Bitcoin uses merkle trees to efficiently prove transaction inclusion:

Security Model

SPV provides strong security guarantees:

Trade-offs

Advantages

Limitations

SDK Implementation

The SDK provides comprehensive SPV support:

// Configure SPV verification
const config = {
  spv: {
    enabled: true,
    maxMemoryLimit: 100000000, // 100MB
    chainTracker: chainTracker
  }
}

// Verify transaction with SPV
const result = await transaction.verify(chainTracker, {
  merkleProof: proof,
  blockHeader: header
})

BEEF Integration

SPV works seamlessly with BEEF format:

Next Steps