Getting Started
Installing the CashScript compiler
The command line CashScript compiler cashc can be installed from NPM.
npm install -g cashcInstalling the JavaScript SDK
The JavaScript SDK can be installed into your project with NPM.
npm install cashscriptWriting your first smart contract
There are some examples available on the Examples page, that can be used to take inspiration from. Further examples of the JavaScript integration can be found on GitHub. A simple example is included below.
pragma cashscript ^0.7.0;
contract TransferWithTimeout(pubkey sender, pubkey recipient, int timeout) {
// Allow the recipient to claim their received money
function transfer(sig recipientSig) {
require(checkSig(recipientSig, recipient));
}
// Allow the sender to reclaim their sent money after the timeout is reached
function timeout(sig senderSig) {
require(checkSig(senderSig, sender));
require(tx.time >= timeout);
}
}Tip: Read more about the CashScript language syntax in the Language Description.
Integrating into JavaScript
While more detailed examples are available on GitHub, we show an integration of the TransferWithTimeout contract in a JavaScript project.
After compiling the contract file to an artifact JSON with cashc, it can be imported into the CashScript SDK.
Tip: Read more about the JavaScript SDK in the SDK documentation.
Last updated