Home

Awesome

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 create a PR and tag me @gyan0890 on it and we will be happy to support you with the process.

A great resource to get you up to speed with the new Cairo syntax in a Starknet context is Chapter 2 of the Starknet Book.

You can also ping me(@gyanlakshmi) on Telegram to help you assign the right tasks.

ERC20 on Starknet

Welcome! This is an automated workshop that will explain how to deploy an ERC20 token on Starknet and customize it to perform specific functions. The ERC20 standard is described here It is aimed at developers that:

This tutorial was written by Florian Charlier (@trevis_dev) in collaboration with Henri Lieutaud and Lucas Levy, based on Henri's original ERC20 101 and ERC20 102 tutorials for Solidity.

​ ​

Introduction

Disclaimer

Don't expect any kind of benefit from using this, other than learning a bunch of 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

The goal of this tutorial is for you to customize and deploy an ERC20 contract on Starknet. Your progress will be check by an evaluator contract, deployed on Starknet, which will grant you points in the form of ERC20 tokens.

Each exercise will require you to add functionality to your ERC20 token.

For each exercise, you will have to write a new version on your contract, deploy it, and submit it to the evaluator for correction.

Where am I?

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

TopicGitHub repo
Learn how to read Cairo codeCairo 101
Deploy and customize an ERC721 NFTStarknet ERC721
Deploy and customize an ERC20 token (you are here)Starknet 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:

Getting ready to work

Step 1 - Clone the repo

git clone https://github.com/starknet-edu/starknet-erc20
cd starknet-erc20

Step 2 - Set up your environment

There are two ways to set up your environment on Starknet: a local installation, or using a docker container

For a production setup instructions we wrote this article.

Option A - Set up a local python environment

pip install openzeppelin-cairo-contracts

Option B - Use a dockerized environment

for mac m1:

alias cairo='docker run --rm -v "$PWD":"$PWD" -w "$PWD" shardlabs/cairo-cli:latest-arm'

for amd processors

alias cairo='docker run --rm -v "$PWD":"$PWD" -w "$PWD" shardlabs/cairo-cli:latest'
docker run --rm -it -v ${pwd}:/work --workdir /work shardlabs/cairo-cli:latest

Step 3 -Test that you are able to compile the project

starknet-compile contracts/Evaluator.cairo

Step 4 - Define your environment variables to set up your account

export STARKNET_NETWORK=alpha-goerli
export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount

Step 5 - Create and deploy your account

Before deploying your account, send a few Goerli ETH to it.

starknet new_account
starknet deploy_account

Working on the tutorial

Workflow

To do this tutorial you will have to interact with the Evaluator.cairo contract. To validate an exercise you will have to

For example to solve the first exercise the workflow would be the following:

deploy a smart contract that answers ex1call submit_exercise on the evaluator providing your smart contract addresscall ex2_test_erc20 on the evaluator contract

Notes: To deploy a smart contract, follow these instructions:

starknet-compile my_contrats/erc20.cairo --output artifacts/erc20.json
starknet declare --contract artifacts/erc20.json

Use the contract class from the output of the previous command

starknet deploy --class_hash <compile_contract_class_hash> --network alpha-goerli

Your objective is to gather as many ERC20-101 points as possible. Please note :

Contracts code and addresses

Contract codeContract on voyager
Points counter ERC200x228c0e6db14052a66901df14a9e8493c0711fa571860d9c62b6952997aae58b
Evaluator0x14ece8a1dcdcc5a56f01a987046f2bd8ddfb56bc358da050864ae6da5f71394
Dummy ERC20 token (DTK20)0x66aa72ce2916bbfc654fd18f9c9aaed29a4a678274639a010468a948a5e2a96

​ ​

Tasks list

Today you will deploy your own ERC20 token on Starknet!

The tutorial is structured in two parts

Exercise 1 - Deploy an ERC20

starknet-compile contracts/token/ERC20/ERC20.cairo --output artifacts/ERC20.json
starknet deploy --contract ERC20 --inputs arg1 arg2 arg3 --network alpha-goerli 

Exercise 2 - Verifying your ERC20

Exercise 3 - Creating a faucet

Exercises 4, 5 and 6 - Creating an allow list

Exercises 7, 8 and 9 - Creating a multi tier allow list

Exercise 10 - Claiming dummy tokens

Exercise 11 - Calling the faucet from your contract

Exercise 12 - Using transferFrom on an ERC20

Exercise 13 - Approve

Exercise 14 - Revoking approval

Exercise 15 - Using transferFrom

Exercise 16 and 17 - Tracking deposits with a wrapping ERC20

Exercise 18 - Withdrawing tokens and burning wrapped tokens

​ ​

Annex - Useful tools

Converting data to and from decimal

To convert data to felt use the utils.py script To open Python in interactive mode after running script

python -i utils.py
>>> str_to_felt('ERC20-101')
1278752977803006783537

Checking your progress & counting your points

​ Your points will get credited in your 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: ​