Skip to content
On this page

Mutez โ€‹

The type of amounts in SmartPy is sp.TMutez.

The corresponding type in Michelson is

Michelson mutez.

Literals โ€‹

sp.tez(<natural number>), sp.mutez(<natural number>)
Introduce a mutez.

Example โ€‹

python
# Two identical amounts (one tez):
sp.tez(1)
sp.mutez(1000000)

Global properties โ€‹

Get transferred amount โ€‹

sp.amount
The amount of the current transaction, which is of type sp.TMutez.

Example โ€‹

python
amount = sp.amount
Michelson AMOUNT

Get contract balance โ€‹

sp.balance
The balance of the current contract.
Due to the not intuitive semantics in Michelson, we suggest that developers do not rely on balance too much.

See Tezos Agora Post.
In tests, a contract's balance is accessible through the <contract>.balance field.

Example โ€‹

python
balance = sp.balance
Michelson BALANCE

Operations โ€‹

Addition โ€‹

expr1 + expr2
Add two values of type sp.TMutez, expr1 and expr2.

Example โ€‹

python
result = sp.mutez(10) + sp.tez(1) # 1000010 of type sp.TMutez
Michelson ADD

Subtraction โ€‹

expr1 - expr2
Subtract two values of type sp.TMutez, expr1 and expr2.
This operation fails if the result is negative.

Example โ€‹

python
result = sp.mutez(20) - sp.mutez(10) # 10 of type sp.TMutez

sp.sub_mutez(expr1, expr2)
Subtract two values of type sp.TMutez, expr1 and expr2.
Returns a sp.TOption(sp.TMutez). This operation doesn't fail.

sp.sub_mutez(a, b)ย == sp.some(a-b) when a-b is a non negative and sp.none otherwise.

Example โ€‹

python
result = sp.sub_mutez(sp.mutez(20) - sp.mutez(10)) # sp.some(sp.mutez(10))
result2 = sp.sub_mutez(sp.mutez(10) - sp.mutez(20)) # sp.none
Michelson SUB

Multiplication โ€‹

sp.mul(<expr1>,ย <expr2>)
Multiply a sp.TMutez with a sp.TNat and produce a sp.TMutez.

Example โ€‹

python
value = sp.mul(sp.nat(2), sp.mutez(2)) # 4 of type sp.TMutez

Division โ€‹

sp.ediv(expr1, expr2)
Perform euclidean division, where expr1 is the dividend, and expr2 is the divisor.

Example โ€‹

python
(quotient, remainder) = sp.match_pair(sp.ediv(sp.tez(11), sp.tez(2)).open_some())
Michelson EDIV

Split tokens โ€‹

sp.split_tokens(amount, quantity, totalQuantity)
Compute amount * quantity / totalQuantity where amount is of type sp.TMutez, quantity and totalQuantity are of type sp.TNat.

Example โ€‹

python
sp.split_tokens(sp.mutez(100), 1, 10) # 10 mutez