The Script and the Stack: Bitcoin's Dynamic Duo
Imagine you're following a recipe to bake a cake. The recipe () tells you what to do, and your kitchen counter () is where you place and use your ingredients and tools.
The : Your Bitcoin Recipe
A script is like a recipe for spending Bitcoin. It's a set of instructions (called ) that define the conditions for using your Bitcoin.
Example of a (the recipe):
OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG


The : Your Bitcoin Kitchen Counter
The stack is like your kitchen counter. It's where you put your ingredients (data) as you follow the recipe. You always use the item on top first, just like in cooking.
How the stack works:
1. You start with an empty counter []
2. Add ingredients as the recipe says
3. Use or combine ingredients from the top
4. Keep going until the recipe is complete
Putting it All Together: Baking Your Bitcoin Transaction
When you want to spend Bitcoin, your wallet creates an (like gathering your ingredients). This is combined with the (the recipe) of the Bitcoin you want to spend. If you follow the recipe correctly with the right ingredients, you can spend the Bitcoin!
The Recipe vs. The Ingredients: An Important Distinction
In our Bitcoin kitchen:
- The recipe () contains both cooking instructions () and a list of ingredients (data).
- Only the ingredients go on your kitchen counter () .
- As you follow the recipe, you perform actions (the 'opcodes') using the ingredients on your counter, but the instructions themselves never go on the counter.
For example, when you see OP_DUP in the recipe, you duplicate the top item on your counter, but OP_DUP itself stays in the recipe book, not on the counter.
This distinction is key for understanding how Bitcoin scripts work and for writing them correctly.
Key Concept: Bitcoin's Universal Cookbook and Kitchen Guidelines
Imagine Bitcoin as a global kitchen with two important elements:
- The Universal Cookbook, aka: These are the fundamental, unchanging recipes that every Bitcoin chef must follow exactly. They define what makes a transaction or block valid in the Bitcoin network.
- The Kitchen Guidelines, aka: These are like flexible guidelines that each Bitcoin kitchen (node) can adjust. They determine which transactions a node will accept or relay, but don't affect the validity of blocks or confirmed transactions.
While the Universal Cookbook ensures everyone creates the same basic Bitcoin dishes, the Kitchen Guidelines allow node operators to customize how they handle certain non-core functions. This flexibility lets nodes adapt to network conditions and their own preferences, while still maintaining the core rules of Bitcoin.