The P2PKH case study locks each output to a public-key hash. BCH can also lock outputs with custom conditions. You can put a program directly in the output or commit to its hash and reveal the program at spend time.
Choose how to place the locking condition
| Output type | In the output | At spend time |
|---|---|---|
| P2PKH | A standard locking script containing a public-key hash. | Provide the public key and signature. |
| Pay to Script (P2S) | The locking program itself. Since May 2026, most bare locking scripts up to 201 bytes are eligible for standard relay. | Provide the data the program expects. The program is visible as soon as the output is created. |
| Pay to Script Hash (P2SH) | A standard locking program containing a 20-byte HASH160 or 32-byte HASH256 of the redeem script. | Push the arguments and then the serialized redeem script. CashVM checks the hash and evaluates the redeem script with the arguments. |
A P2SH CashAddr can represent the script hash. Paying directly to an arbitrary script requires the script bytecode. For constraints and exceptions, see Pay to Script and P2SH32.
Read a custom script
CashVM reads instructions and data pushes. In 02 aa bb 51, 02 tells CashVM to push the next two bytes as a single item, aabb. Then 51 pushes the number 1. Read the stack top first, as in the payment trace. It now holds [01, aabb]. Trace the P2PKH stack · Open the opcode table
Evaluate the unlocking and locking scripts together with the transaction they authorize.
Use introspection in a covenant
A covenant restricts how its UTXO can be spent. Introspection instructions let its locking script read fields of the spending transaction. For example, the funding UTXO could require that the next transaction's output 0 pay at least 50,000 sats and carry the intended recipient's locking bytecode. Anyone satisfying those conditions could spend it unless the script also requires authorization, such as a signature.
- Push
0and useOP_OUTPUTVALUEto read the value of output 0. Compare it against 50,000 sats. - Push
0again and useOP_OUTPUTBYTECODEto read the output's locking bytecode. Compare those bytes against the expected recipient script. - Consider every permitted output, change, fee, and use of other inputs. A rule on output 0 alone leaves the rest of the transaction free to change.
OP_INPUTINDEX gives the current input index. OP_UTXOVALUE and OP_UTXOBYTECODE use an input index to read the UTXO it spends. Token introspection can also check category, commitment, and amount. Introspection specification · Where CashScript fits
See VM limits for loops, functions, and input budgets.
A spending condition that checks a public key against a saved hash and verifies a signature made with the corresponding private key.A fixed-length digest used to identify data or commit to its contents, such as a transaction ID or public-key hash.The currency unit of Bitcoin Cash, equal to 100,000,000 satoshis.A spending condition that commits to the hash of a redeem script, which the spender supplies along with its arguments.The Bitcoin Cash address encoding, which uses a prefix, type, payload, and checksum to describe how to construct a locking script.The bytes encoding a script’s instructions and the data they operate on.The Bitcoin Cash virtual machine that executes the scripts authorizing an input to spend its UTXO.The program in an output that specifies the conditions required to spend it.A Bitcoin Cash record that defines new outputs and, for a payment, identifies the UTXOs being spent.A locking script that constrains how its UTXO may be spent, for example by requiring the spending transaction to pay a particular output.The basic unit of spendable value on Bitcoin Cash, holding satoshis and any attached tokens under the spending rules defined by its locking bytecode.Script instructions that let CashVM read fields of the spending transaction and the UTXOs it spends.The smallest unit of BCH, equal to 0.00000001 BCH.A value made with a private key that lets someone with the corresponding public key verify authorization of the signed data.A transaction record that identifies a UTXO to spend and supplies its unlocking bytecode and sequence number.