Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Run and deploy it at
import smartpy as sp
class User(sp.Contract):
# Constructor
def __init__(self):
self.init(userMap = # Initializes a map data structure to store user data with email as key
# Entry point to add new user data
def addUser(self, params): # Takes in email, name, gender in params[] = sp.record( # Here email is the key and the data is stored in a record (similar to a struct in C/C++)
name =,
gender = params.gender,
score = 0,
) # For each user we store the email (as key), name, gender and score
# Entry point to update the score of a user
def updateScore(self, params): # Takes in email and score in params[].score += params.score # Adds the incomming score to the existing score of a user
# Tests for the smart contract
if "templates" not in __name__:
@sp.add_test(name = "User")
def test():
c1 = User() # Created an object of User class
scenario = sp.test_scenario()
scenario.h1("User Data") # Displays h1 heading (as in HTML)
scenario += c1 # Displays current state of c1
scenario += c1.addUser( # Displays the state of c1 after calling the addUser entry point
email = '',
name = 'Bob',
gender = 'male'
scenario += c1.updateScore( # Displays the state of c1 after updating the score to 10
email = '',
score = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment