SmartPy Focus: Importing SmartPy and Python code

Importing SmartPy and Python code

Import pure Python code

Import a template

FA2 = sp.import_template("FA2.py")
class my_token(FA2.FA2):
...

Import some SmartPy script from a URL, a file, etc.

Import some SmartPy script from the browser local storage

Import some SmartPy script directly from a string

Using imported code in practice

Adding tests

ttt = sp.import_template("tictactoe.py")
import smartpy as spttt = sp.import_template("tictactoe.py")@sp.add_test(name = "Other TicTacToe")
def test():
scenario = sp.test_scenario()
c1 = ttt.TicTacToe()
scenario += c1
scenario += c1.play(i = 0, j = 0, move = 1)

Inheriting classes to add new features

FA2 = sp.import_template("FA2.py")
class Link_token(FA2.FA2):
@sp.entry_point
def proxy(self, oracle, params):
...

Mixins

class FA2(
FA2_token_metadata,
FA2_mint,
FA2_administrator,
FA2_pause,
FA2_core):
def __init__(self, config, admin):
FA2_core.__init__(self, config,
paused = False,
administrator = admin)
class FA2_no_mint(
FA2_token_metadata,
# FA2_mint,
FA2_administrator,
FA2_pause,
FA2_core):
def __init__(self, config, admin):
FA2_core.__init__(self, config,
paused = False,
administrator = admin)
FA2 = sp.import_template("FA2.py")
class FA2_no_mint(
FA2.FA2_token_metadata,
# FA2_mint,
FA2.FA2_administrator,
FA2.FA2_pause,
FA2.FA2_core):
def __init__(self, config, admin):
FA2.FA2_core.__init__(self, config,
paused = False,
administrator = admin)

Ad-hoc edition of contracts

FA2 = sp.import_template("FA2.py")
class FA2_no_mint(FA2.FA2):
def __init__(self, config, admin):
FA2.FA2.__init__(self, config, admin)
self.mint = None

Getting involved

--

--

--

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lucky Block Omega Mod for Minecraft (1.12.2–1.7.10) —

How to install OpenFOAM into M1 MAC

How to Get There?

Custom Collection View Layout: it’s not that hard to create.

Advanced Features of Google Docs — p2

Cross-Organizational Teams Can Benefit Your Software Development Process

What’s a slug

Save and retrieve data using Multi Index Tables

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SmartPy.io

SmartPy.io

An intuitive and effective smart contracts language and development platform for Tezos. In Python.

More from Medium

Retired Programmer Tries AI Programming in Python. 01) Prologue

ANN training using two time series as input

Vending Machine Controller using VHDL

Build Your Own Reinforcement Learning Algorithm