Introduction to Programmable Payments
Bitcoin transactions are fundamentally script-based, enabling programmable payments without intermediaries. Unlike traditional payments, Bitcoin transfers are executed by validating cryptographic scripts that lock and unlock digital assets. This guide explores the technical principles behind Bitcoin's programmable payments and their implications for blockchain technology.
How Bitcoin Transactions Work
Every Bitcoin transaction is recorded on the blockchain, where users can trace inputs/outputs via public keys. To spend an output (e.g., Alice paying Bob), the sender must:
- Sign the transaction with their private key.
- Broadcast it to miners for validation.
- Wait for confirmation once included in a block.
However, Bitcoin doesn’t directly send funds to recipient addresses. Instead, it uses locking scripts that specify:
"Whoever provides a valid unlocking script can spend these funds."
Example Locking Script
OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIGScript Execution: Step-by-Step
- Unlocking Script
Provides signature and public key (e.g.,48304502...14cf740f). - Locking Script
Verifies the public key hash matches the recipient address (e.g.,76a914dc...489c88ac). Validation Process
- Concatenate unlocking + locking scripts.
- Execute commands sequentially using a stack.
- Final stack must return
1(valid) or0(invalid).
Stack Operations
| Step | Instruction | Stack State |
|---|---|---|
| 1 | Push signature | [sig] |
| 2 | Push public key | [pubkey, sig] |
| 3 | OP_DUP | [pubkey, pubkey, sig] |
| 4 | OP_HASH160 | [pubkey_hash, pubkey, sig] |
| 5 | Push recipient hash | [recipient_hash, pubkey_hash, pubkey, sig] |
| 6 | OP_EQUALVERIFY | [pubkey, sig] (if hashes match) |
| 7 | OP_CHECKSIG | [1] (if signature is valid) |
Advanced Scripting Capabilities
Pay-to-Public-Key-Hash (P2PKH)
Standard Bitcoin transactions use P2PKH scripts to verify ownership via cryptographic signatures.
Multisig Transactions
Require multiple signatures to authorize spending. For example:
OP_2 <pk1> <pk2> <pk3> OP_3 OP_CHECKMULTISIGThis script allows spending if 2 of 3 authorized parties sign.
Puzzle Scripts
Conditional scripts can create "math puzzles" for spending outputs:
OP_HASH256 <target_hash> OP_EQUALSolved by providing data whose hash matches target_hash.
The Essence of Programmable Payments
Bitcoin’s script-based system enables:
- Trustless transactions: No intermediaries needed.
- Smart contracts: Auto-executing agreements (e.g., insurance, loans).
- Flexible conditions: Time-locked releases, multisig vaults.
👉 Explore real-world Bitcoin scripting examples
FAQ Section
Q1: What’s the difference between locking and unlocking scripts?
A: Locking scripts secure funds to conditions (e.g., a recipient’s address). Unlocking scripts satisfy those conditions (e.g., providing a valid signature).
Q2: Can Bitcoin scripts include loops or conditional logic?
A: No. Bitcoin scripts are deliberately Turing-incomplete for security, supporting only linear execution.
Q3: How do multisig wallets enhance security?
A: They distribute signing authority among multiple parties, reducing single-point-of-failure risks (e.g., lost keys).
Conclusion
Bitcoin’s programmable payments revolutionize finance by combining cryptographic security with scriptable conditions. From simple P2PKH transfers to complex multisig arrangements, these principles underpin decentralized applications and smart contracts.