Global Functions & Operators

CashScript has several functions builtin for things like cryptographic and arithmetic applications. It also includes many common operators, although some important ones are notably missing due to the limitations of the underlying Bitcoin Script.

Arithmetic functions


int abs(int a)

Returns the absolute value of argument a.


int min(int a, int b)

Returns the minimum value of arguments a and b.


int max(int a, int b)

Returns the maximum value of arguments a and b.


bool within(int x, int lower, int upper)

Returns true if and only if x >= lower && x < upper.

Hashing functions


bytes20 ripemd160(any x)

Returns the RIPEMD-160 hash of argument x.


bytes20 sha1(any x)

Returns the SHA-1 hash of argument x.


bytes32 sha256(any x)

Returns the SHA-256 hash of argument x.


bytes20 hash160(any x)

Returns the RIPEMD-160 hash of the SHA-256 hash of argument x.


bytes32 hash256(any x)

Returns the double SHA-256 hash of argument x.

Signature checking functions


All signature checking functions must comply with the NULLFAIL rule. This means that if you want to use the output of a signature check inside the condition of an if-statement, the input signature needs to either be correct, or an empty byte array. When you use an incorrect signature as an input, the script will fail.


bool checksig(sig s, pubkey pk)

Checks that transaction signature s is valid for the current transaction and matches with public key pk.


bool checkMultiSig(sig[] sigs, pubkey[] pks)

Performs a multi-signature check using a list of transaction signatures and public keys.


While this function can be used inside your smart contracts, it is not supported by the JavaScript SDK, so it is recommended not to use it. Instead a checkMultiSig() call can be simulated using multiple checkSig() calls.


bool checkDataSig(datasig s, bytes msg, pubkey pk)

Checks that sig s is a valid signature for message msg and matches with public key pk.


An overview of all supported operators and their precedence is included below. Notable is a lack of multiplication and exponentiation, since these operations are not supported by the underlying Bitcoin Script.

2Type cast<type>(<expression>)
3Object instantiationnew <class>(<args...>)
4Function call<function>(<args...>)
5Tuple index<tuple>[<index>]
6Member access<object>.<member>
7Postfix increment and decrement++, --
8Unary minus-
8Logical NOT!
9Division and modulo/, %
10Addition and subtraction+, -
10String / bytes concatenation+
11Numeric comparison<, >, <=, >=
12Equality and inequality==, !=
13Bitwise AND&
14Bitwise XOR^
15Bitwise OR|
16Logical AND&&
17Logical OR||