Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed old syntax in 03.mdx #359

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lessons/tokens-FA2/03/03.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ editor:
import smartpy as sp

# Import FA2 template
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
FA2 = sp.io.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
# Define Cyber_Token
class Cyber_Token(FA2.FA2):
pass
Expand All @@ -38,7 +38,7 @@ editor:
admin = sp.test_account("Decentralized Dictator")

# Initialize Cyber_Token as cyber_token with single_asset = True
cyber_token = Cyber_Token(FA2.FA2_config(single_asset=True, assume_consecutive_token_ids = False), admin = admin.address, metadata = sp.big_map({"": sp.bytes_of_string("tezos-storage:content"),"content": sp.bytes_of_string("""{"name" : "Cyber Token"}""")}))
cyber_token = Cyber_Token(FA2.FA2_config(single_asset=True, assume_consecutive_token_ids = False), admin = admin.address, metadata = sp.big_map({"": sp.utils.bytes_of_string("tezos-storage:content"),"content": sp.utils.bytes_of_string("""{"name" : "Cyber Token"}""")}))
#Add cyber_token to the scenario
scenario += cyber_token
---
Expand Down Expand Up @@ -89,14 +89,14 @@ 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_script_from_url("https://smartpy.io/dev/templates/FA2.py")
FA2 = sp.io.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 -
* `sp.import_script_from_url` - If you're not using SmartPy's online IDE.
* `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.
* `sp.io.import_script_from_url` - If you're not using SmartPy's online IDE.
* `sp.io.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.

<br />

Expand All @@ -105,7 +105,7 @@ There are a lot of classes in the FA2 template along with the core `FA2` contrac
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_script_from_url("https://smartpy.io/dev/templates/FA2.py")
FA2 = sp.io.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class Your_Token(FA2.FA2):
pass

Expand All @@ -116,7 +116,7 @@ def test():
admin = sp.test_account("Elon Musk owns this account.")

your_token = Your_Token(FA2.FA2_config(single_asset = True), admin = admin.address,
metadata = sp.big_map({"": sp.bytes_of_string("tezos-storage:content"),"content": sp.bytes_of_string("""{"name" : "Your Token"}""")}))
metadata = sp.big_map({"": sp.utils.bytes_of_string("tezos-storage:content"),"content": sp.utils.bytes_of_string("""{"name" : "Your Token"}""")}))
```

That's all the code needed to implement your own fungible token!
Expand All @@ -125,7 +125,7 @@ Look at the last line of code in the snippet above -

```python
your_token = Your_Token(FA2.FA2_config(single_asset = True), admin.address,
metadata = sp.big_map({"": sp.bytes_of_string("tezos-storage:content"),"content": sp.bytes_of_string("""{"name" : "Your Token"}""")}))
metadata = sp.big_map({"": sp.utils.bytes_of_string("tezos-storage:content"),"content": sp.utils.bytes_of_string("""{"name" : "Your Token"}""")}))
```

On first look, we're initializing a smart contract like we usually do.
Expand All @@ -138,7 +138,7 @@ Let's deconstruct it!


```python
metadata = sp.big_map({"": sp.bytes_of_string("tezos-storage:content"),"content": sp.bytes_of_string("""{"name" : "Your Token"}""")}))
metadata = sp.big_map({"": sp.utils.bytes_of_string("tezos-storage:content"),"content": sp.utils.bytes_of_string("""{"name" : "Your Token"}""")}))
```

<br />
Expand All @@ -158,5 +158,5 @@ Take the first steps towards building the universe's most advanced civilization,

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`, `assume_consecutive_tokens=False`, address to the `admin`, and in the `metadata`, `name` needs to be equal to `"Cyber Token"`.
3. Initialize `Cyber_Token` with `single_asset=True`, `assume_consecutive_token_ids=False`, address to the `admin`, and in the `metadata`, `name` needs to be equal to `"Cyber Token"`.
4. Add `cyber_token` to the scenario.