• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language Cairo
  • Created over 2 years ago
  • Updated 9 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 build StarkNet <-> Ethereum cross layer applications

StarkNet messaging bridge

Welcome! This is an automated workshop that will explain how to use the StarkNet L1 <-> L2 messaging bridge to create powerful cross layer applications.

It is aimed at developers that:

  • Understand Cairo syntax (not familiar yet? Click here)
  • Understand the Solidity syntax

Introduction

How it works

The goal of this tutorial is for you to create and deploy contracts on StarkNet and Ethereum that will interact with each other. In other words, you will create your own L1 <-> L2 bridge.

Your progress will be check by an evaluator contract, deployed on StarkNet, which will grant you points in the form of ERC20 tokens, deployed at address 0x031d9e05ec67956acfec4768f7b302a56f8a256686fa077594f6dde40d5ca04c.

Another evaluator is deployed on L1 (evaluator contract). It will check your work on L1, and send back instructions to the L2 evaluator to credit you points on L2.

Each exercise will allow you to explore the Starknet messaging bridge in a step by step way. Be sure to check both sides of the exercice - on L1 and L2.

  • In exercice 1 you will use the L1 evaluator to send a message to the L2 evaluator
  • In exercice 2 you will use the L2 evaluator to send a message to the L1 evaluator
  • In exercise 3 you will deploy an L1 contract that sends a message to the L2 evaluator
  • In exercise 4 you will deploy an L2 contract that sends a message to the L1 evaluator
  • In exercise 5 you will deploy an L2 contract that receives a message from the L1 evaluator
  • In exercise 6 you will deploy an L1 contract that receives a message from the L2 evaluator ​

Getting ready to work

Evaluators addresses

  • The L2 Evaluator is accessible on Starkscan or Voyager at address 0x0455c60bbd52b3b57076a0180e7588df61046366ad5a48bc277c974518f837c4
  • The L1 evaluator is accessible on Etherscan at address 0x94210fB83a2C1e548add07026DaA294a440Ae86d

Working on the tutorial

L2 -> L1 communication takes ~30 mins so it is recommended to complete the L2 -> L1 part with care, and then start working on the next exercice while the message is passed.

Exercises & Contract addresses

  • The L2 evaluator is deployed at address ``, you can interact with it using Starkscan or Voyager
  • The L1 evaluator is deployed at address ``, you can interact with it using Etherscan

Tasks list

Exercise 1 - Send an L1→L2 message with an existing contract (2 pts)

  • To validate this exercice, you need to successfully call ex01SendMessageToL2() on the L1 evaluator
  • It will then send a message to the L2 evaluator and trigger function ex_01_receive_message_from_l1(), which will credit you points.
  • Be careful! There is a constraint on the value of "message"

Exercise 2 - Send an L2→L1 message with an existing contract (2 pts)

  • To validate this exercice, you need to successfully call ex_02_send_message_to_l1() on the L2 evaluator
  • It will then send a message to the L1 evaluator
  • You will then have to trigger function ex02ReceiveMessageFromL2() on the L1 evaluator. This function will validate your answer, and send instructions to the L2 evaluator, through the L1 handler validate_from_l1(), which will credit you points
  • Be careful! There is a constraint on the value of "message"

Exercise 3 - Send an L1→L2 message with your own contract (2 pts)

  • To validate this exercice, you need to write and deploy an L1 smart contract that calls the ex_03_receive_message_from_l1_contract() L1 handler on the L2 evaluator
  • The handler will credit points to your account

Exercise 4 - Send an L2→L1 message with existing contracts (2 pts)

  • To validate this exercice, you need to write and deploy an L2 smart contract that sends a message to the L1 evaluator
  • Once the message arrived, you then need to trigger the function ex04ReceiveMessageFromAnL2Contract() on the L1 evaluator. This function will consume the message you sent, and send instructions to the L2 evaluator, through the L1 handler validate_from_l1(), which will credit you points
  • Be careful, there are constraints on the EOA that triggers the function!

Exercise 5 - Receive an L1→L2 message with your own contract (2 pts)

  • To validate this exercice, you need to write and deploy an L2 smart contract that can receive messages from the L1 evaluator
  • You then need to call ex05SendMessageToAnL2CustomContract() on the L1 evaluator. This function will send a random value to your contract, as well as to the L2 evaluator. Your L2 contract needs to store that variable, and make it visible with a view function called random_value()
  • Once both messages arrived, you need to call ex_05_check_result() on the L2 evaluator. This function will call random_value() on your deployed L2 contract, and check wether the random value received matches the one he received

Exercise 6 - Receive an L2→L1 message with existing contracts (2 pts)

  • To validate this exercice, you need to write and deploy an L1 smart contract that can receive messages from the L2 evaluator
  • Your L1 contract needs to have a function consumeMessage() that triggers L2 message consumption
  • Once the message arrived, you need to trigger the function ex06ReceiveMessageFromAnL2CustomContract() on the L1 evaluator. This function will call consumeMessage() on your L1 contract, and check that your contract was able to consume the message correctly.
  • It will then send instructions to the L2 evaluator, through the L1 handler validate_from_l1(), which will credit you points

Annex - Useful tools and ressources

Checking your progress & counting your points

​ Your points will get credited in your wallet! Add token 0x031d9e05ec67956acfec4768f7b302a56f8a256686fa077594f6dde40d5ca04c and check from time to time. ​

Articles & documentation

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! ​

Where am I?

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

Topic GitHub repo
Learn how to read Cairo code Cairo 101
Deploy and customize an ERC721 NFT StarkNet ERC721
Deploy and customize an ERC20 token StarkNet ERC20
Build a cross layer application (you are here) 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 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 ​

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:

  • 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

​

More Repositories

1

starknetbook

Mastering Starknet. By the Starknet community
CSS
824
star
2

starknet-cairo-101

Learn how to read Cairo code
Cairo
471
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