Start your career in bitcoin open source — ₿OSS

APPLY TODAY

Stack

A stack is a Last-In-First-Out (LIFO) data structure. Think of it like a stack of plates:

  • You add (push) new plates to the top.
  • You remove (pop) plates from the top.

Let's visualize this with our Bitcoin Stack component.
Try pushing some values onto the stack and see how they stack up!

Bitcoin Stack Simulator
Stack (Last-In-First-Out):

Stack is empty

2. Basic Stack Operations

Bitcoin's script uses stack operations to process data. Let's explore two operations as an example:

OP_ADD: pops the top two values from the stack, adds them, and pushes the result back.

  1. Push the number 3 onto the stack
  2. Push the number 4 onto the stack
  3. Click the OP_ADD button
Bitcoin Stack Simulator
Available Operations:
Stack (Last-In-First-Out):

Stack is empty

OP_EQUAL: compares the top two stack items. If they're equal, it pushes 1 (true), otherwise 0 (false).

  1. Push the number 5 twice
  2. Click the OP_EQUAL button
Bitcoin Stack Simulator
Available Operations:
Stack (Last-In-First-Out):

Stack is empty

Now try with different numbers!

Suggest Edits