Decoding #2: Locking & Unlocking Scripts 🔒🔓
- We're starting a series of posts to teach you about Bitcoin development. We'll be sharing them here. Tell us how we can make it better!
- If you prefer reading on the website, check 👉 https://bitcoindevs.xyz/decoding/locking-unlocking
Locking and Unlocking Scripts define how transactions can be spent.
1- Locking Script
A script that specifies spending conditions for a transaction output.
Example:
OP_2 OP_ADD OP_4 OP_EQUAL
Condition: Add 2, check if it equals 4.
2- Unlocking Script
A script that provides the data to satisfy the conditions in the locking script.
Example:
OP_2
Value: 2 satisfies the locking script condition above.
3- Execution
- Unlocking script runs first, followed by locking script.
- If the stack contains
TRUE (1)
, the transaction is valid.
To see how this works in an interactive way, visit https://bitcoindevs.xyz/decoding/locking-unlocking