Skip to content

Commit

Permalink
Merge branch 'master' of github.com:octo-technology/tezos-academy
Browse files Browse the repository at this point in the history
 Please enter a commit message to explain why this merge is necessary,
  • Loading branch information
AymericBethencourt committed Jul 19, 2020
2 parents 8af59b4 + 7c87a0a commit b48a243
Show file tree
Hide file tree
Showing 36 changed files with 1,015 additions and 1,238 deletions.
6 changes: 0 additions & 6 deletions src/frontend/src/app/App.components/Drawer/Drawer.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export const DrawerView = ({
)
else return <div key={chapter.pathname} />
})}

<DrawerItem className={pathname === '/coming-next' ? 'current-path' : 'other-path'}>
<Link to="/coming-next" onClick={() => hideCallback()}>
What's next?
</Link>
</DrawerItem>
</DrawerStyled>
</>
)
Expand Down
20 changes: 16 additions & 4 deletions src/frontend/src/pages/Chapter/Chapter.data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,33 @@ export const chapterData = [
{
pathname: '/pascal/chapter-interop',
language: 'PascaLIGO',
name: '26- Pascal - Interoperability',
name: '26 - Pascal - Interoperability',
data: pascalDataInterop,
},
{
pathname: '/pascal/chapter-preprocessor',
language: 'PascaLIGO',
name: '27- Pascal - Preprocessor',
name: '27 - Pascal - Preprocessor',
data: pascalDataPreprocessor,
},
{
pathname: '/pascal/chapter-fa2',
language: 'PascaLIGO',
name: '28- Pascal - FA2',
name: '28 - Pascal - FA2',
data: pascalDataFA20,
},
{
pathname: '/pascal/chapter-fa2-operator',
language: 'PascaLIGO',
name: '29- Pascal - FA2 Operator',
name: '29 - Pascal - FA2 Operator',
data: pascalDataFA20Operator,
},
{
pathname: '/pascal/chapter-fa2-hook',
language: 'PascaLIGO',
name: '30 - Pascal - FA2 Hook',
data: camelDataFA20Hook,
},

{
pathname: '/camel/chapter-about',
Expand Down Expand Up @@ -488,4 +494,10 @@ export const chapterData = [
name: '29 - Reason - FA2 Operator',
data: reasonDataFA20Operator,
},
{
pathname: '/reason/chapter-fa2-hook',
language: 'ReasonLIGO',
name: '30 - Reason - FA2 Hook',
data: camelDataFA20Hook,
},
]
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Chapter 22 : Deploy & Invoke
# Chapter 23 : Deploy contract

<dialog character="admiral"> Time to go live.</dialog>


## Smart contract

A smart contract is code written in Michelson langage (a low-level stack-based turing-complete language).
It contains entrypoints which describe all possible way to interact with a smart contract.
It contains prototype of each entrypoint. What kind of parameters are exepected to execute an entrypoint
A smart contract is code written in Michelson langage (a low-level stack-based turing-complete language).
It contains entrypoints which describe all possible way to interact with a smart contract.
It contains prototype of each entrypoint. What kind of parameters are exepected to execute an entrypoint
It contains the description of storage.

### Storage
Expand All @@ -18,21 +17,20 @@ The description of the storage is done by strongly-typing the data structure.

### Entrypoints

Entrypoints of a smart contract describe how to mutate a storage.
Entrypoints of a smart contract describe how to mutate a storage.
Executing an entrypoint takes some parameters and a state of a storage and returns a new state of storage and some operations

![](/images/contract_in_out.png)


Execution of an entrypoint produces a new state of the storage of the smart contract. If executopn did not throw an exception and did not fail then the new state of storage is applied.

Operations are transactions (smart contract invocation) that will be sent to some other contracts and will trigger an entryppoint of the targeted contract or a tez transfer (no invocation of entrypoint). If execution of an entrypoint produces operations (ordered list of transactions) then they are sent and executed following order of the list of operation.

## Deploy

A smart contract must be deployed to the blockchain in order to be invoked. When deploying a smart contract ot the blockchain , one must specify the initial state of the storage.
A smart contract must be deployed to the blockchain in order to be invoked. When deploying a smart contract ot the blockchain , one must specify the initial state of the storage.
Deployment of a smart contract in Tezos is called "origination".
Here is the syntax of the tezos command line to deploy a smart contract :
Here is the syntax of the tezos command line to deploy a smart contract :

```
tezos-client originate contract <contract_name> for <user> transferring <amount> from <from_user> \
Expand All @@ -47,31 +45,28 @@ tezos-client originate contract <contract_name> for <user> transferring <amount>
<initial_storage> is a Michelson expression. The --init parameter is used to specify initial state of the storage.
<gaz> it specifies the the maximal fee the user is willing to pay for this operation (using the --burn-cap parameter).


## Invoke

Once the smart contract has been deployed on the blockchain (contract-origination operation baked into a block), it is possible to invoke an entrypoint of the smart contract using the command line.

Here is the syntax of the tezos command line to invoke a smart contract :
Here is the syntax of the tezos command line to invoke a smart contract :

```
tezos-client transfer <amount> from <user> to <contract_name> --arg '<entrypoint_invocation>' --dry-run
```

<amount> is the quantity of tez being transfered to the contract.
<contract_name> name given to the contract
<entrypoint_invocation> name of the entrypoint and corresponding parameters. exemple 'Increment(5)'.
<entrypoint_invocation> name of the entrypoint and corresponding parameters. exemple 'Increment(5)'.

⚠️ Notice the --arg parameter specifies an entrypoint call.

⚠️ Notice the --dry-run parameter simulate invocation of the entrypoint.



## Ligo compiler

In order to produce a smart contract, a tool called transpiler (aka LIGO compiler) is used to transform LIGO code into Michelson code.
Michelson smart contract are stored in a file with .tz extension.
Michelson smart contract are stored in a file with .tz extension.

This ligo compiler is also used to transform "Ligo expression" into "Michelson expression" as needed to deploy or invoke a smart contract.

Expand All @@ -82,6 +77,7 @@ Here is how to transform ligo code into Michelson code using the ligo compiler i
```
ligo compile-contract code.mligo mainFunc > code.tz
```

<mainFunc> argument is the name of the "main function" in the .ligo file. (see Chapter "Main Function").

⚠️ Notice the output of the command is the Michelson code. We just redirect the command output into a .tz file.
Expand All @@ -96,7 +92,6 @@ ligo compile-storage [options] code.mligo mainFunc '<expression>'

<expression> is a ligo expression


### Invocation parameter

Here is how to transform ligo expression into Michelson expression using the ligo compiler in command line.
Expand All @@ -107,21 +102,20 @@ ligo compile-parameter [options] code.mligo mainFunc '<expression>'

<expression> is a ligo expression


### Simulating
### Simulating

Here is how to simulate execution of an entrypoint using the ligo compiler in command line.

```
ligo dry-run [options] code.mligo mainFunc '<entrypoint(p)>' '<storage_state>'
```

<storage_state> state of the storage when simulating execution of the entrypoint
<entrypoint(p)> entrypoint of the smart contract that is invoked (parameter *p* of this entrypoint is specified between parantheses).
<storage*state> state of the storage when simulating execution of the entrypoint
<entrypoint(p)> entrypoint of the smart contract that is invoked (parameter \_p* of this entrypoint is specified between parantheses).

### Ligo Expression in command line

Let's see some exemple how to transpile a storage ligo expression into a michelson one.
Let's see some exemple how to transpile a storage ligo expression into a Michelsonone.

Let's consider this smart contract which associate coordinates to a planet name.

Expand All @@ -148,9 +142,9 @@ let main (action,store : parameter * storage): return =

#### Maps

The _Map.literal_ predifined function can be used to initialize a *map*
The _Map.literal_ predifined function can be used to initialize a _map_

The command line *ligo compile-storage* for transpiling a map containg a tuple.
The command line _ligo compile-storage_ for transpiling a map containg a tuple.

```
ligo compile-storage starmap.mligo main 'Map.literal [("earth", (1,1,1))]'
Expand All @@ -160,7 +154,7 @@ ligo compile-storage starmap.mligo main 'Map.literal [("earth", (1,1,1))]'

Initialization of elements of a tuple is specified between _(_ and _)_ separated by comma _,_.

The command line *ligo compile-storage* for transpiling a map containg a tuple.
The command line _ligo compile-storage_ for transpiling a map containg a tuple.

```
ligo compile-storage starmap.mligo main 'Map.literal [("earth", (1,1,1))]'
Expand All @@ -177,10 +171,10 @@ This command returns :
Initialization of elements of a record is specified between _{_ and _}_ separated by comma _;_. Each element is a key/value pair seperated by _=_ and follow the syntax :

```
{ <key1> = <value1>; <key2> = <value2> }
{ <key1> = <value1>; <key2> = <value2> }
```

Let's modify our type *coordinates* to be a record instead of a tuple.
Let's modify our type _coordinates_ to be a record instead of a tuple.

```
// starmap2.mligo
Expand All @@ -198,8 +192,7 @@ let main (action,store : parameter * storage): return =
| DoNothing -> (([] : operation list),store)
```


The command line *ligo compile-storage* for transpiling a map containg a record tuple.
The command line _ligo compile-storage_ for transpiling a map containg a record tuple.

```
ligo compile-storage starmap2.mligo main 'Map.literal [("earth", {x=1;y=1;z=1})]'
Expand Down Expand Up @@ -243,9 +236,6 @@ let main (action,store : parameter * storage): return =
| DoNothing -> (([] : operation list),store)
```



<!-- prettier-ignore -->1- Write _compile-storage_ command and the ligo expression for initializing the *Sol* system containing planet "earth" with coordinates (2,7,1).

<!-- prettier-ignore -->2- Write _dry-run_ command and the ligo expression for adding a planet "mars" with coordinates (4,15,2) in our *Sol* system. Reuse the *Sol* system of step 1.

<!-- prettier-ignore -->2- Write the _dry-run_ command and the ligo expression for adding a planet "mars" with coordinates (4,15,2) in our *Sol* system. Reuse the *Sol* system of step 1.
Loading

0 comments on commit b48a243

Please sign in to comment.