Home

Awesome

StarkNet Cairo 101

Get started with Cairo with this simple tutorial. Complete the puzzles/exercises, get tokens and learn about StarkNet smart contracts!

Introduction​

Disclaimer

​Don't expect any benefit from using this other than learning some cool stuff about StarkNet, the first general-purpose validity rollup on the Ethereum Mainnnet.

​StarkNet is still in Alpha. This means that development is ongoing, and the paint is not dry everywhere. Things will get better, and in the meanwhile, we make things work with a bit of duct tape here and there!​

How it works

Complete the exercises and get tokens! This workshop is a set of smart contracts deployed on StarkNet Alpha on testnet. Each smart contract is an exercise/puzzle - which outlines a feature of the Cairo Smart contract language.

Completing the exercise will credit you with points in the form of an ERC20 token.

​ This workshop focuses on reading Cairo code and StarkNet smart contracts to understand its syntax. You do not need to code or install anything on your machine to follow and complete it.​

​ It will take you some time in order to get started (doing the first two exercises) into the tutorial. Hang on! Once there, things will flow more easily. You're learning!​

Where am I?

This workshop is the first in a series aimed at teaching how to build on StarkNet. Checkout out the following:

TopicGitHub repo
Learn how to read Cairo code (you are here)Cairo 101
Deploy and customize an ERC721 NFTStarkNet ERC721
Deploy and customize an ERC20 tokenStarkNet ERC20
Build a cross layer applicationStarkNet messaging bridge
Debug your Cairo contracts easilyStarkNet debug
Design your own account contractStarkNet account abstraction

Providing feedback & getting help

Once you are done working on this tutorial, your feedback would be greatly appreciated!

Please fill out this form to let us know what we can do to make it better.

​ And if you struggle to move forward, do let us know! This workshop is meant to be as accessible as possible; we want to know if it's not the case.

​ Do you have a question? Join our Discord server, register, and join channel #tutorials-support ​ Are you interested in following online workshops about learning how to dev on StarkNet? Subscribe here

Contributing

This project can be made better and will evolve as StarkNet matures. Your contributions are welcome! Here are things that you can do to help:

Languages

A mandarin version is available 中文版本请查看这里here. ​

Getting started

Creating a smart contract wallet

To complete the tutorial you need to collect points. These points will be owned by a smart contract wallet you need to deploy.

Solving exercices & Getting points​

Each exercise is a separate smart contract. It contains code that, when executed correctly, will distribute points to your address. ​ Points are distributed by the function distribute_points() while the function validate_exercise records that you completed the exercise (you can get points only once). Your goal is to:

Graph ​ ​

Using Voyager

For this tutorial, we'll interact with our contracts through Voyager, StarkNet's block explorer. Please make sure to connect Voyager to your account contract! This will allow you to broadcast your transactions through your wallet.

When looking for a contract/transaction, always ensure you are on the Goerli version of Voyager!

​ ​

Addresses of the exercises and contracts

TopicContract codeContract on Voyager
Points counter ERC20Points counter ERC20Link
General syntaxEx01Link
Storage variables, getters, assertsEx02Link
Reading and writing storage variablesEx03Link
MappingsEx04Link
Variable visibilityEx05Link
Functions visibilityEx06Link
Comparing valuesEx07Link
Recursions level 1Ex08Link
Recursions level 2Ex09Link
ComposabilityEx10Link
Importing functionsEx11Link
EventsEx12Link
Privacy on StarkNetEx13Link
MulticallEx14Link

Counting your points

​ Your points will get credited in your installed wallet; though this may take some time. If you want to monitor your points count in real time, you can also see your balance in voyager! ​

You can also check your overall progress here. ​

Transaction status

​ You sent a transaction, and it is shown as "undetected" in Voyager? This can mean two things: ​

Reusing this project

nile compile