9.5 KiB
9.5 KiB
id | title |
---|---|
cheat-sheet | Cheat Sheet |
import Syntax from '@theme/Syntax';
Primitive
Example
Strings
const name: string = "Tezos";
Characters
const t: string = "t";
Integers
const i: int = 42;
Natural numbers
const n: int = 7n;
Unit
const u: unit = unit;
Boolean
const hasDriversLicense: bool = False;
const adult: bool = True;
Boolean Logic
const booleanLogic: bool = (not True) == False == (False and True) == (False or False);
Mutez (micro tez)
const tez: mutez = 42mutez;
Address
const tz1address: address = ""tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
const kt1address: address = ""KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD";
Addition
const add_int: int = 3 + 4;
const add_nat: nat = 3n + 4n;
Multiplication & Division
const mul_int: int = 3 + 4;
const mul_nat: nat = 3n + 4n;
const div_int: int = 10 / 5;
const div_nat: nat = 10n / 5n;
Modulo
const mod: int = 10 mod 3;
Tuples
const mod: int = 10 mod 3;
Primitive | Example |
---|---|
Modulo | 10 mod 3 |
Tuples |
|
Types | type age is int , type name is string |
Includes | #include "library.ligo" |
Functions (short form) |
|
Functions (long form) |
|
If Statement |
|
Options |
|
Assignment | const age: int = 5; |
Assignment on an existing variable ⚠️ 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 |
Type Annotations | ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) |
Variants |
|
Variant (pattern) matching |
|
Records |
|
Maps |
|
Contracts & Accounts |
|
Transactions |
|
Exception/Failure | failwith ("Your descriptive error message for the user goes here.") |
Primitive | Example |
---|---|
Strings | "Tezos" |
Characters | "t" |
Integers | 42 , 7 |
Natural numbers | 42n , 7n |
Unit | unit |
Boolean |
|
Boolean Logic |
|
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 |
|
Types | type age = int , type name = string |
Includes | #include "library.mligo" |
Functions |
|
If Statement |
|
Options |
|
Variable Binding | let age: int = 5 |
Type Annotations | ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) |
Variants |
|
Variant (pattern) matching |
|
Records |
|
Maps |
|
Contracts & Accounts |
|
Transactions |
|
Exception/Failure | failwith ("Your descriptive error message for the user goes here.") |
Primitive | Example |
---|---|
Strings | "Tezos" |
Characters | "t" |
Integers | 42 , 7 |
Natural numbers | 42n , 7n |
Unit | unit |
Boolean |
|
Boolean Logic |
|
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 |
|
Types | type age = int; , type name = string; |
Includes | #include "library.mligo" |
Functions |
|
If Statement |
|
Options |
|
Variable Binding | let age: int = 5; |
Type Annotations | ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) |
Variants |
|
Variant (pattern) matching |
|
Records |
|
Maps |
|
Contracts & Accounts |
|
Transactions |
|
Exception/Failure | failwith ("Your descriptive error message for the user goes here."); |