What opcodes let Kaspa scripts inspect a transaction's input and output count?

Kaspa's scripting layer provides three opcodes that let a script examine the structure of the transaction it belongs to: OpTxInputCount, OpTxOutputCount, and OpTxInputIndex. An opcode is a low-level instruction — a single verb the script engine can execute during validation. OpTxInputCount (0xb3) returns how many inputs the transaction has; OpTxOutputCount (0xb4) returns how many outputs it has; and OpTxInputIndex (0xb9) tells the script which specific input slot is currently being checked. This matters for beginners because these opcodes are the building blocks that allow Kaspa scripts to enforce structural rules on a transaction — for example, requiring a precise number of inputs before a coin is allowed to move.

Learn more ›