Skip to content

Bitcoin and Bitcoin Cash Technical Guide for AI Agents (2025)

This document provides a comprehensive technical reference for AI Agents working with Bitcoin (BTC) and Bitcoin Cash (BCH) transaction systems, covering address types, multisig mechanisms, and transaction sending workflows.

Table of Contents

  1. Overview
  2. Address Types
  3. Multisig Mechanisms
  4. Transaction Sending Mechanisms
  5. Key Differences Between BTC and BCH
  6. Quick Reference Tables

Overview

Bitcoin (BTC) vs Bitcoin Cash (BCH)

FeatureBitcoin (BTC)Bitcoin Cash (BCH)
Fork DateOriginal (2009)August 2017 (hard fork from BTC)
Block Size1-4 MB (with SegWit)32 MB
SegWit Support✅ Yes (activated 2017)❌ No
Taproot Support✅ Yes (activated 2021)❌ No
Primary FocusStore of value, Layer 2 solutionsPeer-to-peer electronic cash
Core ImplementationBitcoin CoreBitcoin ABC / BCHN
Required Versionv22.0+ (for Taproot)v0.24.0+

Shared Characteristics

Both BTC and BCH share the following foundational properties:

  • UTXO Model: Unspent Transaction Output model for tracking ownership
  • ECDSA Signatures: secp256k1 elliptic curve for cryptographic operations
  • SHA-256 Mining: Same proof-of-work algorithm
  • Base58Check Encoding: For legacy address format encoding
  • Script Language: Bitcoin Script for transaction validation

Address Types

Bitcoin (BTC) Address Types

Bitcoin supports four main address types, each corresponding to different script types and BIP standards:

1. Legacy (P2PKH) - BIP44

Purpose: 44'
Derivation Path: m/44'/0'/account'/change/index
PropertyValue
Prefix1 (mainnet), m or n (testnet)
Length25-34 characters
EncodingBase58Check
Script TypePay-to-Public-Key-Hash
Example1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

ScriptPubKey Structure:

OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

Pros:

  • Maximum compatibility with all wallets/exchanges
  • Widely understood and documented

Cons:

  • Largest transaction size
  • Highest fees
  • No SegWit benefits

2. P2SH-SegWit (P2SH-P2WPKH) - BIP49

Purpose: 49'
Derivation Path: m/49'/0'/account'/change/index
PropertyValue
Prefix3 (mainnet), 2 (testnet)
Length34 characters
EncodingBase58Check
Script TypePay-to-Script-Hash wrapping SegWit
Example3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy

ScriptPubKey Structure:

OP_HASH160 <scriptHash> OP_EQUAL

Pros:

  • SegWit fee savings (~26% reduction)
  • Backward compatible with legacy wallets
  • Improved transaction malleability protection

Cons:

  • Not as efficient as native SegWit
  • More complex script structure

3. Native SegWit (P2WPKH) - BIP84

Purpose: 84'
Derivation Path: m/84'/0'/account'/change/index
PropertyValue
Prefixbc1q (mainnet), tb1q (testnet)
Length42 characters
EncodingBech32
Script TypePay-to-Witness-Public-Key-Hash
Examplebc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq

Witness Script Structure:

0 <20-byte pubKeyHash>

Pros:

  • Best pre-Taproot fee efficiency (~38% reduction)
  • Full SegWit benefits
  • Error detection with Bech32 checksum

Cons:

  • Some older wallets don't support sending to bc1q

4. Taproot (P2TR) - BIP86

Purpose: 86'
Derivation Path: m/86'/0'/account'/change/index
PropertyValue
Prefixbc1p (mainnet), tb1p (testnet)
Length62 characters
EncodingBech32m
Script TypePay-to-Taproot
SignatureSchnorr (BIP340)
Examplebc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr

Witness Script Structure:

1 <32-byte x-only pubKey>

Pros:

  • Best fee efficiency (~50% reduction for multisig)
  • Enhanced privacy (all spends look identical)
  • Schnorr signature aggregation (MuSig2)
  • Script path spending for complex contracts

Cons:

  • Requires Bitcoin Core v22.0+
  • Some exchanges still don't support withdrawal to bc1p

