Skip to content
On this page

Project management โ€‹

Installation โ€‹

Dependencies

RequirementVersion
Python>= 3.7
NodeJS>= 10.x

Download the CLI.

shell
sh <(curl -s https://legacy.smartpy.io/cli/install.sh)

Directory structure โ€‹

shell
smartpy-cli
โ”‚
โ”œโ”€โ”€ templates
|   |
โ”‚   โ””โ”€โ”€ welcome.py              # A very simple template
โ”‚
โ”œโ”€โ”€ ...
โ””โ”€โ”€ SmartPy.sh                  # Command line interface

Write a contract โ€‹

shell
# Create a folder to store the contracts
mkdir ~/smartpy-cli/contracts
# Create a folder to store contract compilation artifacts
mkdir ~/smartpy-cli/compilation
# Create a folder to store contract test artifacts
mkdir ~/smartpy-cli/test

# Create a contract file
touch ~/smartpy-cli/contracts/my_contract.py

Edit my_contract.py and add your own logic or use the example below:

python
import smartpy as sp

class MyContract(sp.Contract):
  def __init__(self, value):
      self.init(storedValue = value)

  @sp.entrypoint
  def store(self, value):
    # Store a new value
    self.data.storedValue = value

@sp.add_test(name = "MyContract")
def test():
  scenario = sp.test_scenario()
  contract = MyContract(1)
  scenario += contract
  contract.store(2)

# A a compilation target (produces compiled code)
sp.add_compilation_target("my_contract_compiled", MyContract(1))

Running compilations โ€‹

The command below will run the compilation targets in the file my_contract.py and store the generated compilation artifacts at ~/smartpy-cli/compilation.

shell
~/smartpy-cli/SmartPy.sh compile ~/smartpy-cli/contracts/my_contract.py ~/smartpy-cli/compilation

Running tests โ€‹

The command below will run the test targets in the file my_contract.py and store the generated test artifacts at ~/smartpy-cli/test.

shell
~/smartpy-cli/SmartPy.sh test ~/smartpy-cli/contracts/my_contract.py ~/smartpy-cli/compilation

Deploy contracts โ€‹

By default, the originator will use a faucet account.
But you can provide your own private key by providing the argument --private-key

shell
~/smartpy-cli/SmartPy.sh originate-contract --code ~/smartpy-cli/compilation/my_contract/<...>_contract.tz --storage ~/smartpy-cli/compilation/my_contract/<...>_storage.tz --rpc https://granadanet.smartpy.io --private-key <edsk...>