Skip to main content


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 favorite IDE or use the official SmartPy online editor, with added interesting features to facilitate development.

Write, test, and compile from the Online Editor

The SmartPy online editor is not just a simple text editor for smart contracts. It comes with a built-in simulation suite, which provides powerful testing tools for developers.

SmartPy online IDE homepage

FIGURE 1: Online Editor

To familiarize yourself with SmartPy, you can choose among numerous existing examples of smart contracts, by going to the Templates tab.

SmartPy online IDE smart contract templates selection

FIGURE 2: Online Editor Templates

On the left screen of the online editor, you can:

  • Write your code
  • Run and test your code

SmartPy online IDE, left part: write SmartPy code

FIGURE 3: 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

SmartPy online IDE, right part: launch the tests, deploy the contract

FIGURE 4: Online Editor Result Test Area

SmartPy online IDE, view of the compiled code

FIGURE 5: Online Editor Result Michelson Contract Code

Write, test and, compile from your local IDE

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.


Create a virtual environment

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:

python3 -m venv /path/to/env

Activate the 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:

source /path/to/env/bin/activate

The name of the environment should appear at the beginning of the command line. It can be deactivated by running:

(venv) $ deactivate

Install the command line interface

To install the SmartPy CLI, run:

sh <(curl -s

Compile SmartPy Contracts or Expressions

Use the script to compile a SmartPy smart contract:

~/smartpy-cli/ compile <> <output-directory>

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.

Execute the tests of your SmartPy Script

Use the script to run the tests:

~/smartpy-cli/ test <> <output-directory>

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 just need Python and the necessary libraries. Or you can simply start coding in the online editor.