Version: 0.31.0

# Cheat Sheet

Strings

let name: string = "Tezos";

Characters

let t: string = "t";

Integers

let i: int = 42;

Natural numbers

let n: nat = 7 as nat;

Unit

let u: unit = unit;

Boolean

let has_drivers_license: bool = false

let adult: bool = true

Boolean Logic

let booleanLogic: bool =

(!true) ==

false ==

(false && true) ==

(false || false)

Mutez (micro tez)

let tez: tez = 42 as tez

let tez2: tez = 7 as mutez

Address

let tz1address: address =

"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" as address;

let kt1address: address =

"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD" as address;

Addition

let add_int: int = 3 + 4;

let add_nat: nat = (3 as nat) + (4 as nat);

Multiplication & Division

let mul_int: int = 3 * 4;

let mul_nat: nat = (3 as nat) * (4 as nat);

let div_int: int = 10 / 5;

let div_nat: nat = (10 as nat) / (5 as nat);

Modulo

let mod_nat: nat = 10 % 3

Tuples

type name = [string, string]

let winner: name = ["John", "Doe"]

let firstName: string = winner[0]

let lastName: string = winner[1]

Types

type age = int

type name = string

Includes

`#include "library.religo"`

Functions (short form)

let add = (a: int, b: int): int =>

a + b;

Functions (long form)

let add = (a: int, b: int): int => {

let c = a;

let d = b;

return c + d

};

If Statement

let if_statement = (age : int): int => {

if (age < 16) {

failwith ("Too young to drive") as int

} else {

return 1

}

}

Options

type middle_name = option<string>;

let middle_name : middle_name = Some("Foo");

let middle_name_ : middle_name = None();

Variable Binding

let age: int = 5

Type Annotations

let someAddress: address =

"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" as address;

Variants

type action =

["Increment", int]

| ["Decrement", int];

Variant *(pattern)* matching

let a: action = Increment(5)

let result: int = match(a, {

Increment: (n: int) => n + 1,

Decrement: (n: int) => n - 1

})

Records

type person = {

age: int,

name: string

}

let john : person = {

age: 18,

name: "john doe"

}

let name_: string = john.name

Maps

type prices = map<nat, tez>;

let prices: prices = Map.literal(list([

[10 as nat, 60 as mutez],

[50 as nat, 30 as mutez],

[100 as nat, 10 as mutez]

]));

let price: option<tez> = Map.find_opt(50 as nat, prices)

let prices2: prices = Map.update(200 as nat, (Some (5 as mutez)), prices)

Contracts & Accounts

let destinationAddress: address =

"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" as address;

let contract : contract<unit> =

match (Tezos.get_contract_opt(Tezos.sender) as option<contract<unit>>, {

Some: (contract: contract<unit>) => contract,

None: () => (failwith("no contract") as contract<unit>)

})

Transactions

let payment: operation =

Tezos.transaction(unit, 100 as mutez, contract);

Exception/Failure

let fail = (u: unit) : unit =>

failwith("a failure message")