๐ŸงŠ The internet cash guide โ€” now in 37 posts ยท โšก Paid in Bitcoin Cash only ยท ๐Ÿš€ Ships worldwide from the USA
โ† Back to: A wallet is not an account Deep dive

The Script Under Every Wallet

Before CashScript, before tokens, there was a stack, a few opcodes, and a rule: the transaction either validates or it does not.

This deep dive expands on the scripting foundation mentioned in "Money that rules." It covers how BCH scripts actually work โ€” the stack-based execution model, the standard payment patterns, and how introspection opened the door to covenants. This is technical content for developers and the deeply curious.

A Bitcoin Cash wallet looks simple: an address, a balance, a send button. Underneath, every payment is a script execution. The script is small, stack-based, and deliberately boring. That is what makes it possible for every full node to validate it quickly.

The standard payment script

A normal BCH address is usually a pay-to-public-key-hash, or P2PKH, lock. The locking script says, in effect: take the public key provided by the spender, hash it, compare it to the hash in the output, then check that the signature matches the key. The classic opcode sequence is OP_DUP OP_HASH160 <pubkeyhash> OP_EQUALVERIFY OP_CHECKSIG.

The spending transaction provides the signature and public key in its unlocking script. The two scripts run in sequence. If the stack ends with a true value, the input is valid. If it ends with false, or an opcode fails, the transaction is rejected.

There is no account balance being edited. The input is consumed, and new outputs are created. The wallet hides this, but the model explains why a transaction can have multiple inputs, why change is a real output, and why the fee depends on bytes rather than the dollar amount.

Bitcoin Script stack-based execution
Bitcoin Script execution: stack-based VM. The unlocking script provides data (signature, pubkey), the locking script executes opcodes (OP_DUP, OP_HASH160, etc.), and the stack state determines if the transaction is valid. Result: TRUE means the spend is authorized.

Pay to script hash

P2PKH is only the default. A more flexible lock is pay-to-script-hash, or P2SH. Instead of locking to a single key, the output locks to the hash of a redeem script. The spender reveals the full script when spending it, and the network checks that the hash matches and that the script evaluates to true.

P2SH is how more complex contracts fit into a normal-looking address. The contract can require multiple signatures, a timelock, a hash preimage, or a combination of conditions. BCH added P2SH32 in 2023, using a stronger 32-byte hash for new contracts while keeping the old format compatible.

Multisig and timelocks

Two building blocks show up in almost every application. The first is multisignature: require m of n keys to sign before the money can move. A 2-of-3 escrow is the classic example. The second is a timelock: make a coin unspendable until a certain time or block height, using OP_CHECKLOCKTIMEVERIFY, or until a relative delay has passed, using OP_CHECKSEQUENCEVERIFY.

Combine them and you get useful contracts. An inheritance vault can let the owner spend now, but let a family key spend after a year of inactivity. An escrow can let the buyer and seller agree, but let the buyer reclaim the funds if the seller disappears past a deadline. A swap can release funds only when a secret is revealed before a timeout.

Introspection changed the ceiling

BCH scripts have always been able to check signatures and time. Native introspection, activated in 2022, added the ability to inspect where the money is going. A contract can now read details of the transaction spending it: output values, locking scripts, token data, the active input index, and more.

That is what makes covenants possible. A vault can refuse to send funds anywhere except a designated cold address. A contract can require that part of the money returns to itself, or that a token moves with the payment. The script is no longer only asking "who signed?" It can ask "what does this transaction actually do?"

Focused by design

BCH Script is a focused language. It has no global memory and no network calls, and the 2026 upgrade adds bounded loops and reusable functions. The principle is simple: every contract must be cheap to validate and small enough to audit.

That focus is what makes BCH contracts reliable. The script is not trying to run a social network. It is making money behave predictably. A small, deterministic language with explicit rules is exactly the right tool for that job.

If you want to go deeper, CashScript without the ceremony shows how the high-level language makes these scripts readable and auditable.

We do not provide financial advice.

Bitcoin Cash

Internet cash needs places to spend it.

Every order at stickers.cash is paid in BCH โ€” a cheap, real-world way to move your first coins, practice self-custody, and put a sticker on something you own.

Shop stickers No wallet yet? Selene ยท Paytaca ยท Badger