Practical overview
When it fits
Use it when studying Bitcoin Script fundamentals through small code examples and transaction-script puzzles.
Who it is for
- Developers learning the stack-based mechanics of Bitcoin Script.
- Readers studying how unlocking and locking transaction scripts combine.
Documented uses
- Trace how simple operations push, pop, and transform stack values.
- Relate Ruby examples to Bitcoin Script notation and opcodes.
- Work through a transaction-script puzzle involving an unlocking input and a locking output.
Requirements & limits
The repository is public and identifies its license as CC0-1.0.
- Examples are written in Ruby and focus on a simple stack machine.
- The material explains concepts and examples; it does not establish a packaged library, API, or interactive interface.
- The repository describes Bitcoin Script as left-to-right and without loops.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Build a minimal Ruby stack machine for Bitcoin Script operations
Model OP_2 and OP_ADD to compute 2 + 2 on a stack.
Before you start
- Ruby, as used by the documented example.
- A stack supporting push and pop operations.
Steps
Initialize an empty stack.
Define op_2 to push the number 2 onto the stack.
Define op_add to pop the top two values, add them, and push the result.
Call op_2 twice, then op_add; inspect the stack result.
Expected outcome
The stack contains [4] after the two pushes and addition.
Guide limitations
- This is a minimal educational stack-machine example, not a packaged library or a documented Bitcoin transaction execution interface.
- The example covers only the two operations shown.
Work through the two-part ? + 2 = 4 stack puzzle
Represent an unlock value and a lock-side script that checks whether adding 2 produces 4.
Before you start
- Ruby stack operations using push and pop.
- Definitions for op_2, op_add, op_4, and op_equal, as shown in the example.
Steps
Initialize an empty stack.
In the ScriptSig (input/unlock) part, push the missing value onto the stack.
In the ScriptPubKey (output/lock) part, run op_2, op_add, op_4, and op_equal in that order.
Inspect the final stack value; the example describes 1 as true.
Expected outcome
For the puzzle value 2, the operations leave [1] on the stack.
Guide limitations
- The puzzle is an educational stack-machine illustration; it does not document a complete transaction, network interaction, or production validation procedure.
- Bitcoin Script is described as stack-based and intentionally not Turing-complete, with no loops.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 17 October 2026
- Original website title
- openblockchains/programming-bitcoin-script · Official homepage title · retained in its source language

