SmartPy Concepts

To build smart contracts in SmartPy, developpers write Python classes using regular Python and a some building blocks provided by the SmartPy library.
This building blocks appear in terms of values (representing constants such as integers, booleans, strings, tokens, keys, records of values, lists of values, etc.), expressions (that evaluate to values) and commands that act on expressions, storage and parameters.

The pervasive use of the smartpy module calls for an abbreviation and the usual convention is to use import smartpy as sp at the beginning of contract scripts.


Contracts are defined by Python classes that inherit a class sp.Contract.
These classes:

Entry points are methods def myEntryPoint(self, params): ... decorated with a decorator @sp.entryPoint.
They implement the logic on the contract: verifications that some conditions are met, token transfers, computations, storage updates, etc.


SmartPy, thanks to SmartML, uses a custom type inference algorithm to associate types to each expression, value, storage and entry points.
To keep the programming experience enjoyable, these types usually remain implicit but one can add new type constraints if necessary.



Expressions are everywhere in SmartPy.
A few typical constructions:


Values are evaluated expressions. At any point in time, and for any entry point, storage and parameters are values.
Typical values are:


Access to internal modules

For advanced users, please see Internals.