This chapter aims to prepare you and your working environment to be ready to code, test, and compile your smart contracts.
You can code locally on your favourite IDE or use the official SmartPy online editor, with added interesting features to facilitate development.
The SmartPy online editor is not just a simple text editor for smart contracts. It comes with a built-in simulation suite, that provides powerful testing tools for developers.
FIGURE 1: Smartpy.io Online Editor
To familiarize yourself with SmartPy, you can choose among numerous existing examples of smart contracts, by going to the Templates tab.
FIGURE 2: Smartpy.io Online Editor Templates
On the left screen of the online editor, you can:
- Write your code
- Run and test your code
FIGURE 3: Smartpy.io Online Editor Code Area
Once you run your code, you can visualize the result on the right screen, which contains:
- Your inlined python code
- Your generated Michelson contract and storage (also available in JSON format)
- A summary of your test scenario and the generated Michelson parameter code
- An interface to deploy your Michelson contract on a testnet or the mainnet
FIGURE 4: Smartpy.io Online Editor Result Test Area
FIGURE 5: Smartpy.io Online Editor Result Michelson Contract Code
In the following chapters, we will use the online editor. But in this section, we will still provide the basics for using SmartPy on a local IDE.
A virtual environment is a self-contained Python installation, separated from the global Python installation. It contains its own modules. Hence, it is most useful when a specific module version is needed without affecting the other modules. Run this command to create a virtual environment:
By default, your OS uses the python interpreter from
/usr/bin/python. Once a virtual environment is created, it has to be activated in order to be used by the OS. You can activate your virtual environment by running:
The name of the environment should appear at the beginning of the command line. It can be deactivated by running:
After having activated your virtual environment, you can install SmartPy by running:
Verify the installation by running:
If the command returns nothing, then the installation has been successful.
To install the SmartPy CLI, run:
SmartPy.sh script to compile a SmartPy smart contract:
Compilation produces multiple possible outputs including:
- Michelson code for contract and storage
- JSON code for contract and storage
It is referring to Michelson source code in JSON representation.
SmartPy.sh script to run the tests:
This leads to multiple outputs: types of storage values and entrypoint parameters, generated Michelson code, pretty-printed scenario, etc.
Installing an environment for programming with SmartPy is easy to do. You need Python and the necessary libraries. Or you can simply start coding from the online editor.