Opcodes

The visualization below includes an explanation of the most commonly used opcodes in standard transactions.

Understanding opcodes

Getting to know the opcode in this visualization helps you understand most standard bitcoin transactions

Bitcoin OpCode Explorer
OP_CHECKSIG (0xAC)
Verifies a signature against a public key and the transaction data. If the signature is valid, it pushes 1 onto the stack; otherwise, it pushes 0.
Your browser does not support SVG
Example
<sig> <pubkey> OP_CHECKSIG

Categories of opcodes

SVG Image

Key Characteristics

  • Opcodes are typically one byte in size.
  • Some opcodes have been disabled for security reasons.

New opcodes

New opcodes can be added through soft forks to enable new functionality. Eg: OP_CTV, OP_CAT, ...

Exercise: Implement OP_ADD

Your task is to implement the OP_ADD function in the interactive code editor below. Use the provided template and follow the steps outlined in the comments.

Test your implementation by:

  1. Pushing numbers onto the stack using the input field and "Push" button.
  2. Clicking the "OP_ADD" button to execute your implementation.
  3. Observing the result on the stack and the feedback message.
P2PK ScriptPubKey Decoder Exercise
const OP_ADD = (stack) => {
  // Note: The stack is an array. You can use pop(), push(), and length.

// 1. Check if there are at least 2 elements in the stack
// 2. If not, return false
// 3. Pop the top two elements from the stack
// 4. Add them together
// 5. Push the result back onto the stack
// 6. Return true if successful, false if an error occurred

try {
// Implement OP_ADD here

    return true; // Operation successful

} catch (error) {
console.error("Error in OP_ADD:", error);
return false; // Operation failed
}
};

export default OP_ADD
;

Ready to Code?

Choose your preferred language to begin

Solution code

Suggest Edits