sCrypt is an
embedded Domain Specific Language (eDSL) based on TypeScript for writing smart contracts on Bitcoin SV.
Embedded means that it is a language inside another language.
sCrypt is strictly a subset of TypeScript, so all
sCrypt code is valid TypeScript, but not vice versa.
How do Bitcoin Smart Contracts work?
Smart contracts on Bitcoin are based on the UTXO model, which is very different from an account model like Ethereum used.
Each bitcoin transaction consists of some inputs and outputs. An output contains:
- The amount of bitcoins it contains.
- bytecodes (called the
while an input contains:
- A reference to the previous transaction output.
- bytecodes (the
An Unspent Transaction Output (UTXO) is an output not consumed in any transaction yet. The low-level bytecode/opcode is called Bitcoin Script, which is interpreted by the Bitcoin Virtual Machine (BVM).
In the example above, we have two transactions, each having one input (in green) and one output (in red). And the transaction on the right spends the one on the left.
The locking script can be regarded as a boolean function
f that specifies conditions to spend the bitcoins in the UTXO, acting as a lock (thus the name "locking").
The unlocking script in turns provides the function arguments that makes
f evaluates to
true, i.e., the "key" (also called witness) needed to unlock.
Only when the “key” in an input matches previous output’s “lock”, it can spend bitcoins contained in the output.
In a regular Bitcoin payment to a Bitcoin address, the locking script is Pay To Pubkey Hash (P2PKH). It checks the spender has the right private key corresponding to the address so she can produce a valid signature in the unlocking script. The expressive Script enables the locking script to specify arbitrarily more complex spending conditions than simple P2PKH, i.e., Bitcoin smart contracts.
sCrypt is a high-level language to be compiled into Bitcoin Script. The resulting assembly-like scripts could be used as locking scripts when building transactions.
Jump over to the Installation section to learn how to create an
You can also follow this Youtube series.