starknet-edu / starknet-cairo-101

Learn how to read Cairo code
470 stars 245 forks source link
cairo cairo-lang smart-contracts starknet

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: https://github.com/starknet-edu/starknet-cairo-101/issues/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

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

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.

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!

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:

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