• This repository has been archived on 08/Aug/2024
  • Stars
    star
    471
  • Rank 93,216 (Top 2 %)
  • Language Cairo
  • Created over 2 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Learn how to read Cairo code

DISCLAIMER

Hello Starknet community, This repository is not updated with the latest Cairo syntax and hence, we do not recommend to attempt this tutorial as of today. If you are interested in contributing to the repository to update the tutorial, please comment on the below issue to pick up a task. You can find more details about the issue and exercises breakdown here: #61

You can also ping me(@gyanlakshmi) or Omar(@omarespejel) on Telegram to tag you on the right tasks.

Starknet Cairo 101 Automated Workshop

banner

  • A Simplified Chinese version is available here.
  • A Spanish version is available here.
  • (not updated) A Portuguese version is available here.
  • (not updated) A Korean version is available here.

Welcome!

This tutorial is made for developers who are interested in learning how to read Cairo 1 code and Starknet smart contracts. By following it, you'll be able to get started in no time. Have fun!

Introduction​

Welcome to Starknet, a general-purpose Validity Rollup on top of Ethereum mainnet. Starknet is a layer 2 scaling solution that lets developers build decentralised applications without compromising on security, scalability and decentralization.

This workshop is designed to help you read Cairo 1 code and Starknet smart contracts, and understand their syntax. Don't worry, you don't need to code or install anything on your machine to follow and complete it. You can do it all from your browser.

The exercises are a set of smart contracts deployed on Starknet Alpha on testnet. Each smart contract is an exercise/puzzle that outlines a feature of the Cairo Smart contract language.

Completing the exercises will earn you points in the form of an ERC20 token. The token does not have any monetary value, but it's a fun way to track your learning progresses.

We hope you have fun participating in this workshop!

What you will learn

  • How to read Cairo 1 code
  • How to read Starknet smart contracts
  • How to interact with Starknet smart contracts using a browser wallet and a block explorer.

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 mainnet.

Steps

Steps

1. Creating a smart contract wallet and connecting it to a Block Explorer

To complete the tutorial, you need to collect points. You will own these points through your Starknet wallet.

  • The easiest way to set one up is to use Argent X (download the chrome extension or check their repo) or Braavos (download the chrome extension). These wallet solutions are for Starknet what Metamask is for Ethereum. They allow users to initiate transactions and interact with applications on Starknet.
  • Follow the instructions in your wallet app to install the extension. It may take approximately 5 minutes for the account to be deployed. Note that in Starknet, there is only one type of account: smart contract accounts. To create a new wallet, you need to send a transaction that publishes your smart contract wallet to the network.
  • Make sure you are on the Goerli testnet network.
  • The tutorial’s points are held in contract 0x044f65adbdb59bf1db71e8b69efb7c9d0b810db94c1730a05fa5751b02d396de (Starkscan link, Voyager link). Click "Add Token" in your installed wallet and add the tutorial contract address so that your points balance appears there. A new token called SC101 (starknet-cairo-101) will appear in your wallet.
  • To execute transactions on the Goerli Starknet testnet, you will need testnet ETH to pay for gas. You have two options:
    • Go to the faucet and follow the instructions. It may take a few minutes
    • Go to Starkgate and bridge Goerli Eth from Ethereum to Starknet

2. Use a Block Explorer to interact with the contracts

To finish this workshop, you have to interact with the exercises/smart contracts through a block explorer.

You can use either Starkscan or Voyager. These are for Starknet what Etherscan is for Ethereum. They allow you to browse the state of the blockchain and view all transactions and their status.

By connecting your wallet to the block explorer, you will be able to send your transactions to the network and interact with the exercises in the tutorial.

When looking for a contract/transaction, always ensure you are on the Goerli version of the Block Explorer. To solve the exercises, access the contract’s functions by using the read/write tab in the explorer.​

3. Solving exercises and getting points​

​ Each exercise is a separate smart contract. It contains code that, when executed correctly, will distribute points to your address.

To solve an exercise, follow the link below to read its code. Read the comments, and follow the instructions to understand the code. Your goal is to get each exercise to call successfully the function distribute_points(), which will send you ERC20 points.

During validation, exercises often also call validate_exercise(), which records that you completed an exercise and prohibit you from collecting points various times.

Each exercise is deployed on the Goerli testnet, and you will need to interact with them through a Block Explorer. You can find the addresses of the contracts in the table below.