Bitcoin Cash (BCH) Address Types

Bitcoin Cash uses the CashAddr format (introduced 2018) with its own prefix and encoding:

1. CashAddr P2PKH

PropertyValue
Prefixbitcoincash:q (mainnet), bchtest:q (testnet)
Length~50 characters (with prefix)
EncodingCashAddr (modified Bech32)
Script TypePay-to-Public-Key-Hash
Examplebitcoincash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy

ScriptPubKey Structure:

OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

2. CashAddr P2SH

PropertyValue
Prefixbitcoincash:p (mainnet), bchtest:p (testnet)
Length~50 characters (with prefix)
EncodingCashAddr (modified Bech32)
Script TypePay-to-Script-Hash
Examplebitcoincash:pr0662zpd7vr936d83f64u629v886aan7c77r3j5v5

CashAddr Characteristics:

  • Case-insensitive (always lowercase recommended)
  • Built-in checksum for error detection
  • Network prefix prevents cross-chain sending errors
  • Can omit prefix when network is unambiguous

3. Legacy Format (Backward Compatible)

BCH can also use legacy Base58Check addresses (starts with 1 for P2PKH, 3 for P2SH), but CashAddr is strongly recommended to prevent accidental BTC/BCH cross-sends.


Multisig Mechanisms

Multisig Concepts

Definition: Multi-signature (multisig) requires M-of-N signatures to authorize a transaction.

Common Configurations:

  • 2-of-2: Both parties must sign (joint control)
  • 2-of-3: Any 2 of 3 parties must sign (recovery/escrow)
  • 3-of-5: Corporate treasury management

Bitcoin Multisig Types

1. Traditional P2SH Multisig (Legacy)

Address Prefix: 3 (mainnet)
Script Type: Pay-to-Script-Hash
BIP: BIP11, BIP16

Redeem Script Structure:

<M> <PubKey1> <PubKey2> ... <PubKeyN> <N> OP_CHECKMULTISIG

Example 2-of-3:

2 <PubKey1> <PubKey2> <PubKey3> 3 OP_CHECKMULTISIG

Characteristics:

PropertyValue
Maximum Keys15 (due to OP_CHECKMULTISIG limit)
Transaction Size~370-400 bytes (2-of-3)
PrivacyLow (multisig is visible on-chain)
Signature TypeECDSA

2. P2WSH Multisig (Native SegWit)

Address Prefix: bc1q (longer than P2WPKH)
Script Type: Pay-to-Witness-Script-Hash
BIP: BIP141, BIP143

Witness Script Structure:

0 <32-byte scriptHash>

Characteristics:

PropertyValue
Maximum Keys15
Transaction Size~270-300 bytes (2-of-3)
Fee Savings~27% vs P2SH
PrivacyLow (multisig visible)
Signature TypeECDSA

3. Taproot Multisig (Key Path)

With Taproot, multisig can be implemented in two ways:

A. Key Path Spending (MuSig2)

Address Prefix: bc1p
Script Type: Pay-to-Taproot (key path)
BIP: BIP340, BIP341, BIP327

MuSig2 Protocol (Two-Round):

Round 1: Nonce Generation (Parallel)
├── Signer 1 generates nonce
├── Signer 2 generates nonce
└── Signer N generates nonce


  Exchange public nonces


Round 2: Partial Signing (Sequential)
├── Signer 1 creates partial signature
├── Signer 2 creates partial signature
└── Signer N creates partial signature


  Aggregate into single signature

MuSig2 Characteristics:

PropertyValue
On-Chain AppearanceSingle signature (indistinguishable from single-sig)
Transaction Size~200-250 bytes
Fee Savings30-50% vs P2WSH multisig
PrivacyMaximum (looks like single-sig)
Signature TypeSchnorr (64 bytes)
FlexibilityN-of-N only (all signers required)

CRITICAL: Nonce Security

  • NEVER reuse nonces - Reusing a nonce leaks the private key
  • Generate fresh nonces for every transaction
  • Delete nonces after signing

B. Script Path Spending

For M-of-N (where M < N), Taproot uses script path:

Taproot Output Key = Internal Key + TapTweak(Merkle Root)

