A friendly Smart Contract Language for Tezos
Smart contracts were never so easy
- JsLIGO
- CameLIGO
- PascaLIGO
- ReasonLIGO
type storage = int;type parameter =| ["Increment", int]| ["Decrement", int]| ["Reset"];type return_ = [list <operation>, storage];/* Two entrypoints */const add = ([store, delta] : [storage, int]) : storage => store + delta;const sub = ([store, delta] : [storage, int]) : storage => store - delta;/* Main access point that dispatches to the entrypoints according tothe smart contract parameter. */const main = ([action, store] : [parameter, storage]) : return_ => {return [(list([]) as list <operation>), // No operations(match (action, {Increment: (n: int) => add ([store, n]),Decrement: (n: int) => sub ([store, n]),Reset: () => 0}))]};/* Tests for main access point */const _test_initial_storage = () : unit => {let initial_storage = 42 as int;let [taddr, _, _] = Test.originate(main, initial_storage, 0 as tez);return assert(Test.get_storage(taddr) == initial_storage);};const test_initial_storage = _test_initial_storage();const _test_increment = () : unit => {let initial_storage = 42 as int;let [taddr, _, _] = Test.originate(main, initial_storage, 0 as tez);let contr = Test.to_contract(taddr);let _ = Test.transfer_to_contract_exn(contr, (Increment (1)), 1 as mutez);return assert(Test.get_storage(taddr) == initial_storage + 1);}const test_increment = _test_increment();
type storage = inttype parameter =Increment of int| Decrement of int| Resettype return = operation list * storage// Two entrypointslet add (store, delta : storage * int) : storage = store + deltalet sub (store, delta : storage * int) : storage = store - delta(* Main access point that dispatches to the entrypoints according tothe smart contract parameter. *)let main (action, store : parameter * storage) : return =([] : operation list), // No operations(match action withIncrement (n) -> add (store, n)| Decrement (n) -> sub (store, n)| Reset -> 0)(* Tests for main access point *)let test_initial_storage =let initial_storage = 42 inlet (taddr, _, _) = Test.originate main initial_storage 0tez inassert (Test.get_storage taddr = initial_storage)let test_increment =let initial_storage = 42 inlet (taddr, _, _) = Test.originate main initial_storage 0tez inlet contr = Test.to_contract taddr inlet _ = Test.transfer_to_contract_exn contr (Increment (1)) 1mutez inassert (Test.get_storage taddr = initial_storage + 1)
type storage is inttype parameter isIncrement of int| Decrement of int| Resettype return is list (operation) * storage// Two entrypointsfunction add (const store : storage; const delta : int) : storage isstore + deltafunction sub (const store : storage; const delta : int) : storage isstore - delta(* Main access point that dispatches to the entrypoints according tothe smart contract parameter. *)function main (const action : parameter; const store : storage) : return is((nil : list (operation)), // No operationscase action of [Increment (n) -> add (store, n)| Decrement (n) -> sub (store, n)| Reset -> 0])(* Tests for main access point *)const test_initial_storage = {const initial_storage = 42;const (taddr, _, _) = Test.originate(main, initial_storage, 0tez);const storage = Test.get_storage(taddr);} with assert (storage = initial_storage);const test_increment = {const initial_storage = 42;const (taddr, _, _) = Test.originate(main, initial_storage, 0tez);const contr = Test.to_contract(taddr);const _ = Test.transfer_to_contract_exn(contr, Increment(1), 1mutez);const storage = Test.get_storage(taddr);} with assert (storage = initial_storage + 1);
type storage = int;type parameter =Increment (int)| Decrement (int)| Reset;type return = (list (operation), storage);// Two entrypointslet add = ((store, delta) : (storage, int)) : storage => store + delta;let sub = ((store, delta) : (storage, int)) : storage => store - delta;/* Main access point that dispatches to the entrypoints according tothe smart contract parameter. */let main = ((action, store) : (parameter, storage)) : return => {(([] : list (operation)), // No operations(switch (action) {| Increment (n) => add ((store, n))| Decrement (n) => sub ((store, n))| Reset => 0}))};/* Tests for main access point */let test_initial_storage = {let initial_storage = 42;let (taddr, _, _) = Test.originate(main, initial_storage, 0tez);assert (Test.get_storage(taddr) == initial_storage)};let test_increment = {let initial_storage = 42;let (taddr, _, _) = Test.originate(main, initial_storage, 0tez);let contr = Test.to_contract(taddr);let _ = Test.transfer_to_contract_exn(contr, (Increment (1)), 1mutez);assert (Test.get_storage(taddr) == initial_storage + 1)};
Strong, Static Type System
Write types, then code. Benefit from the safety of type systems.
Polyglot
Code in your language. Write PascaLIGO, CameLIGO, ReasonLIGO, JsLIGO or add your own syntax.
Easy Integration
You can use LIGO as a Node.js library with Truffle.