Compiling contracts
To compile a SmartPy contract, make sure that SmartPy is installed as described in Installation. Then, run the command python path/to/contract.py
, where path/to/contract.py
is the path to your contract.
When you compile the contract, SmartPy automatically runs the tests in the contract and generates output files. If the contract compiles successfully and the tests pass, no messages appear in the terminal output.
Output files
When you compile a SmartPy contract locally with the python
command, SmartPy writes output files to the folder that you specify when you create the test scenario. For example, if you create the test scenario with the code scenario = sp.test_scenario("My test", main)
, SmartPy writes output files to the My_test
folder, relative to the location of the test scenario file.
SmartPy compiles each contract, each contract's initial storage, and the parameters for each smart contract call to multiple output files. The compiled file names start with step_[nnn]
, where [nnn]
is the number of the step in the test scenario that instantiated the contract. The log.txt
file lists when each file is created so you can match files to commands in your test scenario.
Output log: The
log.txt
file includes messages from the compiler, the names of other compiled files as they are created, and messages that you add as described in Logging.Compiled contract files: SmartPy compiles each contract that you instantiate and add to the test scenario to a Michelson in files that end in
_contract.tz
and Micheline JSON in files that end in_contract.json
.SmartPy gives each contract in the test scenario an ID number in the order that they are instantiated in the code, starting with 0. The first contract is compiled to a file that ends in
_cont_0_contract.tz
. Other output files that are associated with this contract have the same ID number, such asstep_001_cont_0_storage.tz
for its initial storage value andstep_007_cont_0_params.tz
for the parameters sent to that contract in a call.Compiled initial storage files: SmartPy compiles the initial storage value of each contract to Python, Micheline JSON, and Michelson files that end in
_storage.py
,_storage.json
, and_storage.tz
. You can use the contents of these files to set the initial storage of the contract when you deploy it.Parameter files: SmartPy compiles the parameters from each smart contract call in the test scenario to Python, Micheline JSON, and Michelson files that end in
_params.py
,_params.json
, and_params.tz
. You can use the contents of these files as examples of how to format parameters for smart contract calls after you deploy the contract.Module imports (Internal use): If you set the
SMARTPY_DEPENDENCIES_FILE
environment variable to a file name, the compiler outputs the tree of module imports that occur during simulation. It writes the information inMakefile
format, as in this example:bash$ SMARTPY_DEPENDENCIES_FILE=imports.mk python templates/calculator_new.py
In this case, the compiler creates a file named
imports.mk
with the following contents:maketemplates/example_import.spy: wheels/tezos-smartpy/smartpy/math.spy templates/calculator_main.spy: wheels/tezos-smartpy/smartpy/math.spy templates/example_import.spy wheels/tezos-smartpy/smartpy/utils.spy templates/calculator_new.py: templates/calculator_main.spy