ts-sdk

Chain Tracking

How the BSV TypeScript SDK interacts with the Bitcoin network to retrieve transaction and blockchain data.

Chain Tracker Concept

A chain tracker provides access to Bitcoin blockchain data without running a full node:

import { WhatsOnChain } from '@bsv/sdk'

// Create a chain tracker
const chainTracker = new WhatsOnChain('mainnet')

// Get transaction data
const txData = await chainTracker.getTransaction('txid')

Key Functions

Transaction Lookup

UTXO Queries

Block Information

Network Status

SPV Integration

Chain trackers enable SPV (Simplified Payment Verification):

Multiple Providers

The SDK supports multiple chain tracking services:

// Primary and fallback providers
const config = {
  chainTracker: {
    provider: 'WhatsOnChain',
    network: 'mainnet',
    fallbacks: ['GorillaPool', 'TAAL']
  }
}

Benefits

Scalability

Reliability

Performance

Common Patterns

Transaction Verification

// Verify a transaction exists
const exists = await chainTracker.getTransaction(txid)
if (exists) {
  // Transaction is confirmed on-chain
}

UTXO Validation

// Check if UTXO is still unspent
const utxo = await chainTracker.getUTXO(txid, outputIndex)
if (utxo) {
  // UTXO is available for spending
}

Error Handling

Chain tracker operations can fail due to:

The SDK provides automatic retry and failover mechanisms.

Configuration

Chain trackers can be configured for:

Next Steps