2019-06-11 05:37:12 +04:00
---
id: cheat-sheet
title: Cheat Sheet
---
2020-03-04 17:19:00 +04:00
import Syntax from '@theme/Syntax';
< div className = "cheatsheet" >
2019-06-21 16:45:52 +04:00
2020-02-25 21:07:53 +04:00
<!--
2020-01-28 20:36:55 +04:00
Note that this table is not compiled before production and currently needs to be managed manually.
-->
2019-06-11 05:37:12 +04:00
2020-03-04 17:19:00 +04:00
< Syntax syntax = "pascaligo" >
2019-06-11 05:37:12 +04:00
|Primitive |Example|
|--- |---|
|Strings | `"Tezos"` |
|Characters | `"t"` |
|Integers | `42` , `7` |
|Natural numbers | `42n` , `7n` |
|Unit| `unit` |
|Boolean|< pre > < code > const hasDriversLicense: bool = False;< br / > const adult: bool = True;< / code > < / pre > |
2019-07-09 13:29:24 +04:00
|Boolean Logic|< pre > < code > (not True) == False == (False and True) == (False or False)< / code > < / pre > |
2019-10-27 20:50:24 +04:00
|Mutez (micro tez)| `42mutez` , `7mutez` |
2019-06-11 05:37:12 +04:00
|Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"` , `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"` |
|Addition |`3 + 4`, `3n + 4n` |
|Multiplication & Division| `3 * 4` , `3n * 4n` , `10 / 5` , `10n / 5n` |
|Modulo| `10 mod 3` |
|Tuples| < pre > < code > type name is (string * string);< br / > const winner: name = ("John", "Doe");< br / > const firstName: string = winner.0;< br / > const lastName: string = winner.1;< / code > < / pre > |
|Types|`type age is int`, `type name is string` |
|Includes|```#include "library.ligo"```|
|Functions (short form)|< pre > < code > function add (const a : int ; const b : int) : int is< br / > block { skip } with a + b< / code > < / pre > |
|Functions (long form)|< pre > < code > function add (const a : int ; const b : int) : int is< br / > block { < br / > const result: int = a + b;< br / > } with result< / code > < / pre > |
2020-02-26 22:37:05 +04:00
| If Statement | < pre > < code > if age < 16 < br / > then failwith ("Too young to drive."); < br / > else const new_id: int = prev_id + 1;< / code > < / pre > |
2019-06-11 05:37:12 +04:00
|Options|< pre > < code > type middleName is option(string);< br / > const middleName : middleName = Some("Foo");< br / > const middleName : middleName = None;< / code > < / pre > |
|Assignment| ```const age: int = 5;```|
2020-03-04 17:19:00 +04:00
|Assignment on an existing variable < br / > *⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` |
2019-07-10 07:05:33 +04:00
|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
2019-06-11 05:37:12 +04:00
|Variants|< pre > < code > type action is< br / > | Increment of int< br / > | Decrement of int< / code > < / pre > |
2019-06-24 19:31:55 +04:00
|Variant *(pattern)* matching|< pre >< code > const a: action = Increment(5);< br /> case a of< br /> | Increment(n) -> n + 1< br /> | Decrement(n) -> n - 1< br /> end</ code ></ pre > |
2019-06-11 05:37:12 +04:00
|Records|< pre > < code > type person is record< br / > age: int ;< br / > name: string ;< br / > end< br / > < br / > const john : person = record< br / > age = 18;< br / > name = "John Doe";< br / > end< br / > < br / > const name: string = john.name;< / code > < / pre > |
2019-10-27 20:50:24 +04:00
|Maps|< pre > < code > type prices is map(nat, tez);< br / > < br / > const prices : prices = map< br / > 10n -> 60mutez;< br / > 50n -> 30mutez;< br / > 100n -> 10mutez;< br / > end< br / > < br / > const price: option(tez) = prices[50n];< br / > < br / > prices[200n] := 5mutez;< / code > < / pre > |
2019-06-21 16:45:52 +04:00
|Contracts & Accounts|< pre > < code > const destinationAddress : address = "tz1...";< br / > const contract : contract(unit) = get_contract(destinationAddress);< / code > < / pre > |
|Transactions|< pre > < code > const payment : operation = transaction(unit, amount, receiver);< / code > < / pre > |
2020-02-26 22:37:05 +04:00
|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`|
2019-06-11 05:37:12 +04:00
2020-03-04 17:19:00 +04:00
< / Syntax >
< Syntax syntax = "cameligo" >
2019-12-12 22:07:13 +04:00
|Primitive |Example|
|--- |---|
|Strings | `"Tezos"` |
|Characters | `"t"` |
|Integers | `42` , `7` |
|Natural numbers | `42n` , `7n` |
|Unit| `unit` |
|Boolean|< pre > < code > let has_drivers_license: bool = false< br / > let adult: bool = true< / code > < / pre > |
|Boolean Logic|< pre > < code > (not true) = false = (false & & true) = (false | | false)< / code > < / pre > |
|Mutez (micro tez)| `42mutez` , `7mutez` |
|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)` , `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)` |
|Addition |`3 + 4`, `3n + 4n` |
|Multiplication & Division| `3 * 4` , `3n * 4n` , `10 / 5` , `10n / 5n` |
|Modulo| `10 mod 3` |
|Tuples| < pre > < code > type name = (string * string)< br / > let winner: name = "John", "Doe"< br / > let first_name: string = winner.0< br / > let last_name: string = winner.1< / code > < / pre > |
|Types|`type age = int`, `type name = string` |
|Includes|```#include "library.mligo"```|
|Functions |< pre > < code > let add (a : int) (b : int) : int = a + b < / code > < / pre > |
2020-02-26 22:37:05 +04:00
| If Statement | < pre > < code > let new_id: int = if age < 16 < br / > then failwith ("Too young to drive.") < br / > else prev_id + 1< / code > < / pre > |
2019-12-12 22:07:13 +04:00
|Options|< pre > < code > type middle_name = string option< br / > let middle_name : middle_name = Some "Foo"< br / > let middle_name : middle_name = None< / code > < / pre > |
|Variable Binding | ```let age: int = 5```|
|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
|Variants|< pre > < code > type action =< br / > | Increment of int< br / > | Decrement of int< / code > < / pre > |
|Variant *(pattern)* matching|< pre >< code > let a: action = Increment 5< br /> match a with< br /> | Increment n -> n + 1< br /> | Decrement n -> n - 1< br /></ code ></ pre > |
|Records|< pre > < code > type person = {< br / > age: int ;< br / > name: string ;< br / > }< br / > < br / > let john : person = {< br / > age = 18;< br / > name = "John Doe";< br / > }< br / > < br / > let name: string = john.name< / code > < / pre > |
2020-01-28 20:36:55 +04:00
|Maps|< pre > < code > type prices = (nat, tez) map< br / > < br / > let prices : prices = Map.literal [< br / > (10n, 60mutez);< br / > (50n, 30mutez);< br / > (100n, 10mutez)< br / > ]< br / > < br / > let price: tez option = Map.find_opt 50n prices< br / > < br / > let prices: prices = Map.update 200n (Some 5mutez) prices< / code > < / pre > |
2020-02-25 21:07:53 +04:00
|Contracts & Accounts|< pre > < code > let destination_address : address = "tz1..."< br / > let contract : unit contract = < br / > Tezos.get_contract destination_address< / code > < / pre > |
|Transactions|< pre > < code > let payment : operation = < br / > Tezos.transaction unit amount receiver< / code > < / pre > |
2020-02-26 22:37:05 +04:00
|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`|
2019-12-12 22:07:13 +04:00
2020-03-04 17:19:00 +04:00
< / Syntax >
< Syntax syntax = "reasonligo" >
2020-01-28 20:36:55 +04:00
|Primitive |Example|
|--- |---|
|Strings | `"Tezos"` |
|Characters | `"t"` |
|Integers | `42` , `7` |
|Natural numbers | `42n` , `7n` |
|Unit| `unit` |
|Boolean|< pre > < code > let has_drivers_license: bool = false;< br / > let adult: bool = true;< / code > < / pre > |
|Boolean Logic|< pre > < code > (not true) = false = (false & & true) = (false | | false)< / code > < / pre > |
|Mutez (micro tez)| `42mutez` , `7mutez` |
|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)` , `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)` |
|Addition |`3 + 4`, `3n + 4n` |
|Multiplication & Division| `3 * 4` , `3n * 4n` , `10 / 5` , `10n / 5n` |
|Modulo| `10 mod 3` |
|Tuples| < pre > < code > type name = (string, string);< br / > let winner: name = ("John", "Doe");< br / > let first_name: string = winner[0];< br / > let last_name: string = winner[1];< / code > < / pre > |
|Types|`type age = int;`, `type name = string;` |
|Includes|```#include "library.mligo"```|
|Functions |< pre > < code > let add = (a: int, b: int) : int => a + b; < / code > < / pre > |
2020-02-26 22:37:05 +04:00
| If Statement | < pre > < code > let new_id: int = if (age < 16 ) { < br / > failwith ("Too young to drive."); < br / > } else { prev_id + 1; }< / code > < / pre > |
2020-01-28 20:36:55 +04:00
|Options|< pre > < code > type middle_name = option(string);< br / > let middle_name : middle_name = Some("Foo");< br / > let middle_name : middle_name = None;< / code > < / pre > |
|Variable Binding | ```let age: int = 5;```|
|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
|Variants|< pre > < code > type action =< br / > | Increment(int)< br / > | Decrement(int);< / code > < / pre > |
|Variant *(pattern)* matching|< pre >< code > let a: action = Increment(5);< br /> switch(a) {< br /> | Increment(n) => n + 1< br /> | Decrement(n) => n - 1;< br /> } < br /></ code ></ pre > |
|Records|< pre > < code > type person = {< br / > age: int,< br / > name: string< br / > }< br / > < br / > let john : person = {< br / > age: 18,< br / > name: "John Doe"< br / > };< br / > < br / > let name: string = john.name;< / code > < / pre > |
|Maps|< pre > < code > type prices = map(nat, tez);< br / > < br / > let prices : prices = Map.literal([< br / > (10n, 60mutez),< br / > (50n, 30mutez),< br / > (100n, 10mutez)< br / > ]);< br / > < br / > let price: option(tez) = Map.find_opt(50n, prices);< br / > < br / > let prices: prices = Map.update(200n, Some (5mutez), prices);< / code > < / pre > |
2020-02-25 21:07:53 +04:00
|Contracts & Accounts|< pre > < code > let destination_address : address = "tz1...";< br / > let contract : contract(unit) = < br / > Tezos.get_contract(destination_address);< / code > < / pre > |
|Transactions|< pre > < code > let payment : operation = < br / > Tezos.transaction (unit, amount, receiver);< / code > < / pre > |
2020-02-26 22:37:05 +04:00
|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.");`|
2019-12-12 22:07:13 +04:00
2020-03-04 17:19:00 +04:00
< / Syntax >
2019-10-27 20:50:24 +04:00
2019-06-11 05:37:12 +04:00
2019-10-27 20:50:24 +04:00
< / div >