Learn Bitcoin Script through hands-on experimentation with real testnet transactions. Understand how Bitcoin's scripting language enables custom spending conditions, multisig wallets, timelocks, and more.
- bitcoinjs-lib - JavaScript Bitcoin library
- Hiro's multisig repo - Stacks-over-Bitcoin multisig tools
- Testnet - Safe environment for experimentation
- Web Interface - Transaction creation and signing
- P2SH (Pay-to-Script-Hash) - How Bitcoin wraps complex scripts
- Redeem Scripts - The actual spending conditions
- OpCodes - Bitcoin Script instructions
- Stack Operations - How Bitcoin Script executes
- Multisig - Multiple signatures required
- Timelocks - Time-based spending conditions
- Escrow - Dispute resolution mechanisms
- Hash Locks - Secret-based spending (HTLCs)
- Custody Solutions - Secure key management
- Lightning Network - Payment channels
- Atomic Swaps - Cross-chain transactions
- Smart Contracts - Programmable money
# Basic 2-of-2 multisig
node scripts/multisig.js
# Timelock script
node scripts/timelock.js
# Escrow script
node scripts/escrow.js
# Hash lock script
node scripts/hashlock.js- Get testnet coins from faucets (see
testnet/README.md) - Send coins to your generated addresses
- Monitor on testnet block explorers
- Use the web interface to create transactions
- Sign with your private keys
- Broadcast to testnet
OP_2 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG
- Requires 2 signatures from 2 public keys
- Used for shared custody and security
<locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG
- Funds locked until specified time
- Used for time-based releases and escrow
OP_SHA256 <hash> OP_EQUALVERIFY <pubkey> OP_CHECKSIG
- Requires knowledge of secret (preimage)
- Used for atomic swaps and Lightning Network
- Input Script - Provides data and signatures
- Output Script - Defines spending conditions
- Execution - Bitcoin validates the combination
- Result - Transaction succeeds or fails
OP_CHECKSIG- Verify signatureOP_CHECKMULTISIG- Verify multiple signaturesOP_CHECKLOCKTIMEVERIFY- Check timelockOP_SHA256- Hash operationOP_EQUALVERIFY- Verify equality
- Privacy - Script hash hides spending conditions
- Efficiency - Smaller transaction sizes
- Flexibility - Complex scripts without revealing details
- Create different multisig configurations (2-of-3, 3-of-5)
- Experiment with timelock durations
- Test script validation with wrong signatures
- Combine multiple conditions (multisig + timelock)
- Create custom escrow scenarios
- Build hash lock contracts
- Design your own script opcodes
- Create complex conditional logic
- Explore Lightning Network scripts
btc-script-lab/
├── scripts/ # Bitcoin Script examples
│ ├── multisig.js # 2-of-2 multisig
│ ├── timelock.js # Time-based spending
│ ├── escrow.js # Dispute resolution
│ └── hashlock.js # Secret-based spending
├── multisig-stx-btc/ # Web interface for Stacks
├── testnet/ # Testnet guides and tools
└── notes.md # This learning guide
- Mastering Bitcoin - Chapter 6: Transactions
- Bitcoin Script Tutorial
- Lightning Network Scripts
- Run the examples - Start with
multisig.js - Fund your scripts - Get testnet coins and send them
- Test spending - Use the web interface to create transactions
- Experiment - Try different script combinations
- Build - Create your own custom scripts
- Explore - Learn about Lightning Network and Layer 2
- Start simple - Begin with basic multisig
- Test everything - Use testnet for all experiments
- Read the code - Understand how scripts are constructed
- Experiment freely - Testnet coins have no value
- Document your learning - Keep notes on what you discover
Happy scripting! 🚀