Skip to content

Commit

Permalink
Interface for Smartpy compiler. (#133)
Browse files Browse the repository at this point in the history
* Drawer for michelson output added.

* Disabled Show Compiled Code button if the code has errors.

* Pushing

* dot-prop added.

* Content updated to use sp.import_script_from_url

* Fixed spacing issues in the content.

* Edge-case for chapters with no code fixed.

* Pushing to see errors, build will fail.

* Fixed errors in markdown

Co-authored-by: Bhaskar Singh <[email protected]>
  • Loading branch information
manangouhari and bhaskarSingh authored Nov 6, 2020
1 parent d88f2c1 commit c8e29e6
Show file tree
Hide file tree
Showing 37 changed files with 16,382 additions and 49 deletions.
2 changes: 2 additions & 0 deletions lessons/inter-contract-calling/01/01.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Intro to Mutez
chapter: Chapter 1
slug: module-02/chapter-01
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down Expand Up @@ -55,6 +56,7 @@ editor:
scenario += test_bot
#scenario.verify over here.
answer: |
import smartpy as sp
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/02/02.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Test Accounts
chapter: Chapter 2
slug: module-02/chapter-02
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/03/03.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: List data-type
chapter: Chapter 3
slug: module-02/chapter-03
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/04/04.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Record data-type
chapter: Chapter 4
slug: module-02/chapter-04
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/05/05.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Inter-contract calling, part-1
chapter: Chapter 5
slug: module-02/chapter-05
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/06/06.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Sub-entry point, loops and local variables
chapter: Chapter 6
slug: module-02/chapter-06
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/inter-contract-calling/07/07.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Inter-contract calling, part-2
chapter: Chapter 7
slug: module-02/chapter-07
filterBy: lesson-2
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/01/01.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Prologue
chapter: Chapter 1
slug: module-01/chapter-01
filterBy: lesson-1
isCode: false
editor:
showEditor: false
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/02/02.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Quick primer on blockchain & smart contract concepts
chapter: Chapter 2
slug: module-01/chapter-02
filterBy: lesson-1
isCode: false
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/03/03.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Introduction to SmartPy
chapter: Chapter 3
slug: module-01/chapter-03
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/04/04.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Scaffolding a basic contract in SmartPy
chapter: Chapter 4
slug: module-01/chapter-04
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/05/05.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Initializing contract's storage
chapter: Chapter 5
slug: module-01/chapter-05
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/06/06.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Simulating initialization of contract with basic testing
chapter: Chapter 6
slug: module-01/chapter-06
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/07/07.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Creating a basic entry point function
chapter: Chapter 7
slug: module-01/chapter-07
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/08/08.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Understanding how SmartPy infers data types
chapter: Chapter 8
slug: module-01/chapter-08
filterBy: lesson-1
isCode: true
editor:
showEditor: false
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/09/09.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with strings & boolean types in SmartPy
chapter: Chapter 9
slug: module-01/chapter-09
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/10/10.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with integers and basic math in SmartPy
chapter: Chapter 10
slug: module-01/chapter-10
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/11/11.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with maps in SmartPy
chapter: Chapter 11
slug: module-01/chapter-11
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/12/12.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with addresses in SmartPy
chapter: Chapter 12
slug: module-01/chapter-12
filterBy: lesson-1
isCode: true
editor:
showEditor: true
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/13/13.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with conditional code in SmartPy - sp.verify
chapter: Chapter 13
slug: module-01/chapter-13
filterBy: lesson-1
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/14/14.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Tinkering with decision making via if & sp.if in SmartPy
chapter: Chapter 14
slug: module-01/chapter-14
filterBy: lesson-1
isCode: true
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/introduction-to-smartpy/15/15.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Ending
chapter: Chapter 15
slug: module-01/chapter-15
filterBy: lesson-1
isCode: true
editor:
showEditor: false
language: python
Expand Down
1 change: 1 addition & 0 deletions lessons/tokens-FA2/01/01.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Intro to tokens
chapter: Chapter 1
slug: module-03/chapter-01
filterBy: lesson-3
isCode: false
editor:
language: python
startingCode: |
Expand Down
1 change: 1 addition & 0 deletions lessons/tokens-FA2/02/02.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Intro to FA2
chapter: Chapter 2
slug: module-03/chapter-02
filterBy: lesson-3
isCode: false
editor:
language: python
startingCode: |
Expand Down
21 changes: 15 additions & 6 deletions lessons/tokens-FA2/03/03.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: FA2 template in SmartPy
chapter: Chapter 3
slug: module-03/chapter-03
filterBy: lesson-3
isCode: true
editor:
language: python
startingCode: |
Expand All @@ -20,11 +21,14 @@ editor:
# Initialize Cyber_Token as cyber_token with single_asset = True
#Add cyber_token to the scenario
answer: |
import smartpy as sp
# Import FA2 template
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
# Define `Cryber_Token`
class Cyber_Token(FA2.FA2):
pass
Expand All @@ -36,6 +40,8 @@ editor:
# Initialize Cyber_Token as cyber_token with single_asset = True
cyber_token = Cyber_Token(FA2.FA2_config(single_asset=True), admin.address)
#Add cyber_token to the scenario
scenario += cyber_token
---

### Intro
Expand Down Expand Up @@ -75,20 +81,22 @@ But what does `single_asset` mean? It signifies whether the token contract has m
To implement a token of your own - you need to import SmartPy's FA2 template and in your own contract, rather than inheriting from `sp.Contract`, you'll inherit from the `FA2` contract.

```python=
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
```
This line is similar to - `import FA2` in plain python.
But because we're writing SmartPy, the rules are different.
You need to use -
1. `sp.import_template` - If your code is running in the SmartPy online IDE.
2. `sp.import_script_from_url` - If you're not using SmartPy's online IDE.

1. `sp.import_script_from_url` - If you're not using SmartPy's online IDE.

2. `sp.import_template` - If your code is running in the SmartPy online IDE. When you use this, you would be required to just pass in `"FA2.py"` as the argument and not the whole URL.

There are a lot of classes in the FA2 template along with the core `FA2` contract which are used in implementing the template in a way that it's easily reusable.

To access the `FA2` contract defined in the template, you need to use the dot(.) notation - `FA2.FA2`, where the first `FA2` represents the template as a whole and the second `FA2` represents the actual contract class defined in the template.

```python=
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Your_Token(FA2.FA2):
pass
Expand Down Expand Up @@ -120,4 +128,5 @@ Take the first steps towards building the universe's most advanced civilization,
#### Step by step walkthrough
1. Import the FA2 template using and set it equal to `FA2`.
2. Define a smart contract - `Cyber_Token` that inherits from the core FA2 contract. (Use `Your_Token`) in the example above as a reference.
3. Initialize `Cyber_Token` with `single_asset=True` and the address to the `admin`.
3. Initialize `Cyber_Token` with `single_asset=True` and the address to the `admin`.
4. Add `cyber_token` to the scenario.
15 changes: 13 additions & 2 deletions lessons/tokens-FA2/04/04.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ title: Interacting with Cyber Token
chapter: Chapter 4
slug: module-03/chapter-04
filterBy: lesson-3
isCode: true
editor:
language: python
startingCode: |
import smartpy as sp
# Import FA2 template
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("FA2.py")
# Define `Cryber_Token`
class Cyber_Token(FA2.FA2):
pass
Expand Down Expand Up @@ -54,7 +55,7 @@ editor:
import smartpy as sp
# Import FA2 template
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
# Define `Cryber_Token`
class Cyber_Token(FA2.FA2):
pass
Expand Down Expand Up @@ -128,7 +129,9 @@ To see how to interact with FA2 based tokens, you need to first know what all en
**1. `transfer`**
This entry point transfers tokens from one account to another.
It accepts two arguments -

1. `from` - This specifies the address of the account from where the tokens need to be sent.

2. `transactions` - It's a list and every item has is a dictionary that has three items -
- `to` - this holds the address of the account tokens are being sent to.
- `amount` - amount of token to be transferred.
Expand All @@ -152,11 +155,15 @@ As the name suggests, it tells you the amount of particular token an account hol

Similar to `transfer`, it accepts a list of requests.
Each item in the list holds -

1. `owner` - Address of the account you want to check the balance for.

2. `token_id` - ID of the token for which you want to check the balance.

It goes through the list and sends to a `consumer` a `response` list, each item in the list has 2 fields -

1. `balance` - this is the amount of a specific token the account holds.

2. `request` - this is the exact `request` that was sent to the entry point in the list.

So, each item in the `response` list ends up looking like -
Expand All @@ -178,9 +185,13 @@ Here what happens is, when calling `balance_of`, we also pass in a `consumer`(th
It creates a specified number of tokens in an account. This is how you'll jump-start your society's economy.
FA2 standard doesn't specify any details for `mint` but the FA2 template in SmartPy has built a `mint` entry point that we can use.
It accepts 4 arguments -

1. `address` - Address to the account where you want to mint the tokens.

2. `amount` - Number of tokens you want to create.

3. `symbol` - Symbol to represent this token(Like dollars have $).

4. `token_id` - 0 in case you only have a single-asset fungible tokens. Used by FA2 standard to differentiate between different tokens.


Expand Down
5 changes: 3 additions & 2 deletions lessons/tokens-FA2/05/05.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ title: Buidl your own bot
chapter: Chapter 5
slug: module-03/chapter-05
filterBy: lesson-3
isCode: true
editor:
language: python
startingCode: |
import smartpy as sp
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Cryptobot(FA2.FA2):
Expand Down Expand Up @@ -63,7 +64,7 @@ editor:
answer: |
import smartpy as sp
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Cryptobot(FA2.FA2):
Expand Down
5 changes: 3 additions & 2 deletions lessons/tokens-FA2/06/06.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ title: Hiring a bot manager
chapter: Chapter 6
slug: module-03/chapter-06
filterBy: lesson-3
isCode: true
editor:
language: python
startingCode: |
import smartpy as sp
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Cryptobot(FA2.FA2):
Expand Down Expand Up @@ -75,7 +76,7 @@ editor:
answer: |
import smartpy as sp
FA2 = sp.import_template("FA2.py")
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Cryptobot(FA2.FA2):
Expand Down
Loading

0 comments on commit c8e29e6

Please sign in to comment.