Q&A: What is CashScript?

Block answers a tech-support question about What is CashScript?

Question:

What is CashScript?


Answer:

CashScript

CashScript is a high-level programming language for writing smart contracts on Bitcoin Cash. Created in 2019, it offers a strong abstraction layer over BCH’s native virtual machine, Bitcoin Script (BCH Script).

Key characteristics

  • Syntax inspired by Solidity (Ethereum’s language, itself influenced by C++, Python, and JavaScript) — but its behavior is fundamentally different because BCH smart contracts work very differently from Ethereum’s.
  • Compiles to Bitcoin Script bytecode. The compiler, called cashc, is a standalone CLI tool that compiles .cash files into .json (or .ts) artifact files.
  • Strong TypeScript SDK for creating, debugging, and testing smart contract transactions. It includes an integrated networkProvider API (e.g. ElectrumNetworkProvider) to fetch blockchain data, making contracts usable type-safely in browsers or on servers.
  • Supports modern BCH features, including native transaction introspection and CashTokens (fungible and non-fungible tokens, activated May 2023).

The UTXO mental model (important!)

CashScript is not Ethereum. BCH uses an Unspent Transaction Output (UTXO) model:

Aspect CashScript / BCH (UTXO) Solidity / Ethereum (Account)
State No global state; independent atomic UTXOs Global state tree with persistent storage
Execution Stateless transaction validation Stateful contract execution
Introspection Full tx visibility (tx.inputs[], tx.outputs[]) Limited (msg.sender, msg.value)
Tokens Native CashTokens (FT/NFT) ERC-20/721 contracts
Fees Based on transaction size Based on computational gas

A CashScript contract doesn’t “do” anything at runtime — it only validates whether a proposed transaction meets its rules. The core question for any contract is “what transformation of UTXOs does this contract permit?”

Language highlights

  • Types: bool, int, string, bytes, bytesN, pubkey, sig
  • Global vars: tx.inputs, tx.outputs, tx.time, tx.version, tx.locktime; plus this.activeInputIndex, this.activeBytecode, this.age
  • Built-ins: checkSig, checkMultiSig, checkDataSig, hash functions (sha256, hash160, etc.), abs, min, max, within, and locking-bytecode constructors (new LockingBytecodeP2PKH(...), P2SH32, etc.)
  • No loops or global state (as of the May 2025 ruleset) — native loops via OP_BEGIN/OP_UNTIL are slated for the May 2026 upgrade.

Example (“Hello World”)

Defining the P2PKH pattern inside a contract illustrates the model:

pragma cashscript ^0.11.0;

contract P2PKH(bytes20 pkh) {
    function spend(pubkey pk, sig s) {
        require(hash160(pk) == pkh);
        require(checkSig(s, pk));
    }
}

Then, in the SDK:

import { Contract, ElectrumNetworkProvider, SignatureTemplate, TransactionBuilder } from 'cashscript';
const provider = new ElectrumNetworkProvider('chipnet');
const contract = new Contract(P2PKH, [pkh], { provider });
const utxos = await contract.getUtxos();
const tx = await new TransactionBuilder({ provider })
  .addInput(utxos[0], contract.unlock.spend(sigTemplate))
  .addOutput({ to: contract.address, amount: 10000n })
  .send();

CashScript’s goal is to make smart-contract development on Bitcoin Cash accessible to a wide range of developers and to power next-generation UTXO-based applications.

Sources:

Would you like more detail on any area — the type system, CashTokens integration, security patterns, or the SDK?


Public Q&A mirror from the Block tech-support bot.


Write a comment