Welcome! This is an automated workshop that will explain how to use the StarkNet L1 <-> L2 messaging bridge.
- The first part allows you to send messages back and forth from L1 to L2, without necessarily having to code.
- The second part requires you to code smart contracts on L1 and L2 that are able to send messages to L2 and L1 counterparts.
- The second part requires you to code smart contracts on L1 and L2 that are able to receive messages from L2 and L1 counterparts.
It is aimed at developers that:
- Understand Cairo syntax
- Understand the Solidity syntax
- Understand the ERC20 token standard
- Understand the ERC721 standard
- Are willing to pull their sleeves up and get to work! This workshop is the first in a series that will cover broad smart contract concepts (writing and deploying ERC20/ERC721, bridging assets, L1 <-> L2 messaging...). Interested in helping writing those? Reach out!
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!
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
- StarkNet messaging bridge
L2 -> L1 communication takes ~30 mins so it is recommended to send the messages from L2 to L1 as soon as possible and to do the exercises on L1 in the meantime.
The tutorial has multiple components:
- An evaluator contract, that is able to mint and distribute
L1L2-101
points - An ERC20 token, ticker
L1L2-101
, that is used to keep track of points - An ERC721 token, "L2 nft", ticker
L2NFT
- An evaluator contract, that will communicate with the evaluator on L2
- An ERC20 token, ticker
TDD
- An ERC721 token, "L2 nft", ticker
MNT
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!
- Go to the ERC20 counter in voyager, in the "read contract" tab
- Enter your address in decimal in the "balanceOf" function
You can also check your overall progress here
You sent a transaction, and it is shown as "undetected" in voyager? This can mean two things:
- Your transaction is pending, and will be included in a block shortly. It will then be visible in voyager.
- Your transaction was invalid, and will NOT be included in a block (there is no such thing as a failed transaction in StarkNet).
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.
- Set up the environment following these instructions
- Install Nile.
- Linux and macos
alias nile='docker run --rm -v "$PWD":"$PWD" -w "$PWD" lucaslvy/nile:0.8.0-x86'
for M1 macs you can use this image instead lucaslvy/nile:0.8.0-arm
- Windows
docker run --rm -it -v ${pwd}:/work --workdir /work lucaslvy/nile:0.8.0-x86
- Clone the repo on your machine
- Test that you are able to compile the project
nile compile
- To convert data to felt use the
utils.py
script
StarkNet Core contract: 0xde29d060D45901Fb19ED6C6e959EB22d8626708e Goerli faucet (0.1 ether every 2 hours)
- Use a function (ex_0_a) of the L2 Evaluator to mint ERC20 tokens on L1
- Mint tokens on L1 DummyToken by consuming the message with the secret value
- Show that you have the tokens (
i_have_tokens
) to trigger points distribution on L2 (2 pts)
- There is a contract on L1 MessagingNft that can mint an ERC721 token.
- It can receive any message from any smart contract on L2, if the payload is formated correctly
- Player has to write a L2 contract that sends messages to (MessagingNft), which will mint an ERC721 token
- Player has to submit the L2 contract that sends message for the minting to the L2 Evaluator
- Player has to call the ex1a() from the evaluator
- Player has to consume the Message on L1 MessagingNft, the points are distributed automatically to the player on L2 after the mint (2 pts)
- There is a contract on L2 l2nft that can mint an L2 ERC721 token.
- Player has to write a L1 contract that sends messages to the L2 Evaluator, which will mint an ERC721 token (2 pts)
- Player has to write a L1 contract that consumes messages from L2
- Player has to call ex3_a() from L2 Evaluator
- Player has to call ex3() from L1 Evaluator in order to consume the message and trigger points distribution (2 pts)
- Player has to create a L2 contract that can receive message from L1 Evaluator in order to set the random value assigned on the message
- Player has to call ex4_b() from L2 Evaluator in order to get the points (2 pts)
Useful resources
https://starknet.io/documentation/l1-l2-messaging/#l1-l2-messaging
https://starknet.io/docs/hello_starknet/l1l2.html
https://github.com/l-henri/StarkNet-graffiti
https://twitter.com/HenriLieutaud/status/1466324729829154822