SmartPy is an intuitive and powerful smart contract development platform for Tezos. The SmartPy language is based on Python. So, having prior experience with Python would come in handy.
The SmartPy code is compiled down to Michelson - a domain-specific low-level programming language for smart contract development on Tezos.
In this section, you will learn to write a smart contract for Tezos Developer Hub using SmartPy. The contract will store the details of all registered developers (name, bio, and wallet address), and there will be an entry point to register new developers.
For writing the smart contract, go to SmartPy IDE and follow the steps below:
Let's get started with importing the SmartPy library.
import smartpy as sp
In SmartPy, a contract is defined by a class that inherits from
class TezosDevHub(sp.Contract): def __init__(self): pass
The first step in creating a contract is defining its storage. The storage contains all the data that defines the state of the contract. You have to define it using
self.init() function inside the constructor.
In this contract, you have to create a
devs map for storing the data of all the devs. The map will hold key-value pairs. The key will be a unique natural number and the value will be a record (similar to a struct in C/C++) of name, bio, and wallet address.
A map can be accessed similar to a Python dictionary.
Another variable that you have to define here is
all_devs which will store the total number of registered devs.