Topic Contract code Contract on Starkscan Contract on Voyager
General syntax Ex01 Link Link
Storage variables, getters, asserts Ex02 Link Link
Reading and writing storage variables Ex03 Link Link
Mappings Ex04 Link Link
Variable visibility Ex05 Link Link
Functions visibility Ex06 Link Link
Comparing values Ex07 Link Link
Recursions level 1 Ex08 Link Link
Recursions level 2 Ex09 Link Link
Composability Ex10 Link Link
Importing functions Ex11 Link Link
Events Ex12 Link Link
Privacy on Starknet Ex13 Link Link
Multicall Ex14 Link Link

4. Counting your points and checking your progress

Your points will be credited to your wallet, though this may take some time. If you want to monitor your points count in real-time, you can also check your balance in a block explorer!

  • Go to the ERC20 counter on Voyager or Starkscan in the "read contract" tab.
  • Enter your address in the balanceOf function.​

Enjoy the workshop! If you have any questions, feel free to contact us on Discord. We are happy to help!


Contributing to improve this workshop

This project can be made better and will evolve. Your contributions are welcome! Go to the CONTRIBUTING file for more information on how to setup your environment and contribute to the project.

Here are some things that you can do to help:

  • Create a branch with a translation to your language
  • Correct bugs if you find some
  • Add an explanation in the comments of the exercise if you feel it needs more explanation
  • Add exercises showcasing your favorite Cairo feature
  • Add a new tutorial to the series

Other Automated Workshops

This workshop is the first in a series aimed at teaching how to build on Starknet. Checkout out other workshops in the series:

Topic GitHub repo
Learn how to read Cairo code (you are here) Cairo 101
Deploy and customize an ERC721 NFT Starknet ERC721
Deploy and customize an ERC20 token Starknet ERC20
Build a cross-layer application Starknet messaging bridge
Debug your Cairo contracts easily Starknet debug
Design your own account contract Starknet account abstraction

Providing feedback & getting help

Once you are done working on this tutorial, your feedback will 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 see 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 attending online workshops about dev on Starknet? Subscribe here

More Repositories

1

starknetbook

Mastering Starknet. By the Starknet community
CSS
824
star
2

starknet-messaging-bridge

Learn how to build StarkNet <-> Ethereum cross layer applications
Cairo
132
star
3

starknet-accounts

Learn how to build and deploy StarkNet Accounts
Cairo
66
star
4

starknet-erc721

Learn how to deploy and customize an ERC721 token on StarkNet
Cairo
56
star
5

starknet-erc20

Learn how to deploy and customize an ERC20 token on StarkNet
Cairo
43
star
6

starknet-debug

Learn how to debug a StarkNet smart contract
Cairo
43
star
7

counter-workshop

Code for Counter Workshop using latest Starknet syntax.
Shell
40
star
8

deploy-cairo1-demo

Cairo
25
star
9

walking-with-starknet

Cairo and StarkNet educational guides in several languages
Cairo
25
star
10

aa-workshop

Code for Account Abstraction workshop using latest Starknet syntax
Cairo
22
star
11

remix-game-day

A short exercice to deploy a StarkNet contract using remix
Cairo
9
star
12

StarkNet-integration

TypeScript snippets for exchanges integration
TypeScript
8
star
13

ownable-workshop

Code for Ownable workshop using latest Starknet syntax.
Cairo
6
star
14

starknet-cc-ctf-challenges

Cairo
5
star
15

buymeacoffee-contracts

Cairo
4
star
16

kakashi

Knowledgeable Assistant Keen on Answering Starknet Heterogeneous Inquiries (KAKASHI)
Python
4
star
17

ultimate-env

Set up your StarkNet dev environment in no time
Cairo
3
star
18

remote-controlled-accounts

Cairo
3
star
19

starknet-seed

A development environment for cairo-lang
Shell
2
star
20

starknet-stack

The goal of this repository is to use a layered tech stack to create a conceptual model for StarkNet.
Go
2
star
21

buymeacoffee-ui

TypeScript
2
star
22

ownable

An example Cairo 1 smart contract to showcase how to run integration tests with Protostar
Cairo
2
star
23

cairo-snippets

Bunch of cairo vs code snippets to make smart-contract development easier
2
star
24

ownable_v2

An example of how to create a Starknet smart contract using the version 2 of the Cairo compiler
Cairo
2
star
25

points-migrator

This smart-contract enables StarkNet users who completed the tutorials to migrate the points to another wallet
Cairo
2
star
26

setup-starknet-dev-env

Python
1
star
27

starknet-edu.github.io

Cairo
1
star
28

hardhat-example

This repository can be used as a base for hardhat projects on Starknet
TypeScript
1
star
29

starknet-scripts

1
star
30

starknet-ecosystem-guide

1
star
31

snf-edu

1
star