Script Tree Structure:

              Root
             /    \
        Branch    Leaf3
        /    \     (2-of-3 script)
    Leaf1   Leaf2
    (2-of-3) (2-of-3)

Characteristics:

  • Multiple spending conditions organized in Merkle tree
  • Only the used script path is revealed on-chain
  • Unused branches remain private

Bitcoin Cash Multisig

BCH supports only traditional P2SH multisig (no SegWit/Taproot):

Address Prefix: p (CashAddr)
Script Type: Pay-to-Script-Hash

Characteristics:

PropertyValue
Maximum Keys15
Transaction Size~370-400 bytes (2-of-3)
PrivacyLow
Signature TypeECDSA

Transaction Sending Mechanisms

UTXO Model

Both BTC and BCH use the UTXO (Unspent Transaction Output) model:

Transaction Structure:
┌──────────────────────────────────────────────┐
│ Version (4 bytes)                            │
├──────────────────────────────────────────────┤
│ Input Count (VarInt)                         │
├──────────────────────────────────────────────┤
│ Inputs[] (variable)                          │
│   ├── Previous TX Hash (32 bytes)            │
│   ├── Previous Output Index (4 bytes)        │
│   ├── ScriptSig Length (VarInt)              │
│   ├── ScriptSig (variable)                   │
│   └── Sequence (4 bytes)                     │
├──────────────────────────────────────────────┤
│ Output Count (VarInt)                        │
├──────────────────────────────────────────────┤
│ Outputs[] (variable)                         │
│   ├── Value (8 bytes)                        │
│   ├── ScriptPubKey Length (VarInt)           │
│   └── ScriptPubKey (variable)                │
├──────────────────────────────────────────────┤
│ Locktime (4 bytes)                           │
└──────────────────────────────────────────────┘

SegWit Transaction (BTC only):

┌──────────────────────────────────────────────┐
│ Version (4 bytes)                            │
├──────────────────────────────────────────────┤
│ Marker (1 byte) = 0x00                       │
│ Flag (1 byte) = 0x01                         │
├──────────────────────────────────────────────┤
│ Input Count (VarInt)                         │
├──────────────────────────────────────────────┤
│ Inputs[] (scriptSig is empty for SegWit)     │
├──────────────────────────────────────────────┤
│ Output Count (VarInt)                        │
├──────────────────────────────────────────────┤
│ Outputs[]                                    │
├──────────────────────────────────────────────┤
│ Witness[] (SegWit data)                      │
│   └── Per input: signatures and pubkeys      │
├──────────────────────────────────────────────┤
│ Locktime (4 bytes)                           │
└──────────────────────────────────────────────┘

Transaction Workflow

Standard Transaction Flow

1. Create Transaction
   └── Select UTXOs (inputs)
   └── Define outputs (recipients + change)
   └── Calculate fee

2. Sign Transaction
   └── For each input:
       └── Generate signature using private key
       └── Signature covers: outputs, input data, sighash

3. Broadcast Transaction
   └── Send to node/network
   └── Node validates and propagates
   └── Miners include in block

4. Confirmation
   └── Block mined containing transaction
   └── Each subsequent block adds confirmation

PSBT (Partially Signed Bitcoin Transaction)

BIP174 - Standard for offline signing and multi-party transactions

PSBT enables:

  • Offline/air-gapped signing
  • Hardware wallet integration
  • Multi-party signing coordination
  • Watch-only wallet workflows

PSBT Structure:

┌──────────────────────────────────────────────┐
│ Magic Bytes: "psbt" + 0xFF (5 bytes)         │
├──────────────────────────────────────────────┤
│ Global Map                                   │
│   ├── PSBT_GLOBAL_UNSIGNED_TX               │
│   ├── PSBT_GLOBAL_XPUB (optional)           │
│   └── PSBT_GLOBAL_VERSION                   │
├──────────────────────────────────────────────┤
│ Input Maps[] (one per input)                 │
│   ├── PSBT_IN_WITNESS_UTXO                  │
│   ├── PSBT_IN_PARTIAL_SIG                   │
│   ├── PSBT_IN_SIGHASH_TYPE                  │
│   ├── PSBT_IN_BIP32_DERIVATION              │
│   └── PSBT_IN_TAP_* (Taproot fields)        │
├──────────────────────────────────────────────┤
│ Output Maps[] (one per output)               │
│   ├── PSBT_OUT_BIP32_DERIVATION             │
│   └── PSBT_OUT_TAP_* (Taproot fields)       │
└──────────────────────────────────────────────┘

