Skip to main content
Version: Next

tez

The token unit on Tezos is called tez in LIGO. There are several ways to write literal values of type tez:

  • Units of millionths of tez, using the suffix mutez after a natural number, like 10000mutez or 0mutez
  • Units of tez, using the suffix tz or tez, like 3tz or 3tez
  • Decimal amounts of tz or tez, like 12.3tz or 12.4tez

LIGO uses the type tez, not mutez. The suffix mutez is only for writing literal amounts of millionths of tez.

Like integers and nats, you can express large amounts of tez with underscores to separate groups of digits, like 1_000mutez (one thousand mutez) or 0.000_004tez.

Adding

You can add amounts of tez with the + operator, as in the following example. You cannot add amounts of tez to integers or nats.

const sum: tez = 5mutez + 1tez;

Subtracting

Because subtracting two amounts could result in a negative amount, subtracting two tez amounts results in an optional amount, as in these examples:

const amount: option<tez> = 5mutez - 1mutez; /* Some (4mutez) */
const negative: option<tez> = 1mutez - 5mutez; /* None */

Multiplying

You can multiply nat and tez values:

const mult: tez = 5n * 5mutez;

Dividing

Because LIGO features neither floating-point nor fixed-point arithmetic, division in LIGO is Euclidean. Dividing two tez values returns the quotient of the operation as a nat.

const div: nat = 10mutez / 3mutez;

Euclidean Division

For cases when you need both the quotient and the remainder, LIGO provides the ediv operation. ediv(x,y) returns Some (quotient, remainder), unless y is zero, in which case it returns None. The function ediv is overloaded to accept tez, beyond all the combinations of natural and integer numbers:

// Some (7, 2mutez)
const ediv1: option<[nat, tez]> = ediv(37mutez, 5mutez);
// Some (7mutez, 2mutez)
const ediv2: option<[tez, tez]> = ediv(37mutez, 5n);