Lesson: Introduction to SmartPy

Ask Question

Chapter 4

Scaffolding a basic contract in SmartPy

Intro:

In this chapter, we will start to lay down the foundation of our Cryptobot contract!

drawing

Study Time:

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:

  1. We first import the smartpy library as sp as we did in the previous chapter.
  2. We use the Python class to define the basic structure of the Bank contract.
  3. To mold this class into a smart contract, we use the concept of class inheritance to inherit from sp.Contract.

Think of this as smartpy library lending smart contract superpowers to a basic Python’s class!

Python concept refresher:

Helpful links that may help in refreshing your Python concepts:

  1. Python classes.
  2. Python class inheritance.

#buidl-ing time:

Let us create the our Cryptobot’s basic contract structure by doing the following:

  1. Declare a class named Cryptobot.
  2. Extend the Cryptobot class by inheriting sp.Contract from the smartpy library.

When you’re finished:

  1. Click on “Check” to check your submission with the correct answer.
  2. Click on “Show Answer” in case you get stuck.

Contract.py

Loading...