PSBT Workflow:

Creator (Watch Wallet - Online)

    │ 1. Create unsigned PSBT
    │    - Select UTXOs
    │    - Add witness data
    │    - Save as .psbt file

┌─────────────────────────────────┐
│ payment_15_unsigned_0_*.psbt    │
└─────────────────────────────────┘

    │ Transfer via USB/QR

Signer 1 (Keygen Wallet - Offline)

    │ 2. Sign with first key
    │    - Add partial signature

┌─────────────────────────────────┐
│ payment_15_unsigned_1_*.psbt    │
└─────────────────────────────────┘

    │ Transfer via USB/QR

Signer 2 (Sign Wallet - Offline)

    │ 3. Sign with second key
    │    - Add partial signature

┌─────────────────────────────────┐
│ payment_15_signed_2_*.psbt      │
└─────────────────────────────────┘

    │ Transfer via USB/QR

Finalizer (Watch Wallet - Online)

    │ 4. Finalize PSBT
    │    - Combine signatures
    │    - Create scriptSig/witness
    │    - Extract final transaction

    │ 5. Broadcast
    │    - Send to network

    Confirmed on blockchain

MuSig2 Transaction Workflow

For Taproot multisig with MuSig2:

Creator (Watch Wallet)

    │ 1. Create unsigned PSBT with MuSig2 metadata

┌─────────────────────────────────┐
│ payment_15_unsigned_0_*.psbt    │
└─────────────────────────────────┘


═══════════════════════════════════════
    ROUND 1: NONCE GENERATION (PARALLEL)
═══════════════════════════════════════

    ├──────┬──────┬──────┐
    ▼      ▼      ▼      ▼
  Signer1 Signer2 Signer3
    │      │      │
    │ Generate nonces (can run in parallel)
    │      │      │
    └──────┴──────┴──────┐

┌─────────────────────────────────┐
│ payment_15_nonce_0_*.psbt       │
│ (contains all 3 public nonces)  │
└─────────────────────────────────┘


═══════════════════════════════════════
    ROUND 2: PARTIAL SIGNING (SEQUENTIAL)
═══════════════════════════════════════

    │ All nonces must be collected first!

  Signer1 ─── Partial Sig 1 ───┐

  Signer2 ─── Partial Sig 2 ───┐

  Signer3 ─── Partial Sig 3 ───┐

┌─────────────────────────────────┐
│ payment_15_unsigned_3_*.psbt    │
│ (contains all partial sigs)     │
└─────────────────────────────────┘


═══════════════════════════════════════
    AGGREGATION & BROADCAST
═══════════════════════════════════════

Aggregator (Watch Wallet)

    │ Aggregate partial signatures → single Schnorr sig

┌─────────────────────────────────┐
│ payment_15_signed_3_*.psbt      │
│ (final 64-byte Schnorr sig)     │
└─────────────────────────────────┘

    │ Broadcast

  Blockchain (looks like single-sig tx!)

Bitcoin Cash Transaction Workflow

BCH uses a simpler workflow without PSBT (legacy raw transactions):

Creator (Watch Wallet)

    │ 1. Create raw transaction
    │    - Hex-encoded transaction

┌─────────────────────────────────┐
│ payment_15_unsigned_0_*.tx      │
│ (hex,prev_addresses format)     │
└─────────────────────────────────┘


Signer 1 (Keygen Wallet)

    │ 2. Sign with ECDSA
    │    - Create scriptSig

┌─────────────────────────────────┐
│ payment_15_unsigned_1_*.tx      │
└─────────────────────────────────┘


Signer 2 (Sign Wallet) [if multisig]

    │ 3. Add second signature

┌─────────────────────────────────┐
│ payment_15_signed_2_*.tx        │
└─────────────────────────────────┘


