Commit 3735979f authored by J H's avatar J H

Improve title and add more details to the post

parent d3a2eaea
# Part V: Tezos Tokens in Michelson
# Part V: Tez in Michelson
We've gone over how to write simple contracts in Michelson, originate them on
on the alphanet and looked at some of the Michelson data structures.
on the alphanet and looked at some of the Michelson data structures. Now let's
take an in-depth look at `tez`, the official Tezos token.
## Terminology
......@@ -95,6 +96,14 @@ value.
The same rules apply as `ADD`. If the result is greater than
9,223,372,036,854,775,807 mutez, it will abort with an overflow error.
You can convert `nat` to `mutez` with the following code (assuming the top of
the stack is `nat`).
```
PUSH nat 1;
MUL; # the result of MUL nat mutez is mutez
```
`EDIV` divides `x` by `y` If it divides by zero, it
will returns `None`, otherwise it returns `Some (Pair (x / y) (x % y))`
where `/` is integer division and `%` is modulus or the remainder of integer
......@@ -102,8 +111,14 @@ division. There are two sets of types you can apply `EDIV` on. `mutez` and
`nat` which returns `option (pair mutez mutez)`, and `mutez` and `mutez`
which returns `option (pair nat mutez)`.
You can convert a `mutez` to `nat` with the following code (assuming a
mutez is on the top of the stack).
You can convert `mutez` to `nat` with the following code (assuming the top of
the stack is `mutez`).
```
DIP { PUSH mutez 1; }; # put one below the mutez value we are converting
EDIV; # EDIV mutez mutez
IF_SOME { CAR; } { PUSH string "This shouldn't happend"; FAILWITH; }; # get the result of integer division, which is a nat
```
`COMPARE` compares two mutez value and returns an int of three possible
values:
......@@ -112,12 +127,6 @@ values:
- iff `x = y` then `0`
- iff `x > y` then `1`
```
DIP { PUSH mutez 1; }; # put one below the mutez value we are converting
EDIV; # EDIV mutez mutez
IF_SOME { CAR; } { PUSH string "This shouldn't happend"; FAILWITH; }; # get the result of integer division, which is a nat
```
## Guess My Number Contract
Let's write a fun contract that involves two or more parties. The contract
......@@ -250,7 +259,9 @@ There are many security flaws and ways we can improve the game contract.
5. The biggest flaw is that the answer is hardcoded in the game. The
participants could read the source code and get the answer. Is there a way
the contract can hide the value?
the contract can hide the value? (How to implement is beyond the scope of
this lesson, we will approach that in later, but try to come up with a
conceptual way of hiding the value.)
# Appendix A: Tezos Tokens Terminology
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment