Scaffolding a basic contract in SmartPy
In this chapter, we will start to lay down the foundation of our
What is a SmartPy contract?
A SmartPy contract is the fundamental component of any smart contract application that you build using SmartPy.
All variables and functions belong to a contract, and this will be the starting point of all your projects/DApps.
Show me an example:
A basic contract definition for the contract
Bank would look like this:
import smartpy as sp class Bank(sp.Contract): pass
Explaining the code above:
- We first import the
spas we did in the previous chapter.
- We use the Python
classto define the basic structure of the
- To mold this
classinto a smart contract, we use the concept of class inheritance to inherit from
Think of this as
smartpy library lending smart contract superpowers to a basic Python’s
Python concept refresher:
Helpful links that may help in refreshing your Python concepts:
Let us create the our
Cryptobot’s basic contract structure by doing the following:
- Declare a
- Extend the
Cryptobotclass by inheriting
When you’re finished:
- Click on “Check” to check your submission with the correct answer.
- Click on “Show Answer” in case you get stuck.