Top-Level
These types and functions are available without any needed prefix.
type address
type address
An untyped address which can refer to a smart contract or account.
type ('key, 'value) big_map
type big_map <'key, 'value>
The type of a big map from values of type key
to values
of type value
is (key, value) big_map
.
type move = int * int
type register = (address, move) big_map
The type of a big map from values of type key
to
values of type value
is big_map<key, value>
.
type move = [int, int];
type register = big_map<address, move>;
Be aware that a big_map
cannot appear inside another big_map
.
type bool
type bool
type bytes
type bytes
type 'param contract
type contract<'param>
A typed contract.
Use unit
as param
to indicate an implicit account.
type chain_id
type chain_id
The identifier of a chain, used to indicate test or main chains.
type int
type int
An integer.
The only size limit to integers is gas.
type key
type key
A public cryptographic key.
type key_hash
type key_hash
The hash of a public cryptographic key.
type 't list
type list<'t>
A sequence of elements of the same type.
type ('key, 'value) map
type map <'key, 'value>
The type of a map from values of type key
to values
of type value
is (key, value) map
.
type move = int * int
type register = (address, move) map
The type of a map from values of type key
to
values of type value
is map <key, value>
.
type move = [int, int];
type register = map <address, move>;
type nat
type nat
A natural number.
The only size limit to natural numbers is gas.
type operation
type operation
An operation emitted by the contract
type 'value set
type set<'value>
type signature
type signature
A cryptographic signature.
type string
type string
A sequence of characters.
type tez
type tez
A specific type for tokens.
type timestamp
type timestamp
A date in the real world.
type chest
type chest
A timelocked chest.
type chest_key
type chest_key
A key to open a timelocked chest.
type unit
type unit
val is_nat: int -> nat option
let is_nat: (i: int) => option<nat>
Convert an int
to a nat
if possible.
val abs: int -> nat
let abs: (i: int) => nat
Cast an int
to nat
.
val int: nat -> int
let int: (n: nat) => int
Cast an nat
to int
.
val unit: unit
let unit: unit
A helper to create a unit.
val failwith : 'a -> 'b
let failwith: (message: 'a) => 'b
Cause the contract to fail with an error message or integer. Other types are not supported at the moment.
Using this currently requires in general a type annotation on the
failwith
call.
let main (p : int) (_s : unit) : operation list * unit =
if p > 10 then failwith "Failure." else [], ()
let main = (p: int, s: unit): [list<operation>, unit] => {
if (p > 10) { failwith ("Failure."); } else return [list([]), []];
};
val assert : bool -> unit
let assert: (condition: bool) => unit
Check if a certain condition has been met. If not the contract will fail.
val ediv : int -> int -> (int * nat) option
val ediv : mutez -> nat -> (mutez * mutez) option
val ediv : mutez -> mutez -> (nat * mutez) option
val ediv : nat -> nat -> (nat * nat) option
let ediv: (value: int, divided_by: int) => option<[int, nat]>
let ediv: (value: mutez, divided_by: nat) => option<[mutez, mutez]>
let ediv: (value: mutez, divided_by: mutez) => option<[nat, mutez]>
let ediv: (value: nat, divided_by: nat) => option<[nat, nat]>
Compiles to Michelson EDIV
, one operation to get both the quotient and remainder of a division. ediv x y
returns None if y
is zero, otherwise returns Some (quotient, remainder)
such that x = (quotient * y) + remainder
and 0 <= remainder < abs(y)
.
val ignore : 'a -> unit
let ignore: (value: 'a) => 'unit
Ignores a value, it can be an alternative to _
prefixed variables.
type 'n sapling_state
type 'n sapling_transaction
type 'v ticket
Edo protocol introduced the following ticket type. Follow this wallet example for an example of correct usage (it goes with its builder). This article might also be useful.
Note that a variable containing a ticket can only be used once (they are not DUP
-able).
The ticket type can be defined over a comparable type 'v
.
'v
being the type of the value used to identify a given ticket.
type va = int
type my_ticket = va ticket