Bitcoin Script Programming
Bitcoin has its own programming language, and it is intentionally limited. No loops, no recursion, no Turing completeness. Every limitation is a security decision — the fewer things that can go wrong, the fewer things will go wrong.
Learn Bitcoin's scripting language and how to create custom transaction conditions.
Script Basics:
- •Stack-based: Operations manipulate a stack
- •Forth-like: Reverse Polish notation
- •Deliberately limited: No loops (Turing incomplete)
- •Predicate: Returns true/false
Example P2PKH Script:
`scriptPubKey:` `OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG`
`scriptSig:` `<signature> <publicKey>`
Execution flow: 1. Signature and public key pushed to stack 2. OP_DUP duplicates public key 3. OP_HASH160 hashes the public key 4. Compare with stored hash 5. Verify signature
Advanced Script Features:
- •OP_IF/OP_ELSE: Conditional execution
- •OP_CHECKMULTISIG: M-of-N signatures
- •OP_CHECKLOCKTIMEVERIFY: Time locks
- •OP_CHECKSEQUENCEVERIFY: Relative time
- •OP_RETURN: Provably unspendable outputs
These enable complex smart contracts like escrow, inheritance, and atomic swaps.
Bitcoin Script enables surprisingly powerful functionality within its constraints: multisig, timelocks, hash locks, and conditional spending. These building blocks combine to create complex financial instruments.
Test Your Knowledge
5 questions · Passing score: 75%
Enjoying these lessons?
Get a free Bitcoin lesson in your inbox every week. Join thousands of learners.
Free forever. No spam. Unsubscribe anytime.