Broadcaster (Watch Wallet)

    │ 4. Send to network

  Confirmed on blockchain

Signature Types Comparison

SignatureAlgorithmSizeUsed By
ECDSAsecp256k1~71-72 bytes (DER encoded)BTC (legacy/SegWit), BCH
SchnorrBIP34064 bytes (fixed)BTC (Taproot only)

Schnorr Benefits:

  • Fixed 64-byte size (vs variable ECDSA)
  • Linearity enables signature aggregation
  • Batch verification is faster
  • Provably secure under standard assumptions

Key Differences Between BTC and BCH

Feature Comparison Matrix

FeatureBitcoin (BTC)Bitcoin Cash (BCH)
SegWit✅ Full support❌ Not implemented
Taproot✅ Full support❌ Not implemented
Schnorr Signatures✅ BIP340❌ Not available
MuSig2✅ BIP327❌ Not available
PSBT✅ BIP174⚠️ Limited support
Address FormatBech32/Bech32mCashAddr
Block Size1-4 MB (SegWit)32 MB
Transaction Malleability✅ Fixed (SegWit)⚠️ Still present
RBF✅ Replace-by-fee⚠️ Child-pays-for-parent

Implementation Differences in go-crypto-wallet

The codebase handles BTC and BCH through inheritance:

go
// Bitcoin Cash embeds and extends Bitcoin
type BitcoinCash struct {
    btc.Bitcoin  // Inherits all Bitcoin functionality
}

// BCH overrides chain parameters
func (b *BitcoinCash) initChainParams() {
    switch conf.Name {
    case chaincfg.TestNet3Params.Name:
        conf.Net = TestnetMagic  // BCH-specific magic
    case chaincfg.MainNetParams.Name:
        conf.Net = MainnetMagic
    }
}

Shared Code Path:

  • Transaction creation
  • UTXO selection
  • Fee calculation
  • Basic signing (ECDSA)

BTC-Only Features:

  • SegWit witness data handling
  • Taproot/Schnorr signing
  • MuSig2 nonce management
  • PSBT creation/parsing
  • Bech32/Bech32m encoding

BCH-Specific:

  • CashAddr encoding/decoding
  • Different network magic bytes
  • No witness data in transactions

Quick Reference Tables

Address Type Selection Guide

Use CaseBTC RecommendationBCH Recommendation
New wallet setupTaproot (bc1p)CashAddr P2PKH
Maximum compatibilityP2SH-SegWit (3)CashAddr P2PKH
Best feesTaproot (bc1p)CashAddr P2PKH
Simple multisigP2WSHP2SH
Private multisigMuSig2 TaprootN/A
Hardware walletNative SegWit (bc1q)CashAddr P2PKH

Multisig Selection Guide

RequirementBTC RecommendationBCH Recommendation
2-of-3 corporateP2WSH or Taproot script pathP2SH
N-of-N with privacyMuSig2 (Taproot)N/A
Maximum compatibilityP2SHP2SH
Best fee efficiencyMuSig2 (Taproot)N/A (use P2SH)
Threshold (M < N)Taproot script pathP2SH

Transaction Size Comparison (2-of-3 Multisig)

TypeSizeFee @ 10 sat/vBNotes
P2SH (BTC/BCH)~370 bytes~3,700 satsLegacy, most compatible
P2WSH (BTC)~270 bytes~2,700 satsSegWit, ~27% savings
MuSig2 (BTC)~215 bytes~2,150 sats42% savings, max privacy

Network Parameters

ParameterBTC MainnetBTC TestnetBCH MainnetBCH Testnet
P2PKH Prefix1m/nq (CashAddr)q (bchtest:)
P2SH Prefix32p (CashAddr)p (bchtest:)
Bech32 Prefixbc1tb1N/AN/A
Bech32m Prefixbc1ptb1pN/AN/A
Default Port833318333833318333
RPC Port833218332833218332

Project-Specific Guides

External References


Document Version: 1.0 Last Updated: 2025-01-07 Target Audience: AI Agents, Developers Applicable Versions: BTC Core v22.0+, BCH ABC v0.24.0+