Introducing SmartPyBasic, a simple CLI to build Tezos smart contract in Python

Installation

sh <(curl -s https://SmartPy.io/SmartPyBasic/SmartPy.sh) local-install ~
~/SmartPyBasic/scripts         # A list of demo scripts (here, only demo.py)
smartpy.py # The SmartPy library
smartpyio.py # A helper module used by SmartPy, mostly in browser
smartmljs.bc.js # The SmartML library
browser.py # A mock module to simulate a browser
smartmlbasic.js # A node JavaScript file to interact with SmartML
smartpybasic.py # A helper library
SmartPy.sh # A helper shell-script

A demo script

## Copyright 2019 Smart Chain Arena LLC. ### To run this script, we need to setup a PYTHONPATH to the
# SmartPyBasic directory.
# If the SmartPyBasic directory is ~/SmartPyBasic, then
# PYTHONPATH=~/SmartPyBasic python3 demo.py
# or
# ~/SmartPyBasic/SmartPy.sh run demo.py
# should work.
import smartpy as spclass MyContract(sp.Contract):
def __init__(self, myParameter1, myParameter2):
self.init(myParameter1 = myParameter1,
myParameter2 = myParameter2)
@sp.entryPoint
def myEntryPoint(self, params):
sp.verify(self.data.myParameter1 <= 123)
self.data.myParameter1 += params
# We evaluate a contract with parameters.
contract = MyContract(12, 13)
# We need to export the compile the contract.
# It can be done with the following.
import smartpybasic as spb
spb.compileContract(contract,
targetBaseFilename = /tmp/myContractDemo")
print("Contract compiled in /tmp/myContractDemoCode.tz")

Direct use with Python

PYTHONPATH=~/SmartPyBasic python3 ~/SmartPyBasic/scripts/demo.py
ls -ltr /tmp/myContractDemo*
~/SmartPyBasic/SmartPy.sh run ~/SmartPyBasic/scripts/demo.py
ls -ltr /tmp/myContractDemo*
-rw-r--r--   ... myContractDemoExpression.smlse
-rw-r--r-- ... myContractDemoStorage.tz
-rw-r--r-- ... myContractDemoCode.tz

The run command

with sp.ifBlock(condition):
...
with sp.elseBlock():
...
with sp.forBlock('x', l) as x:
...
with sp.whileBlock(condition):
...
~/SmartPyBasic/SmartPy.sh run <mycontract.py>

The local-compile command

~/SmartPyBasic/SmartPy.sh local-compile https://SmartPy.io/demo/templates/tictactoe.py "TicTacToe()" /tmp/tictactoe

Going further

--

--

--

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

Cloud-Native Speed and Performance Matters

Git and GitHub Reference

3 Surefire Ways Offline Apps Will Not Drive Your Business Into The Ground During Crisis.

Someone reading a book by the window, visual artwork including translucent images design

Kylin Network is Supported by Web3 Foundation Grants Program

Modern File Transfer Solution on Azure — SFTP

INT 4.0 3-Day Countdown to Launch — China Node Fengli.com

The Ultimate Guide To Power Metrics For Mac OS X

AUTOSAR for Dummies — part 1

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

A-Z List Smart Contract Auditing Companies

Available types of variables in solidity

[DApps] Part III : Call Smart contract function by Web3.js

Problem: Running into the following error message when attempting to run the command truffle…