Home

Awesome

StarkNet Cairo 101

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

Introduction

Disclaimer

Don't expect any kind of benefit from using this, other than learning a bunch of cool stuff about StarNet, the first general purpose validity rollup on the Ethereum Mainnnet.

StarkNet is still in Alpha. This means that develpment 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

This workshop is a set of smart contracts deployed on StarkNet Alpha on testnet. Each smart contract is an exercice/puzzle; each one outlines a feature of the Cairo Smart contract language. Completing the exercice will credit you with points, in the form of an ERC20 token.

This workshop focuses on reading Cairo code and StarkNet smart contracts, in order to understand its syntax. You don't need to code or install anything on your machine in order to follow and complete it. Getting started (doing the first two exercises) will take you some time, in order to get into the tutorial. Hang on! Once there, things will flow more easily. You're learning!

This workshop is the first in a serie that will cover broad smart contract concepts (writing and deploying ERC20/ERC721, bridging assets, L1 <-> L2 messaging...). Interested in helping writing those? Reach out!

Providing feedback

Once you are done working on this tutorial, your feedback would be greatly appreciated! Please fill 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.

Getting started

What will change soon

Creating an account contract

In order to complete the tutorial you need to collect points. These points will be owned by a smart contract wallet, that you need to deploy.

Using voyager

For this tutorial we'll interact with our contracts through Voyager, StarkNet's block explorer. When looking for a contract / transaction, always make sure you are on the Goerli version of Voyager!

Using decimals instead of hexadecimal

Voyager currently has issues dealing with hexadecimal values when writing values to contracts.

For example, reading your points balance through voyager currently does not work if you input your Argent X address as hexadecimal.

To overcome this limitation, always convert your hexadecimal value to decimal. I use this website.

Getting points

Each exercice is a separate smart contract. It contains code that, when executed properly, will distribute points to your address. Since there is no way currently to send a transaction easily through your account contract, you'll have to specify your address for each call.

Points are distributed by the function distribute_points() while the function validate_exercice records that you completed the exercice (you can get points only once). Your goal is to:

Checking your progress

Counting your points

Your points will get credited in Argent X; though this make take so time. If you want to monitor your points count in real time, you can also see your balance in voyager!

Transaction status

You sent a transaction, and it is shown as "undected" in voyager? This can mean two things:

You can (and should) check the status of your transaction with the following URL https://alpha4.starknet.io/feeder_gateway/get_transaction_receipt?transactionHash= , where you can append your transaction hash.

Contract addresses

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

Contributing

Help is welcome!

This project can be made better, and will evolve in the coming weeks. Your contributions are welcome! Here are things that you can do to help:

Reusing this project

This project uses Nile.

git clone https://github.com/l-henri/starknet-cairo-101
cd starknet-cairo-101
python3 -m venv env
source env/bin/activate
pip install cairo-nile
nile compile