CashScript Documentation
website·Indexed 33 days ago
https://next.cashscript.orgA high-level programming language for writing smart contracts on Bitcoin Cash (BCH). This documentation covers the cashc compiler, the TypeScript SDK, language syntax, and guides for building transactions, managing UTXOs, and implementing covenants.
What's inside CashScript
- CashScript is a high-level programming language designed for creating smart contracts on Bitcoin Cash (BCH). It provides a strong abstraction layer over the native BCH Script virtual machine and supports advanced features such as native introspection and CashTokens. While its syntax is based on Solidity (Ethereum), its underlying functionality is tailored to the UTXO model of Bitcoin Cash.
Overview of the CashScript TypeScript SDK
The CashScript TypeScript SDK allows developers to build smart contract transactions in both browser and server environments. It provides full type-safety to ensure application reliability and uses a syntax based on Solidity (influenced by C++, Python, and JavaScript), making it accessible to developers familiar with those languages.Overview of the NetworkProvider interface
TheNetworkProviderinterface allows the CashScript SDK to connect to the BCH network for operations such as retrieving contract balances and sending transactions. It provides a standardized interface so that different network providers can be swapped easily. For production,ElectrumNetworkProvideris recommended; for local development,MockNetworkProvideris recommended.Overview of the CashScript TypeScript SDK
The CashScript TypeScript SDK provides a framework for building smart contract transactions on the BCH blockchain, usable in both browser and server environments. It offers advanced debugging tools, standardized network providers for blockchain information, and a type-safe API for transaction building. While optimized for TypeScript to provide better safety guarantees and developer experience, it is also compatible with vanilla JavaScript.Overview of the CashScript Python SDK
Thecashscript-pylibrary is a community-maintained Python SDK used to build and send CashScript transactions from a Python codebase. It is a port of the official TypeScript SDK and is intended for developers building server-side tools, bots, or Electron Cash plugins. It handles contract instantiation, transaction building, and network interaction, but requires contracts to be pre-compiled into artifact JSONs usingcashc.Legacy Simple Transaction Builder Overview
The 'Simple Transaction Builder' operated on a single contract. When calling a contract function from a Contract object's
functions, an incomplete Transaction object is returned. This transaction must be completed by specifying outputs (usingto()orwithOpReturn()) and other parameters before it can be sent viasend().CAUTION: This API was removed in v0.12 and is no longer available in the SDK. Users are strongly recommended to migrate to the new default transaction builder.
ParyonUSD stablecoin protocol
ParyonUSD is a decentralized stablecoin protocol on Bitcoin Cash that issues PUSD via over-collateralized debt positions (CDPs). The protocol is implemented using 26 CashScript contracts managing loans, loan keys, redemptions, a stability pool, and a price oracle.AnyHedge synthetic derivatives platform
AnyHedge is a DeFi project on Bitcoin Cash that functions as a synthetic derivatives platform. It enables two parties to enter a smart contract to speculate on asset prices, where one party takes a 'hedge' position to protect against price fluctuations and the other takes a leveraged 'long' position.Cash-Ninjas NFT minting
Cash-Ninjas is an open-source collectible NFT project on Bitcoin Cash. It employs a non-custodial, multi-threaded minting contract written in CashScript and uses wallet connect for direct minting from smart contract wallets.FundMe.cash crowdfunding
FundMe is a BCH crowdfunding platform using WalletConnect. It implements revocable and refundable pledges through CashTokens receipts, allowing the platform to support an unlimited number of participants per campaign.CashTokens Studio authority management
CashTokens Studio is used for creating CashTokens and managing metadata and reserved supply. It uses CashScript to lock the AuthUTXO in an AuthGuard contract, preventing the accidental spending of authority required to update metadata or release reserved supply.Understand the 'Happy Case' vs. Adversarial Case in BCH Transactions
In the 'Happy Case', Bitcoin Cash miners follow the 'first-seen rule', meaning competing transaction chains only occur due to accidental race conditions. Full nodes will not relay double-spend attempts, and miners will discard them. However, in the 'Adversarial Case', malicious actors intentionally double-spend unconfirmed transactions to extract value or disrupt the system. In an adversarial environment, user transactions are not guaranteed to be confirmed until they have received block confirmations.