Locking Script Overview
The Locking Script (ScriptPubKey)
Every transaction output in Bitcoin is protected by a small program called a ScriptPubKey. This script defines the mathematical conditions that must be met to spend the coins in the future.
1. The Purpose of ScriptPubKey
ScriptPubKey is known as the "Locking Script." Unlike a traditional bank account where you have a "balance," Bitcoin consists of billions of these locked outputs.
-
The Lock: ScriptPubKey (Found in the Output).
-
The Key: ScriptSig (Provided by the future spender).
2. Programmable Money
Because ScriptPubKey is a script (not just an address), it allows Bitcoin to be "programmable." You can create locks that require:
-
A single digital signature (P2PKH).
-
Multiple signatures from a group (Multi-Sig).
-
A password (Hashlock).
-
A specific date to pass (Timelock).
3. Storage in the UTXO Set
When a node verifies the blockchain, it keeps a database of every unspent ScriptPubKey. This is the "Ground Truth" of who owns what. When you see your balance in a wallet, the wallet is actually just summing up all the satoshis attached to ScriptPubKeys that your private key can unlock.
4. Location in the Hex
In a raw transaction output, the ScriptPubKey follows the 8-byte Value field.
[8 Bytes Value][VarInt ScriptLen][ScriptPubKey Bytes]
| Property | Value |
|---|---|
| Role | Locking Script |
| Location | Transaction Output |
| Contents | Opcodes and Data |
| Nickname | The Lock |
In the next section, we will look at the Standard Script Types used in the protocol.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: