Skip to content

Commit

Permalink
module-04 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
manangouhari committed Mar 16, 2021
1 parent 077a417 commit 370dc23
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 96 deletions.
35 changes: 20 additions & 15 deletions lessons/taquito/01/01.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ editor:
print(FAUCET_KEY.pkh)
---
### Intro
## Intro

In this module, there are no right answers :P

We'll take you through the whole process of originating(or deploying) a smart contract on the Tezos blockchain using Javascript, but, we'll complete a chapter complete when you click on 'Next'.

Doesn't mean we've left you high and dry, we got your back.
You can always check reference code from the "Show Answer" tab!

On this adventure, we'll use the Taquito library - library for development on the Tezos blockchain.
On this adventure, we'll use the <span class="string-highlight">Taquito library</span> - library for development on the Tezos blockchain.

And, we'll deploy and interact with `Cyber_Token` - our very own fungible token that we learned how to develop in the previous module.

### Study time
## Study time
Taquito is a library that makes it really easy to make DApps over the Tezos blockchain.
It can do a whole range of things -
- Originate a smart contract
Expand All @@ -62,6 +65,8 @@ It can do a whole range of things -
- Call an entry point
- Check contract's global storage

<br />

There's a few more to it but these are the features that we'll explore in this module.

The code we'll write can work both in the browser and the Node environment, so we won't show you how to wire this up with the UI or a CLI but you can essentially drop the code right into a React or Vue app and it should work without any issues.
Expand All @@ -71,34 +76,34 @@ In this chapter we'll start our journey by creating a Tezos testnet account whic

### Show me an example
To install taquito -
```javascript=
```shell
npm install @taquito/taquito // or yarn add @taquito/taquito
```
Importing the `Tezos` object -
```javascript=
```javascript
import { TezosToolkit } from `@taquito/taquito`
```
Almost all the magic happens through the `TezosToolkit` object we imported right here.

### #buidl-ing time
## #buidl-ing time

#### New feature request!
### New feature request!
You've made quite a few smart contracts so far but now it's time to originate them - for that you need to create an account on the testnet and set it up.

#### Step by step walkthrough
### Step by step walkthrough

> Note: We're already imported `TezosToolkit` and initialized a bunch of other stuff to make this whole journey a little bit smoother for you.
1. Generate your faucet account -
1. Visit the Tezos Faucet - https://faucet.tzalpha.net
2. Click on "Get testnet ꜩ" (will explain "testnet" in a future chapter)
3. Copy and save the whole JSON output it gives you, this data basically signifies your account on the testnet.
2. Set the JSON obtained in the previous step as the `FAUCET_KEY` in the code which is a constant(use the `const` keyword).
3. Activate the testnet account.
#### 1. Generate your faucet account -
1. Visit the Tezos Faucet - https://faucet.tzalpha.net
2. Click on "Get testnet ꜩ" (will explain "testnet" in a future chapter)
3. Copy and save the whole JSON output it gives you, this data basically signifies your account on the testnet.
4. Set the JSON obtained in the previous step as the `FAUCET_KEY` in the code which is a constant(use the `const` keyword).
5. Activate the testnet account.
1. Head over to https://smartpy.io/dev/wallet.html
2. Click on "Faucet Accounts" and then "Faucet Importer".
3. Paste the JSON recieved from the Tezos Faucet in the visible textarea.
4. Hit "Compute your private key".
5. Click "Save Account in Wallet" - this isn't necessary but saving the account in wallet will later give you easy access to all the contracts deployed from this testnet account through the SmartPy explorer.
6. Finally, click "Activate account".
4. Print the `FAUCET_KEY.pkh` to the console, this is the address of your account.
6. Print the `FAUCET_KEY.pkh` to the console, this is the address of your account.
18 changes: 11 additions & 7 deletions lessons/taquito/02/02.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,31 @@ editor:
print(Tezos.signer._key.key)
---
### Intro
## Intro
Well we've generated our Faucet account and activated it.

Now we need to **sign** it as well.
It's required if you want to inject operations into the Tezos blockchain.

### Study time
## Study time

Taquito supports multiple different signers but none are configured by default.

We're going to use `InMemorySigner` - it's best suited for development and testing, not so much for production.

When you're writing code for production that deals with tokens of real value, we suggest using [@taquito/beacon-wallet](https://tezostaquito.io/docs/tezbridge_signer).

### Show me an example

Import the signer -
```javascript=
```javascript
npm install @taquito/signer // or yarn add @taquito/signer
```

<br />

Using the `inMemorySigner` -
```javascript=
```javascript
import { importKey } from "@taquito/signer"

importKey(
Expand All @@ -110,14 +114,14 @@ importKey(
As the first argument, `importKey` takes in the `Tezos` instance and rest all is the data that's needed for signing which we obtained through the faucet.

Once you sign your account, you can check it in the Tezos instance using -
```javascript=
```javascript
print(Tezos.signer._key.key)
```
>Note: To print content in the output on our interface, you'll have to use `print` as a replacement of `console.log`.
### #buidl-ing time
## #buidl-ing time


#### Step by step walkthrough
### Step by step walkthrough
1. Use `importKey` to sign your account. We've already imported it from `@taquito/signer`.
2. Print `Tezos.signer._key.key`
21 changes: 13 additions & 8 deletions lessons/taquito/03/03.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,36 @@ editor:
print(Tezos._rpc)
---
### Intro
## Intro

When you develop an application - do you directly deploy it with ZERO testing?

That's what the testnets exist for, to originate your contract on for testing.

Once you've thoroughly tested your contract, you can originate on the **mainnet**, where tokens have real value.

On testnet, tokens don't have real value - hence, you can test as much as you'd like.

### Study time
## Study time

There are 3-4 testnets but currently **delphinet** is the one that's being used and it's the one that we'll be originating our contracts on as well.

Youneed to provide the RPC url when you instantiate the Tezos object through -
```
You need to provide the RPC url when you instantiate the Tezos object through -

```javascript
const Tezos = new TezosToolkit('https://api.tez.ie/rpc/delphinet')
```

<br />

But then, you can change the RPC url too through -
```javascript=
```javascript
Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/delphinet' });
print(Tezos._rpc); // prints the network you're connected to.
```

### #buidl-ing time
## #buidl-ing time

#### Step by step walkthrough
### Step by step walkthrough
- Use `Tezos.setProvider` to specify you're using **delphinet**.
- Print the rpc you've connected to.
- Print the rpc you've connected to.
22 changes: 10 additions & 12 deletions lessons/taquito/04/04.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1734,12 +1734,12 @@ editor:
};
---
### Intro
## Intro
Michelson is the language than runs on the Tezos network, rest all higher-level languages are an abstraction over it which directly compile to michelson.

### Study time
## Study time

To deploy contracts through Taquito you need to grab the "Code JSON" and "Storage JSON" for the contract that you wrote in SmartPy and this process is made SUPER EASY thanks to the [SmartPy IDE](https://smartpy.io/dev) - it generates "Storage JSON" and "Code JSON" for you which you can directly copy.
To deploy contracts through Taquito you need to grab the "Code JSON" and "Storage JSON" for the contract that you wrote in SmartPy and this process is made SUPER EASY thanks to the [SmartPy IDE](https://smartpy.io/ide) - it generates "Storage JSON" and "Code JSON" for you which you can directly copy.

### Show me an example
If we've the following contract -
Expand Down Expand Up @@ -1771,33 +1771,31 @@ def test():
```

It generates the following **Code JSON** -
```json=
```json
[
{ "prim": "storage", "args": [ { "prim": "int" } ] },
{ "prim": "parameter", "args": [ { "prim": "unit" } ] },
{ "prim": "code", "args": [ [ { "prim": "CDR" }, { "prim": "NIL", "args": [ { "prim": "operation" } ] }, { "prim": "PAIR" } ] ] }
]
```
And **Storage JSON** -
```json=
```json
{ "int": "5" }
```

### #buidl-ing time
## #buidl-ing time

#### New feature request!
### New feature request!
We're going to generate the JSON Code and Storage for the contract we want to originate and store it in our code.
This is super important for originating(deploying) a contract, because Tezos blockchain only understands Michelson.

#### Step by step walkthrough
### Step by step walkthrough
1. Grab the **Code JSON** and **Storage JSON** for the contract -
1. Head over the following link to the [SmartPy IDE](https://smartpy.io/ide?code=eJxtkE9vwjAMxe_9FFa4NBrjsCMa0xB_NC47APeQtqaL1iZVYoY6xHefmwLbJCq1Vfz883uOqRvnCUKtPTUt6AChSZIBrPr6cvoEhHVTacKkO0xYH5koqquQClZGTSskg3PcG4uwm_k2Q6@27hPtLskrHQLMfktph_Arxwnw07CcJK88WxcFDw6UWl0j24nlwZYmqxAixx4F7iF2XNiQo9XeuD5bp6hrKZWxI34G0BwIWnfwcNRVhQRs5ZFjGQv0gfDFhO6MMqzccXQDdVFzRxx@IVLxvHrfLNZbNZ3P14vNRr0t1osXzpZEIo97UpeXuTtbq9zZvSnTYGxZoeLlkSZbf0A5vNnF_xBqJF1o0n2AzJSq1k16ij5CjGOx5aWV26tAngemgvDbhcdAzusSx@xFaEnIYQ9dz_dZIU6iu3oBYxAx@uXizyzJs5T_7_xh8nfbqP0Apoa9VA--) - we've pre-loaded the script for `Cyber_token`.
1. Head over the following link to the [SmartPy IDE](https://smartpy.io/ide?cid=QmT1Kn7rtZbtM89oM75MSxmM7CwBUUng7goqVRBEWVSgM8&k=a187fb27545a0bf44f31) - we've pre-loaded the script for `Cyber_token`.
1. Replace your wallet address for admin -
- Several operations in a fungible token require to be called by the `admin`. We'll be injecting operations through the account that you obtained from the faucet, hence, that account needs to be specified as the `admin` in our code for the fungible token.
1. In the account data you generated from the faucet, there's a key `"pkh"`(value starts from "tz") - this is your wallet address and stands for "public key hash"
2. In the SmartPy code, initialize the admin interfact with the value of your `pkh`.
- Eg: `admin = sp.address("tz1WvExrfb4hPQZhoXeY8DqmmtvceYnDv8Pt")`

2. In the SmartPy code, initialize the admin interfact with the value of your `pkh`. Eg: `admin = sp.address("tz1WvExrfb4hPQZhoXeY8DqmmtvceYnDv8Pt")`
2. Run the smart contract in the IDE.
3. The first section that you see in the output is your contract, click on "Deploy Michelson Contract".
4. Click "Code JSON" and copy the code from there.
Expand Down
18 changes: 11 additions & 7 deletions lessons/taquito/05/05.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ editor:
print(error)
})
---
### Intro
## Intro
Everything on the blockchain has a cost.

Each contract you deploy, each byte you store, each operation you perform - everything costs.

Wouldn't you want to know how much will it cost you to originate a smart contract?
Like you don't buy a t-shirt without checking the price, do you?

### Study time
## Study time

Taquito's estimate method can be used to estimate fees, gas and storage associated with an operation, even originating a contract is an operation.

```javascript=
```javascript
Tezos.estimate.originate({
code: CODE_JSON,
init: STORAGE_JSON
Expand All @@ -54,6 +54,9 @@ Tezos.estimate.originate({
})
.catch(error => print(`Error: ${JSON.stringify(error, null, 2)}`));
```

<br />

You need to pass the `CODE_JSON` and `STORAGE_JSON` for the contract that you grabbed in the previous chapter, and it returns the following properties -

- `burnFeeMutez`: The number of Mutez that will be burned for the storage of the operation.
Expand All @@ -64,9 +67,10 @@ You need to pass the `CODE_JSON` and `STORAGE_JSON` for the contract that you gr
- `totalCost`: The sum of minimalFeeMutez + burnFeeMutez. Returns a number.
- `usingBaseFeeMutez`: Fees according to your specified base fee will ensure that at least minimum fee is used.

<br />

You can even check the balance available in your account through Taquito -
```javascript=
```javascript
Tezos.tz
.getBalance("<YOUR_ADDRESS>")
.then(balance => print(`${balance.toNumber() / 1000000}`))
Expand All @@ -75,11 +79,11 @@ Tezos.tz
> Note: To print things as output in our interface, you need to use `print`.
We're dividing the balance by 1000000 because, it returns the balance in **mutez**, to convert it to **tez** - we divide it with 1000000.

### #buidl-ing time
## #buidl-ing time

#### New feature request!
### New feature request!
It's time for the moment of truth, let's see how much it costs to originate our contract.

#### Step by step walkthrough
### Step by step walkthrough
1. Pass in the `CODE_JSON` as `code` and `STORAGE_JSON` as `init`.
2. Print to the console `totalCost` required for the operation.
19 changes: 12 additions & 7 deletions lessons/taquito/06/06.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ editor:
.catch(error => print(error))
---
### Intro
## Intro
The time has finally come to originate our contract, finally.

### Study time

## Study time
It's a super straightforward process to origiante a contract using Taquito - all you need to do is give it the `CODE_JSON` and `STORAGE_JSON`, rest it handles under the hood for you.


### Show me an example
## Show me an example
> Note: You need to use `print` as a replacement of `console.log` to output content on our platform
```javascript=
```javascript
Tezos.contract.originate({
code: CODE_JSON,
init: STORAGE_JSON
Expand All @@ -61,14 +60,20 @@ Tezos.contract.originate({
})
.catch(error => print(error))
```

<br />

First, we're giving it the `CODE_JSON` and `STORAGE_JSON`.
After that, it's mostly the necessary steps - it returns an origination operation, this it the intermediate step where you've sent your contract for origination and waiting for confirmation.

Next, when you get the origination confirmation back, we're returning the originated contract to the next block.

### #buidl-ing time
## #buidl-ing time

#### Step by step walkthrough
### Step by step walkthrough
- Originate the contract using `Tezos.contract.originate` and pass it the `CODE_JSON` and `STORAGE_JSON` (use the code snippet present above).
**- Don't forget to copy/store the contract address that's being printed to the console, we'll use it in the next few chapters!**

<br />

In a React application you would ideally store the resultant contract as a state variable but we're not choosing to do that to keep this tutorial as isolated as possible from your framework/environment of choice.
Loading

0 comments on commit 370dc23

Please sign in to comment.