Base Types

Numerical (nat, int, timestamp, mutez)

Nat

Nat type represents natural numbers (positive integers U { 0 }); a nat literal should be always followed by an n.

const a: nat = 12n;

A nat value can be converted to int type using the int(nat) builtin function:

const b: int = int(12n);

Int

Int type represents integer numbers; we define an int:

const a: int = 12;

We can check if the int is a nat:

const b1: bool = isNat(12);  // true
const b2: bool = isNat(-12); // false

Transform an int to a nat:

const c: nat = abs(-12);

And negate a nat or int (the result type is always an int):

const d1: int = neg(12n);   // = -12
const d2: int = neg(-12);   // = 12

Mutez

Mutez type represents a tez amount. A mutez literal si preceeded by mtz or tz; 1000000mtz = 1tz.

Timestamp

Timestamp type represent an unix timestamp (seconds since Jan 01 1970).

We also have an helper called Timestamp.duration which produces an int value for a duration.

We can get the current timestamp using the now function:

Bool

Bool type represents a boolean, which has two possible values: true and false.

Enum

Enum type are unit variants; low level are represented as nat, so they are comparable (only for equality).

String

String are sequences of characters.

We can get the length of a string with size:

And get a slice:

Bytes

Bytes are sequences of bytes. Like strings you can get the length and a slice.

Bytes type is useful for encoding/decoding Michelson data using pack and unpack:

Unit

The unit type is a type which has only a value Unit.

Last updated

Was this helpful?