Commit 34543bd6 authored by J H's avatar J H

Merge branch 'alphanet-to-babylonnet' into 'master'

Alphanet to babylonnet

See merge request !14
parents 0f077c09 13b5ee14
......@@ -97,12 +97,14 @@ let's get our hands dirty with some code.
### Installing the Tezos client
The easiest way to play with Michelson is to install the Tezos client from using
docker. In your terminal type the following commands:
docker. We will follow the instruction from
[How to get Tezos: Docker images](https://tezos.gitlab.io/introduction/howtoget.html#docker-images).
In your terminal type the following commands:
```
$ wget https://gitlab.com/tezos/tezos/raw/alphanet/scripts/alphanet.sh
$ chmod +x ./alphanet.sh
$ ./alphanet.sh start
$ wget -O babylonnet.sh https://gitlab.com/tezos/tezos/raw/babylonnet/scripts/babylonnet.sh
$ chmod +x babylonnet.sh
$ ./babylonnet.sh start
```
This should spit out a bunch of output that you can mostly ignore for now. The
......@@ -110,12 +112,13 @@ important thing is that packaged within the Tezos client is a Michelson runtime
we can use to test our programs.
Alternatively, you can build Tezos from source by following the instructions
in the [Tezos Docs](http://tezos.gitlab.io/zeronet/introduction/howtoget.html)
in the [How to get Tezos: Build form sources](https://tezos.gitlab.io/introduction/howtoget.html#build-from-sources)
page.
## Hello Tezos
Open up your favorite editor and write the following program `helloTezos.tz`
in the same directory you put the `alphanet.sh` script.
in the same directory you put the `babylonnet.sh` script.
```
# helloTezos.tz
......@@ -130,14 +133,14 @@ code { DROP;
First we're going to check that the script is well-typed:
```
$ ./alphanet.sh client typecheck script container:helloTezos.tz
$ ./babylonnet.sh client typecheck script container:helloTezos.tz
```
We can see more information emitted by the typechecker by adding the `--details`
flag:
```
$ ./alphanet.sh client typecheck script container:helloTezos.tz --details
$ ./babylonnet.sh client typecheck script container:helloTezos.tz --details
```
This program should typecheck, but if it doesn't, possible reasons are
......@@ -150,7 +153,7 @@ Now that we know the program typechecks, we're going to run it. The command for
telling the tezos client to run a Michelson program (in a sandbox) is:
```
$ ./alphanet.sh client run script <path> on storage <data> and input <data>
$ ./babylonnet.sh client run script <path> on storage <data> and input <data>
```
where `<path>` is the path to the program source (since we're using docker this
......@@ -159,7 +162,7 @@ will be prepended with `container:`), and `<data>` is some Michelson value.
We'll go over what `storage` and `input` mean below. For now, try running:
```
$ ./alphanet.sh client run script container:helloTezos.tz on storage '""' and input Unit
$ ./babylonnet.sh client run script container:helloTezos.tz on storage '""' and input Unit
```
This should return:
......@@ -231,7 +234,7 @@ The initial stack of a Michelson contract is its argument pair `(pair 'parameter
At the command line we ran
```
$ ./alphanet.sh client run script container:helloTezos.tz on storage '""' and input Unit
$ ./babylonnet.sh client run script container:helloTezos.tz on storage '""' and input Unit
```
`'""'` is the command-line syntax for `""`, the empty string and `Unit` is the
......@@ -436,7 +439,7 @@ constructors.
its input parameter, and outputs `"Hello "` concatenated to its initial
storage. So running
`$./alphanet.sh client run script container:helloStorage.tz on storage '"bar"' and input 'Unit'`
`$./babylonnet.sh client run script container:helloStorage.tz on storage '"bar"' and input 'Unit'`
should output "Hello bar".
......
This diff is collapsed.
......@@ -3,14 +3,14 @@
In the last two chapters, we learned how to write some simple Michelson programs
and how to use the Tezos command-line tools to interact with the Tezos
blockchain. In this chapter we will combine both these topics in order to write
a simple Michelson contract, originate it onto the alphanet chain, and then
a simple Michelson contract, originate it onto the babylonnet chain, and then
interact with it in various ways. This will prepare us for the following
chapters, where we will increase the complexity and sophistication of the
Michelson programs we can write.
## Contract origination
To start, let's push a simple contract onto the Alphanet.
To start, let's push a simple contract onto the Babylonnet.
We'll use the following file `idString.tz`:
......@@ -28,7 +28,7 @@ and the parameter passed to it as the new storage.
Let's test it locally, with the `run` command we learned in chapter 1:
```
$ ~/alphanet.sh client run script container:idString.tz \
$ ~/babylonnet.sh client run script container:idString.tz \
on storage '"foo"' and \
input '"bar"'
```
......@@ -43,11 +43,11 @@ emitted operations
indicating the storage string `"foo"` was replaced by `"bar"`.
Now let's push this contract to the Alphanet using our `alice` account from the
Now let's push this contract to the Babylonnet using our `alice` account from the
previous chapter:
```
$ ~/alphanet.sh client originate contract idString for alice \
$ ~/babylonnet.sh client originate contract idString \
transferring 1 from alice \
running container:idString.tz \
--init '"hello"'
......@@ -69,7 +69,7 @@ storage in bytes. The string "hello" is 5 bytes long, and the size of our
contract (after a little minor compression) is 41. The longer our contract, or
the bigger our storage data, the more we have to pay the network.
This being the Alphanet, the fees are in play-money so we don't have to really
This being the Babylonnet, the fees are in play-money so we don't have to really
pay too much attention to them. Still, this notion of "pay-by-the-byte" is
important to understand: a blockchain as a way to store data scales extremely
poorly with respect to the data's size. Compared to a traditional, more
......@@ -81,10 +81,10 @@ provide an out-of-band mechanism for storing and serving data and have all
on-chain computation work with hashes of that data.
Now let's wait for the operation to get deep enough into the chain so we can
look at it on [tzscan.io](www.tzscan.io):
look at it on [https://babylonnet.tzstats.com](https://babylonnet.tzstats.com):
```
$ ~/alphanet.sh client wait for \
$ ~/babylonnet.sh client wait for \
op2pFJi18njQuGS3MzC39XHw2piXybTFGbAQboCdDNLTYiFTAPN to be included \
--confirmations 5
```
......@@ -114,7 +114,7 @@ We can see all the contracts our client knows about (and has assigned short
nicknames), with
```
$ ~/alphanet.sh client list known contracts
$ ~/babylonnet.sh client list known contracts
idString: KT1TDFxATmqqTcPWPJvrv7XC6EDS82ztRntf
bob: tz1QCUKL2YZuGLSdTesXtVHJB8zRcG6XTz8f
alice: tz1M1tuK4BM53S2niKvQDn6SbACiVk6zbjx4
......@@ -138,8 +138,8 @@ simulate what this command will do, without actually sending anything out to the
network.
```
$ ~/alphanet.sh client transfer 0 from alice to idString \
--arg '"world"' --dry-run
$ ~/babylonnet.sh client transfer 0 from alice to idString \
--arg '"world"' --dry-run
Estimated gas: 11375 units (will add 100 for safety)
Estimated storage: no bytes added
......@@ -175,7 +175,7 @@ Now let's try a `--dry-run` of a transaction that won't work, by calling
`idString` with the parameter `42`:
```
$ ~/alphanet.sh client transfer 0 from alice to idString --arg '42' --dry-run
$ ~/babylonnet.sh client transfer 0 from alice to idString --arg '42' --dry-run
Node is bootstrapped, ready for injecting operations.
This simulation failed:
Manager signed operations:
......@@ -207,7 +207,7 @@ Okay, now let's call the contract `idString` for real with the parameter
`"world"` by removing the `--dry-run` flag:
```
$ ~/alphanet.sh client transfer 0 from alice to idString --arg '"world"'
$ ~/babylonnet.sh client transfer 0 from alice to idString --arg '"world"'
```
After a short wait we should see the updated storage value on the block
......@@ -337,7 +337,7 @@ well as this tutorial) sometimes uses the word "operation" ambiguously for
either, depending on the context. Nevertheless, now that you are aware of the
distinction, the context should clarify which kind of operation is meant. For
example, if you read in the [Michelson
specification](http://tezos.gitlab.io/alphanet/whitedoc/michelson.html#operations-on-optional-values)
specification](http://tezos.gitlab.io/babylonnet/whitedoc/michelson.html#operations-on-optional-values)
the phrase "Operations on optional values", you should infer that since optional
values are elements of the Michelson stack, that the phrase refers to *stack*
operations only.
......@@ -351,7 +351,7 @@ Michelson typechecker automatically adds to help us better read the output.
We'll cover annotations in more detail in a future chapter.
```
$ ~/alphanet.sh client typecheck script container:stringCaller.tz -v
$ ~/babylonnet.sh client typecheck script container:stringCaller.tz -v
Well typed
Gas remaining: 399293 units remaining
{ parameter string ;
......@@ -423,7 +423,7 @@ initial storage we pass to it will be the address of `idString`.
Show the address of `idString` with
```
~/alphanet.sh client show known contract idString
~/babylonnet.sh client show known contract idString
KT1TDFxATmqqTcPWPJvrv7XC6EDS82ztRntf
```
......@@ -431,13 +431,13 @@ KT1TDFxATmqqTcPWPJvrv7XC6EDS82ztRntf
And now paste this into the origination command:
```
$ ~/alphanet.sh client originate contract stringCaller for alice \
$ ~/babylonnet.sh client originate contract stringCaller \
transferring 1 from alice \
running container:stringCaller.tz \
--init '"KT1TDFxATmqqTcPWPJvrv7XC6EDS82ztRntf"'
```
If all went well the contract should now appear on tzScan with the correct
If all went well the contract should now appear on tzStats with the correct
storage:
![tzscan_stringCaller](tzscan_stringCaller_storage.jpg)
......@@ -449,10 +449,10 @@ it with a `--dry-run` on your own first, and then when you're satisfied you
understand what's going on run it for real:
```
$ ~/alphanet.sh client transfer 0 from alice to stringCaller --arg '"caller"'
$ ~/babylonnet.sh client transfer 0 from alice to stringCaller --arg '"caller"'
```
Now look at the storage for `idString` again on tzScan:
Now look at the storage for `idString` again on tzStats:
![tzscan_idString](tzscan_idString_storage3.jpg)
......@@ -481,7 +481,7 @@ Contract.
5. In chapter 1 you were given the semantics of the op codes
you would need to complete each exercise. For this exercise you must practice
looking up the op code semantics on your own. Look up the `or` type in the
[Michelson whitedoc](http://tezos.gitlab.io/alphanet/whitedoc/michelson.html#operations-on-unions)
[Michelson whitedoc](https://tezos.gitlab.io/whitedoc/michelson.html#operations-on-unions)
and its associate op codes.
Write a contract called `stringOrAddr` that takes an `or string address`
......
......@@ -64,10 +64,11 @@ Pairs can be constructed with the `PAIR` operation and with the `PAPAIR` family
of macros.
---
**A brief aside on macros**:
Michelson has several macros that are expanded by the parser into sequences of
operations. You can read about the details here: http://tezos.gitlab.io/zeronet/whitedoc/michelson.html#viii-macros
operations. You can read about the details here: [https://tezos.gitlab.io/whitedoc/michelson.html#macros](https://tezos.gitlab.io/whitedoc/michelson.html#macros)
In practice, you usually don't have to pay attention to the details of the
macro expansions, and can mostly just use them as normal. The one caveat to this
......
# 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. Now let's
on the babylonnet and looked at some of the Michelson data structures. Now let's
take an in-depth look at `tez`, the official Tezos token.
## Terminology
......@@ -33,10 +33,10 @@ If you recall from the second tutorial, we originated a contract with the
following command.
```
$ ~/alphanet.sh client originate contract idString for alice \
transferring 1 from alice \
running container:idString.tz \
--init '"hello"'
$ ~/babylonnet.sh client originate contract idString \
transferring 1 from alice \
running container:idString.tz \
--init '"hello"'
```
The sub command on the second line, `transferring 1 from alice`, means transfer
......@@ -48,13 +48,13 @@ certain conditions are met, it sends some amount of the tezos stored to another
If we want to call the contract and transfer more tezos, we can do the following:
```
$ ~/alphanet.sh client transfer 2 from alice to idString --arg '"Good Evening"'
$ ~/babylonnet.sh client transfer 2 from alice to idString --arg '"Good Evening"'
```
The `idString` contract should now have a balance of 3 tez. We can confirm this by running:
```
$ ~/alphanet.sh client get balance for idString
$ ~/babylonnet.sh client get balance for idString
3 ꜩ
```
......@@ -63,7 +63,7 @@ $ ~/alphanet.sh client get balance for idString
Before we make a new contract, let's go over some useful operations that relate to the
tez stored in the contract.
### [Operations on contracts](http://tezos.gitlab.io/zeronet/whitedoc/michelson.html#operations-on-contracts)
### [Operations on contracts](https://tezos.gitlab.io/whitedoc/michelson.html#operations-on-contracts)
`AMOUNT` gives you the amount of mutez in the current transaction. In our
example above, we had `transferring 1`, so amount would be
......@@ -77,7 +77,7 @@ we originate the `idString` contract above, it has a balance of one tez or
1,000,000 mutez. After the call we made to the contract transferring 2 tez,
calling the `BALANCE` operation would return 3,000,000 mutez.
### [Operations on Mutez](http://tezos.gitlab.io/zeronet/whitedoc/michelson.html#operations-on-mutez)
### [Operations on Mutez](https://tezos.gitlab.io/whitedoc/michelson.html#operations-on-mutez)
The rest are simple math operations directly on mutez, but there are a few
details to watch out for.
......@@ -197,7 +197,7 @@ code {
First type check the game contract.
```
~/alphanet.sh client typecheck script container:game.tz
~/babylonnet.sh client typecheck script container:game.tz
```
I made a new account to be the manager which I called simon. You can use
......@@ -206,30 +206,30 @@ tutorial. Before you originate the contract you will need the address of the
manager.
```
~/alphanet.sh client list known addresses
~/babylonnet.sh client list known addresses
```
Now let's originate the game contract.
```
~/alphanet.sh client originate contract game for simon \
transferring 10 from simon \
running container:game.tz \
--init '(Pair 0 "tz1cSBeSxJf6dK1U8HtMSvPt2hMSYDtbf4JB")' --burn-cap 1
~/babylonnet.sh client originate contract game \
transferring 10 from simon \
running container:game.tz \
--init '(Pair 0 "tz1cSBeSxJf6dK1U8HtMSvPt2hMSYDtbf4JB")' --burn-cap 1
```
Now we can start playing by transferring at least one tez and our guess.
```
~/alphanet.sh client transfer 1 from alice to game2 --arg '2' --burn-cap 1
~/alphanet.sh client transfer 1 from bob to game2 --arg '8' --burn-cap 1
~/babylonnet.sh client transfer 1 from alice to game2 --arg '2' --burn-cap 1
~/babylonnet.sh client transfer 1 from bob to game2 --arg '8' --burn-cap 1
```
You can check the balanceof the contract and its storage at any time.
```
~/alphanet.sh client get balance for game
~/alphanet.sh client get script storage for game
~/babylonnet.sh client get balance for game
~/babylonnet.sh client get script storage for game
```
Keep playing until someone guesses the correct number or after 15 attempts, then
......
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