Opcode number: 107
Short description: Move the top item from the main stack to the alternate stack.
OP_TOALTSTACK is used to manipulate stack items between the main stack and an alternate stack.
This page is not well developed. If you think you can contribute to this page, please consider helping us out by opening a pull request on the repo!
- Pop the top item from the main stack.
- Push this item onto the alternate stack.
The alternate stack is a secondary stack that scripts can use to store data temporarily. It operates independently of the main stack, allowing for more complex script operations.
- Temporary Storage: Scripts can use
OP_TOALTSTACKto temporarily store data that might be needed later in the script execution. This helps in organizing data and maintaining a clear main stack.
- Complex Script Logic: In scripts that require intricate logic and multiple steps,
OP_TOALTSTACKallows for better management of stack items and cleaner script execution.
- The alternate stack is not visible in script execution unless accessed explicitly.
OP_TOALTSTACKis often used in conjunction with
OP_FROMALTSTACKto move items back to the main stack when needed.
A script that requires temporarily setting aside a value:
# ASM script
# Raw script
# Main stack
# Alternate stack
A multi-step verification script where intermediate values are stored:
# ASM script
<value> OP_TOALTSTACK <other operations> <value retrieval from alternate stack>