A buyer creates a UTXO the seller can claim. If the UTXO remains unspent when a deadline is reached, the buyer can sign and broadcast a refund. CashScript lets you write those two spending rules. Its compiler, cashc, turns them into bytecode that the network’s CashVM can enforce.
Where CashScript fits
- Compile the contract. The compiler produces an artifact containing the bytecode and the information the app needs to pass in the two public keys and the refund deadline.
- Build the transaction in the application. The app displays the deadline and builds a claim or refund. The wallet signs and broadcasts it. The CashScript TypeScript SDK can help the app build and test either transaction.
- Validate the spend in CashVM. Each validating node runs the spending script. The claim needs the seller’s signature. The refund needs the buyer’s signature and a transaction that satisfies the deadline.
The funding UTXO carries or commits to the compiled script. A transaction built by any app must satisfy that same script. How a node validates an input · How scripts are placed in UTXOs
Where to put a rule
- Use the application for coordination and presentation
- Compute a quote, select UTXOs, estimate a fee, and show the user what they are approving. The original payment uses a standard P2PKH script to verify a signature.
- Put a spending constraint in CashScript when consensus must enforce it
- Put the rule in the script if it must hold even when someone uses a different app. For example, require two signatures or check that a specific new UTXO receives the intended tokens. Use introspection to check transaction fields. For an external fact such as a market price, the application supplies evidence the script can verify, such as a signed price quote.
- Work directly with CashVM bytecode when you need opcode-level control
- Use the opcode reference to inspect compilation, reproduce a validation failure, or hand-write a script whose exact instructions matter. CashVM opcode index
Try the refund contract
In the official example, the deadline opens a refund path. The seller can still claim the UTXO until a valid transaction spends it. Official CashScript transfer-with-timeout example
Continue with the CashScript project
- CashScript Playground to compile a contract and evaluate a spend in your browser.
- Language examples to see how contracts express spending conditions.
- SDK quickstart to load an artifact and build a transaction in an application.
- Covenants and introspection to write conditions that inspect a spending transaction.