Bitcoin’s blockchain is a decentralized, immutable ledger that records every transaction in a secure and transparent way. At the heart of this system lies a powerful yet often overlooked component: Bitcoin transaction scripts. These scripts are what make Bitcoin more than just digital cash—they enable programmable money, laying the foundation for smart contracts and advanced financial logic on the blockchain.
In this article, we’ll explore how Bitcoin transactions work at a script level, understand the role of UTXOs (Unspent Transaction Outputs), and demystify how ownership is verified through cryptographic scripting.
How Bitcoin Transactions Work
Every block in the Bitcoin blockchain contains one or more transactions (Tx). Each transaction represents a transfer of value from one party to another. The first transaction in any block is special—it's called the Coinbase transaction, which rewards the miner with newly minted bitcoins and transaction fees. This transaction has no input, so its previous hash is set to 0000...0000.
All other transactions have one or more inputs (TxIn) and outputs (TxOut). Each input references a previous transaction output by its hash and index, forming a chain of ownership.
👉 Discover how blockchain scripting powers real-world financial innovation
For example:
Tx: abcd...1234
┌─────────────────────┬───────────────────────┐
│ TxIn │ TxOut │
├─────────────┬───────┼──────┬────────────────┤
│ prev hash │ index │ btc │ pkScript │
├─────────────┼───────┼──────┼────────────────┤
│ 2016...a3c5 │ 3 │ 0.15 │ OP_DUP a1b2... │
└─────────────┴───────┴──────┴────────────────┘This creates a link back to an unspent output—known as a UTXO—that the sender wants to spend.
What Is a UTXO?
A UTXO (Unspent Transaction Output) is an output from a prior transaction that hasn’t been spent yet. It’s essentially a “coin” waiting to be used as an input in a future transaction.
Bitcoin doesn’t use accounts like traditional banking systems. Instead, it tracks balances through UTXOs. When Alice receives 0.15 BTC from Bob, she doesn’t get credited to an “account.” Instead, Bob creates a new UTXO with a locking script (pkScript) that defines who can unlock and spend it.
But how does Alice prove she owns that UTXO?
The Role of Bitcoin Scripts
Bitcoin uses a simple stack-based scripting language to define conditions for spending outputs. Every output includes a scriptPubKey (or pkScript), which acts as a lock. To spend it, the spender must provide a scriptSig (signature script) that unlocks it.
When Bob sends 0.15 BTC to Alice, he creates an output with a script like:
OP_DUP OP_HASH160 abcd1234...9876 OP_EQUALVERIFY OP_CHECKSIGHere:
abcd1234...9876is the hash of Alice’s public key (her Bitcoin address).- The script ensures only someone with the corresponding private key can spend the funds.
To spend this UTXO, Alice must provide:
- Her digital signature (proving knowledge of the private key)
- Her public key
These two elements form the scriptSig in her new transaction.
Verifying a Transaction: Step-by-Step Script Execution
Let’s examine the famous Pizza Transaction, where someone paid 10,000 BTC for two pizzas. The input script (sigScript) provided:
<signature> <public key>The referenced output had this locking script:
OP_DUP OP_HASH160 46af3fb4...6829 OP_EQUALVERIFY OP_CHECKSIGBitcoin verifies this by combining both scripts and running them on a stack-based virtual machine.
Step 1: Push Signature and Public Key
Initial stack:
[pubkey]
[sig]Step 2: Execute OP_DUP
Duplicates the top item (public key):
[pubkey]
[pubkey]
[sig]Step 3: Execute OP_HASH160
Hashes the top public key using SHA-256 + RIPEMD-160:
[hash(pubkey)]
[pubkey]
[sig]Step 4: Push Expected Hash
Now push the target hash (46af3fb4...6829) from the script:
[expected_hash]
[hash(pubkey)]
[pubkey]
[sig]Step 5: Execute OP_EQUALVERIFY
Compares the two hashes. If equal, they’re removed; otherwise, verification fails.
Step 6: Execute OP_CHECKSIG
Verifies the signature against the message hash and public key using ECDSA.
If all steps pass, the transaction is valid.
👉 Learn how cryptographic verification secures your digital assets
Advanced Scripting Capabilities
Bitcoin’s scripting language may be intentionally limited (non-Turing complete), but it supports powerful use cases:
✅ Multi-Signature Wallets
A multisig script like:
2 <pubKey1> <pubKey2> <pubKey3> 3 OP_CHECKMULTISIGRequires at least 2 out of 3 signatures to spend. This enhances security—ideal for shared wallets or custodial services where both user and provider must sign.
✅ Time-Locked Transactions
Using OP_CHECKLOCKTIMEVERIFY, outputs can be locked until a specific time or block height. This enables escrow services, delayed payments, or recurring disbursements—similar to automated trust agreements.
✅ Hash-Based Locks
Some scripts require revealing preimages of hashes:
OP_HASH256 <hash> OP_EQUALWhoever provides data that hashes to <hash> can claim the funds. This enables atomic swaps and cross-chain trading without intermediaries.
Why Scripting Matters: Beyond Simple Payments
Bitcoin scripting transforms cryptocurrency from simple peer-to-peer cash into a platform for programmable money. By encoding spending conditions directly into transactions, Bitcoin enables:
- Secure escrow systems
- Decentralized custody solutions
- Trustless multi-party agreements
- Foundation for Layer-2 protocols (e.g., Lightning Network)
This concept foreshadowed modern smart contracts seen on platforms like Ethereum—but with stronger security due to simplicity and immutability.
Frequently Asked Questions
What is a Bitcoin script?
A Bitcoin script is a set of instructions written in Bitcoin’s stack-based language that defines how a transaction output can be spent. It ensures only authorized parties can transfer funds.
How does OP_CHECKSIG work?
OP_CHECKSIG verifies an ECDSA signature against a message (the transaction data) and a public key. It returns true if the signature matches, proving ownership without revealing the private key.
Can anyone create custom Bitcoin scripts?
Yes, technically—but most wallets use standard templates (like P2PKH or P2SH). Non-standard scripts may not be relayed by nodes unless explicitly enabled.
What is the difference between scriptSig and scriptPubKey?
scriptSig is provided by the spender (unlocking script), while scriptPubKey is part of the output (locking script). Together, they are executed to verify validity.
Why isn’t Bitcoin considered Turing complete?
Bitcoin’s script lacks loops and complex control flow to prevent infinite execution and ensure predictability. This design prioritizes security and finality over flexibility.
Are Bitcoin scripts still evolving?
Yes. Upgrades like SegWit, Taproot, and Schnorr signatures have enhanced scripting capabilities, enabling more privacy and efficiency while maintaining backward compatibility.
Final Thoughts
Bitcoin transaction scripts are the backbone of its trustless, decentralized architecture. They allow users to securely transfer value without relying on intermediaries, using cryptography and code as enforcement mechanisms.
From basic payments to complex multi-signature wallets and time-locked contracts, scripting unlocks endless possibilities within Bitcoin’s robust framework.
As blockchain technology evolves, understanding these fundamentals becomes crucial—not just for developers, but for anyone interested in the future of finance.
👉 Explore how programmable money is reshaping global finance