Q&A: What is CashScript and how does it relate to Bitcoin Cash smart contracts?
Question:
What is CashScript and how does it relate to Bitcoin Cash smart contracts?
Answer:
CashScript
CashScript is a high-level, TypeScript-based programming language that compiles to Bitcoin Cash Script bytecode. It lets developers write and interact with Bitcoin Cash smart contracts with far less effort than hand-writing raw Script, while adding type safety, transaction introspection, and native CashTokens support.
It was inspired by Ethereum’s Solidity syntax, but — crucially — it targets the UTXO model, not the account model. The official site is cashscript.org, and the source is on GitHub.
How it relates to Bitcoin Cash smart contracts
Bitcoin Cash smart contracts are just locking scripts that define the conditions under which a UTXO can be spent. CashScript is a compiler (cashc) plus a TypeScript SDK that makes writing, deploying, and spending those contracts practical:
- It compiles to BCH Script. The
cashccompiler turns.cashsource into Bitcoin Cash bytecode. - It matches the UTXO mental model. A contract doesn’t “do” anything at runtime — it only validates whether a proposed transaction satisfies its rules. It’s stateless and atomic, unlike EVM contracts.
- It provides transaction introspection. Contracts can inspect
tx.inputs[],tx.outputs[],.value,.lockingBytecode,.tokenCategory,.nftCommitment, etc., enabling covenants (contracts that constrain how their own funds move). - Native CashTokens support. Direct access to token categories, capabilities (
0x01mutable,0x02minting), and NFT commitments. - An SDK for building transactions. The TypeScript SDK handles contract instantiation, UTXO selection, unlocking, fee estimation, and broadcasting, in browser or on a server.
What this enables
Common patterns include covenants (e.g., the 5-point self-replication check), time-locked release (tx.time/this.age), multi-signature, and token-gated access. State is carried in NFT commitments rather than global storage — because BCH, unlike Ethereum, has no global contract state (which the docs note is an advantage for scalability).
Example of the covenant pattern:
require(tx.outputs[0].lockingBytecode == tx.inputs[0].lockingBytecode);
require(tx.outputs[0].tokenCategory == tx.inputs[0].tokenCategory);
require(tx.outputs[0].value == expectedValue);
require(tx.outputs[0].tokenAmount == expectedAmount);
require(tx.outputs[0].nftCommitment == newCommitment);
In short: CashScript is to Bitcoin Cash Script roughly what Solidity is to the EVM — a developer-friendly high-level language — but designed around BCH’s UTXO validation model and native token primitives rather than accounts and global state.
Sources: PSF LLM Wiki — cashscript-language.md, cashscript-faq.md; cashscript.org; GitHub (CashScript/cashscript).
Related wiki pages if you want to go deeper: cashscript-sdk, cashscript-security, cashscript-multi-contract, and cashtokens-spec.
Public Q&A mirror from the Block tech-support bot.
Write a comment