Home

Awesome

ERC20 on StarkNet

Introduction

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 workshop is the third in a series that will cover broad smart contract concepts (writing and deploying ERC20/ERC721, bridging assets, L1 <-> L2 messaging...).
You can find the previous tutorials here:

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.

Interested in helping writing those? Reach out!

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

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!

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.

Do you have a question? Join our Discord server, register and join channel #tutorials-support

Table of contents

How to work on this tutorial

Before you start

The tutorial has three components:

It is structured in two parts:

Workflow

To do this tutorial you will have to interact with the Evaluator.cairo contract.
The most convenient way to do this is through Voyager. Please do not forget to connect to your wallet when interacting with the evaluator (see below). To do an exercise you will have to use the evaluator's contract submit_[erc20|exercise]_solution functions to provide the address of the contract to verify for your exercise solution. Once it's done you can call the appropriate function on the evaluator to verify the desired exercise(s). For example, to solve the first exercise the workflow would be the following:

  1. Deploy a smart contract that answers ex2
  2. Call submit_erc20_solution on the evaluator providing your smart contract address
  3. Call ex2_test_erc20 on the evaluator contract

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

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:

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.

Install cairo-lang

With pip
pip install openzeppelin-cairo-contracts
With docker

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

Getting to work

starknet-compile contracts/Evaluator.cairo

Open Python in interactive mode after running script

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

Contract addresses

Contract codeContract on voyager
Points counter ERC200x037b0ca3995eb2d79626b6a0eac40fe4ba19ddf73d81423626b44755614b9cee
Evaluator0x05bf05eece944b360ff0098eb9288e49bd0007e5a9ed80aefcb740e680e67ea4
Dummy ERC20 token (DTK20)0x029260ce936efafa6d0042bc59757a653e3f992b97960c1c4f8ccd63b7a90136

Points list

Today you will deploy your own ERC20 token on StarkNet!

Setting up

Part 1

đź“ť Submissions for this part are given to the Evaluator by calling submit_erc20_solution() đź“ť <br/>(NOT submit_exercise_solution())

ERC20 basics

Exercise 1

Exercise 2

The total amount of points to collect from completing all exercises up to this point is : 8 points

Distributing tokens

Exercise 3

The total amount of points to collect from completing all exercises up to this point is : 10 points

Creating an ICO allow list

Exercises 4, 5 and 6

The total amount of points to collect from completing all exercises up to this point is : 14 points

Creating multi tier allow list

Exercises 7, 8 and 9

The total amount of points to collect from completing all exercises up to this point is : 19 points

Part 2

Submissions

âť—Submissions for this part are given to the Evaluator by calling submit_exercise_solution()âť—<br/>(instead of submit_erc20_solution())

Manipulating ERC20 tokens from other contracts

Exercise 10

The total amount of points to collect from completing all exercises up to this point is : 21 points

Calling another contract from your contract

Exercise 11

Exercise 12

The total amount of points to collect from completing all exercises up to this point is : 26 points

Approve and transferFrom

Exercise 13

Exercise 14

Exercise 15

The total amount of points to collect from completing all exercises up to this point is : 30 points

Tracking user deposits with a deposit wrapper ERC20

Exercise 16 and 17

Exercise 18

The total amount of points to collect from completing all exercises up to this point is : 36 points

The end?

Congratulations on reaching the end of the tutorial!

As new exercises could be added, there might be additional points to collect in the future, though. Who knows?