StarkNet Cairo tutorial

StarkNet Cairo tutorial · 31 Mar 2022 · 1:12:22

Henri Lieutaud and Lucas demonstrate Cairo development on Starknet, covering account contracts, Nile tooling, and ERC-20 and ERC-721 exercises. They also explain L1–L2 messaging and how to build applications that send data between Ethereum and Starknet.

Speakers

Topics

From StarkNet Cairo tutorial.

Transcript

cool okay so today I'm going to so thank you for assisting thank you for waiting for me um today I'm going to show you how to get started developing on um Stark net how long do we have Leo for this presentation well one hour okay perfect so my goal will be to explain to you how you can start developing stuff on um Stark net and what are the main differences with uh for example solidity um okay so I'm going to skip

this I'm going to assume that you were here for the last presentation and that you're aware of how ZK rollups work if not I'm sure you can find the recording online later on okay so now about the developer experience on starnet the first thing to note is that starnet is not an evm chain um it uses provable computation and as such it has a specific smart contract language called Cairo um which allows you to do provable computation this has a few drawbacks um the first one being that

you have to learn a new language but it has some advantages also um solidity was designed specifically for the evm and so for a virtual machine that is of limited size so it's kind of like if you when you're writing solidity code you basically can execute it just on a very small machine right Cyro doesn't have this limitation Cyro can execute arbitrary complex code and so there are some limits right now in stet in terms of how much computation you can do but um but this limit may rise uh with the network a long time so

that's one big uh big big Advantage um this slide is a bit outdated we now have a solidity to chyo transpiler so if you don't want to learn um Cairo you can use this which is called warp and war is basically a tool with which you can um compile your solidity code into Cairo so I'm going to share the repo here and you can have access to it if you want to explore it um it's a good tool so um the way it works currently is that um some things are available on Stark net uh most

things are available on Stark net that you can have on solidity some things are not something very specific so for example you know um block. um Bas fee doesn't exist in starnet so we don't have it in U in in in starnet um but other than that most things exist right um now about stand implementations if you're developing on solidity you're probably very used to using erc20 contracts and erc721 contracts that were developed by open Zeppelin um and basically the really

cool thing with these contracts is that you can just take them and customize them and then deploy them which is great um you on starnet were in the process of developing this F open Zeppelin is working on a set of Cairo contracts of boiler plates chairo contracts and so um there are um and they're working on it they're not totally fixed now you can use some of them in the uh you can use some of them as is now but make sure if you write prodution code that eventually you'll move to uh the more audited version and the latest version so be mindful of this while they're still not solidified

it's worth to update them regularly now number another important thing to note is that compiling code in Cairo and importing functions Works differently than solidity let me show you um so this is one repo we're going to work today on I'm going to clone it right then show it to you okay so this is my repo and these

are my contracts oh you can't see my repo you can't see my screen wait a minute okay okay I'm going to share my full screen okay so now you should be able to see my uh my full screen okay um the the way smart contracts works so let's take this one for example let's say the one erc20 here which goes dumy token esc20 you can see that in the contracts

folder here there are two types of of erc20 contracts there is one called erc20 base and one which is called Dy token erc20 this one is what we call the base contract or a backend contract and this one is um an interface contract or not an interface it's a frontend contract it's an implementation so basically the way it works is that all the logic of the functions the internal Logics is programmed in the Bas file here so there's one call here like this function is entirely internal it can't be called by other contract and this contract here

the frontend contract will import these functions and use them inside his function that it turns into front end function so these functions they're marked as external they can be called by our contract so one big difference with solidity also is that you have one smart contract per folder there's no notion of having you know uh various contract in the same file so you have one smart contract per file inside of them you can import other functions from other contracts so here where I'm importing a base contract and then inside my function I use the

internals um the fact that this cont contract has only internal functions and that this one has external functions is not enforced by the compiler it's a programming convention convention for now um which is visible here and you can see people discussing about it let me share and you can see um and you'll see what people use for what reason okay um so be mindful of that then another very important thing when dealing with Stark net is that on ethereum there is no notion of

externally owned account on ethereum when you're doing a transaction most of the time you will use a private key and a public key and this public key is your account and this public key can hold funds there's no such things such thing in um in starnet in Stark net every account is a smart contract and these smart contract are called account contract they Implement some logic to identify the user so they have a function called execute and in execute you will have some signature that will show um who uh is doing this

SCH and you will have non management inside the smart contract but there's no non management and there's no no Ash and there's no signature at the transaction level so this is a very diff important distinction um it's something that has been long sought after on ethereum a lot of people wanted to build this but they haven't been able to change theum enough to do it so we are lucky that we're coming after ethereum with a few years of experience to build upon and so we decided to implement it from implemented from the from the beginning this allows of a lot of really interesting use cases

that I invite you to explore now regarding um idees and how you build on Stark net there are three main tools you can use one is the Stark net CLI it works but it's a bit raw then you have hard hat which is used with JavaScript and Nile which is used and written in Python today's tutorial is based on Nile both are very new tooling I would say the following developing on Stark net and is um developing with Cairo is not easy um but not necessarily because of

Cairo it is difficult because the tooling around it is much more nent and as has much more bugs than what you would find on ethereum so developer experience is difficult not because of the language but because of the environment so be mindful that these toolings are being developed so if you find a bug document it maybe submit a here corrected but you know there's no roads here we need to build them as we go okay so how do we get started first of all I want to introduce to you I want to introduce you to a bunch of tutorials I'm going to show you the first one here and then two

others actually three others like I me this one too the first one is this one starnet Cairo 101 going to share the link um and um this tutorial is a tutorial where you don't have to write code all you need to do is just read code and interact with the ecosystem there is a long read me here that I invite you to read it will explain to you how it works basically you will need to install a browser extension called Aron X which is here and once you have installed AR X

you will have to create an account so I'm going to create a new account it will ask ask me to download my back [Music] app that's a desate backup okay so it's going to deploy it once I have it this tutorial is a set of smart contracts that are written here and the code of which you can read here for example and all of these tutorial they're deployed on Stark net and each tutorial has the each exercise has a

function that will credit points to you in the form of erc20 points see this function here and this function here will give you points the points are also deployed on Stark net and they're here right so I can go here and if I want to see my points in Aral X I'm going to just add a token here it already appears right it's SC [Music] 101 just going to wait for it to be added okay so I already have it in my

wallet and I can see that I have zero points so far so what am I going to do I want to collect points so I'm going to read the exercise and do what is necessary to get to the distribute points here okay so while reading it basically you will get a lot of intuition as to how things work okay so read the comments it will explain to you what you need to do and here so these are the import directives this is the Constructor there is not much to do here okay so there is a function called claim points what does it do what are those things implicit arguments okay it's written here so I can read more about

them here then what do I do oh okay so this line will read my address the address of my account and then it will simply credit points to me validate the exercise so I can only do it once and distribute points okay so I just need need to call this function to get points easy all right so here's the exercise one and here it is deployed once I'm on the interface here I can see an interface here to read the data from the contract and another to write data to the contract so you know I just need to call this function and I should get points I'm going to send

this a something did not work my wallet is not deployed yet so I'm going to wait for a bit let's see these transactions are taking some time to be executed okay my transaction has been accepted so now my wallet should work right okay it's deployed I click on transact and now my transaction should go through okay I can now go and check my transaction and verify if it was uh when

it is accepted and when it is accepted I should get points here okay so I'm just going to leave it there let's go look at the second exercise okay so this was very easy let's look at what happens in the second exercise all right so second exercise all right there's a bunch of St okay I want points what do I need to do so it's reading my address and now okay so it's reading a value from Storage so this is how you create a variable and all you read from another variable Okay cool so my secret

value is compared to my value what is my value oh it's here okay interesting so for this function I need to send a parameter it's a felt so in the previous exercise it was explained what a felt is so I invite you to read it okay so basically it compares the parameter I'm giving here to a parameter it has in storage and this is the equivalent of a require so it means this should be equal all right so basically I need to figure out a way to read this value and I need to call myun function by input itting here okay so where is this okay so this is basically an exercise to explain to

you how to create the storage variable and how to make it public so that anyone can read it so okay cool this means that I just need to read the value and then call the proper function with the correct value let's try to do that so what's the name of the getter it's called My Secret value Okay cool so I'm going to go here read contract ah my secret value let's read it this is a bit slow okay so it's

31020 pretty cool so now I should be able to call claim points here with my value by the way let's check before that my transaction passed so I should have points here my previous transaction okay I got two points now I'm going to complete this and once this transaction pass passes I'm going to get four points okay this was easy um and so basically the whole tutorial is this each exercise is fairly straightforward if you come from the exercise before so

really they're just you know it's about reading them one after the other doing the first two exercises will what will be what takes you the most time and then waiting for transaction is will will take you some time also um Stark net is still a bit slow it will get better but for now this is what will take your time so I highly encourage you to do this tutorial if you want to get a feel of what the syntax of Cairo is and while these exercises are very simple these one here are much more complex um but if you do them in an order they should be very I mean they shouldn't be too difficult to do so I suggest

you I suggest you do them one by one and by the end of this tutorial you should have a good feel of how how Cairo code is organized how to read it how to interpret it and things like that okay so that's for our first tutorial the Stark net CYO 101 are there any questions so far there Al what's what's the extension it's called AR X it's called AR X so I'm going to put a link wait a

second yeah AR X yeah we can we can we can cool did you find it okay yeah sure I find it it's um yeah I know it's a it's ome I don't know if there are questions from the audience or if I can help with something else uh is yeah no question there okay good so that's all my

um all right so this first tutorial is basically about reading code now let me check uh I don't know if Lucas is here if he's been able to join one of my coworker Lucas should be uh joining the conference I don't know if he's the in the waiting [Music] room can you uh can you check Leo please if Lucas is in the waiting room I shared the zoom link with him and he's present the next tutorial uh no we can we we can't send

link in the waiting rooms no what I mean is is Lucas in the waiting room right now is good can you are you connected Lucas can you hear us yeah I can hear uh but Lucas can you hear us and can you talk yes sorry didn't hear you cool thank you so everyone here is Lucas um and is working with me on Stark net Dev advocacy so Lucas I just presented the Stark net CYO 101 and I was about to present the erc20 and erc721

um okay go on for the first one my original has some troubles okay so you want me to present erc20 or erc721 as you wish As You Wish Okay cool so um yep I'm actually going to share my screen again cool so now let's take a look at the erc20 contract so this tutorial here's the link is a bit different but a bit similar to the first one um basically it works the same way in the sense that as you do some questions you get and you

receive some points um if you look at the contract address is here right and you can add it in AR X right here okay add it here and I think it's the it's already my wallet but you know you can do it that way cool it's already there no problem um now um in order to use this tutorial the way it works is the following you will have to write you will have to take an ec20 contract and customize it to satisfy

conditions required by the exercises um and basically here you will be working on doing an Ico um the way it works is the following in order to correct it um there is a smart contract here called the evaluator smart contract consider it as a robotic teacher is an automated teacher and so when you want it to correct your smart contract what you need to do is deploy your smart contract and then say to the teacher hey teacher uh can you correct my uh my contract please so you will for example send him here you will call this function you will send him the address of your smart contract and then you will

say okay I know what your address is now do the now let's correct the exercise and then you can call these functions that will correct your exercise so let's take a look at what they are this first question doesn't require me to submit code I just need to call it to receive a rank basically there's some uh there's a good amount of uh information here about what you is required in this part what the evaluator wants to check is that I'm able to deploy an nc20 token and that I am able to set a ticker as well as a Sten

Supply so how do I do that let's take a look so first I need to get assign a ticker and a supply so I'm going to do that first let's go to the evaluator then you know write contract assign rank I can just call that and then wait for it to be to be mine it's going to take a [Music] while and the transaction is here let's wait to for it to be mine and for me to be assigned a a tier in Supply now in the meanwhile I'm going to take a look at what is in

this fun following function okay so what does it do okay so it reads my address and then it reads the supply and the symbol that was assigned to me then it retrives the address of my deployed contract so the contract I'm going to deploy it reads where it is stored and then you will declare a variable and from my contract here read the total Supply and you will check if the total supply of my token is equal to the expected Supply so what he assigned to me okay so I need to create just as

many tokens as you want me to and then you will read the symbol by calling this function and verify that the symbol of the token I submitted is the correct one okay fair enough then here you will check his address and he will read his balance in tokens from my token okay so he's basically checking that this function is implemented then he will try to call approv to verify that Pro is implemented then you will verify that it was it had an effect by reading the allowance here okay cool and then it's validated okay so basically I just need to declare an

erc20 with the proper to current supplyer now how do I do that okay let's take the repo so here the folder contract I can see that there's a folder called token and one called rc20 let's take a look so I'm going to copy this one actually I'm going to call itc2 henry.

Cairo all right so how do I set the total Supply probably I can do this here right I'm calling the Constructor and here I can set the name and siol and initial Supply so probably what I can do is just you know deploy this contract by setting the correct ticker and supply and then I should be okay so let's try that how do I deploy a contract how do I call the Contra The Constructor let's take a look here um is there any information how to

deploy a contract on 721 H okay so in this repo I'm going to give you a shortcut here in deploy there is a bunch in in this for file there is a bunch of examples of commands so basically I'm going to take one here copy paste it and then you know iterate from here okay so Nile is the tool we're using deploy is to deploy to Smart contract this is the name of the contract so my contract is called erc20 enry so I'm going to put this here then here are the values I'm passing as

argument and then the network where I'm deplo going so here basically what I should do is add the arguments that are here so the name the symbol the initial Supply and the recipient so name I can put whatever I want so I'm going to call it Henry poken wait I can't pass this as a string okay so something important to note is that when you're doing when you're um dealing with CLI tools here you you should put everything or at least most things in decimal okay so here I need to convert my ask it string to decimal turns out there is a tool for

that here so huh python I let's do this so I can do python ITIL like this H nice so now I can do string to fils it didn't like that let's try this okay let's try with Python 3

this is better okay so this is the felt so I didn't mention it because it's in the first tutorial but a felt is basically an integer but instead of going to 2 to the power of 256 it goes to 2 to the power of 251 it goes actually it goes to a prime number in the order of two to the power of 251 um and the reason for that is is with the mathematics behind Cairo um since Cairo compiles to arithmetics instructions uh executed on pols um we can't use bll and logic and I mean we don't use natively Boolean logic and

powers of two so we use this big prime number okay so this is the name of my token represented as uh decimal what should I put next symbol oh so for the symbol I need to put the symbol that was assigned to me let's see this transaction was accepted so now I should be able to read a ticker and a supply that were assigned to me okay so what's my address okay so that's the supply I

should have that's my ticker by the way this is a ticker in the decimal form let's see how it looks in a oh okay oh so that's my ticker okay so symbol it's this initial Supply okay so I'm going to put this and then recipient okay so recipient it's me let's see if this works all right so it won't work but let's see

why so okay let's try to execute that command and deploy the contract huh first of all I didn't set up the environment yeah true so something really important to note is that setting up your environment this part here is the most important and the longest thing that will the longest thing that for this tutorial once you're done with setting up the environment you should be able to do this um to have Nile do something and it should work so here I'm going to try to deploy my contract and it's going not going to

work why exactly exctly no such file directory artifacts erc20 and R Jon okay so I wrote my contract in Kyo but I didn't compile it so let's compile it n compile and then I should be able to deploy it right it's going to take a few seconds and see here in erc20 enry what I'm doing really is just you know taking the base functions of erc20 I'm really reusing most of what exists and then I can add some function so here for example I added a faucet so I mean it was in the in the dtk

erc20 so what it does is just basically you know set a number of tokens to distribute Min them and send them to the person calling that's it and so that's really like similar to what you would do in solidity you know you add functions building on on the others okay so my contracts were compiled now can I deploy my contract it won't work but let's see why so what is the issue here expected at least five inputs got four wait that's strange there are five value here why does he expect five uh there are five sorry four lines why does he expect five well I explained a bit earlier that

the base type of Cairo is a felt which is basically between 0 and 2 to the power of 251 now solidity uses 2 to the power of 256 with a un 256 so this means that if you want to manipulate values between 0 to 0 to the^ of 256 you have to use two Felts and so we have this abstraction here U to 56 which is basically a struct with two fils so basically here in the Constructor when it is expecting one two three four values is actually expecting

one two three four five values so this is two fails I should I should give so in my command here this is the um so both values should be the first 128 diet or the second or the I mean the least significant 128 by or the most significant 128 bytes so this is the least significant it goes first and then the second part you know just going to put zero because there is no I mean this is less than 128 bytes so now I'm going to send this my contract should be should deploy let's

see swe pounds yes it went through okay super cool so let's take the transaction hash and you know I'm just going to wait for it to go through while it is going through though here is the address of my contract so I can submit this one already so you know I'm going to go to write contract I've deployed my contract and now I can tell him hey look this is my contract so I'm going to use this function and transact okay so now what am I waiting exactly I'm waiting for my smart contract to be deployed here and I'm waiting for the evaluator to know what is the address of

my contract and then I will be able to call this function which is this erc20 um and by the way while I'm doing that in the evaluator I can check here so when I called submit erc20 ex is pretty cool I get Five Points here and when I call the sign rank in the beginning I also got one point here very cool so now when this transaction when this transaction goes through I should get five more points and when this once this transaction has gone

through I can call this one and I should get two more points so okay let's wait for this transaction to go through this is me waiting for my contract to be deployed and this is something else okay so basically the whole tutorial is this you know you take an erc20 and then little by little you customize it so if I look here what is question two so so Distributing token I need to create a get token in my contract I need to deploy my contract and then I should

show that get tokens work okay so let's see this function it's it's here so what does it do it reads my address it retrives my uh my exercise and then it calls get tokens that's get tokens which is an internal function let's see ah it's here so what does it do okay it reads the address of the evaluator it reads the balance of the evaluator and then it tries to call a function called get tokens and it expects to see the amount received so now it checks that this amount is not

zero this is an operation to check that this amount received is different than zero and then actually it's actually to check that zero is lower than amount received so and then I'm going to read he's going to read his balance again and he is going to check that the final balance and the initial balance are different by the amount received which is what was expected Okay cool so basically I need to implement a faucet here okay so maybe I can rep purpose uh the faucet I saw here

right and then you know call it get tokens [Music] and here it returns success instead of returning success let it return amount that should work but I'm not going to do it right now you'll do it yourself what I want to underline here is that basically if you follow these exercises you're going to be adding functionality and then understanding how to manage wh list uh multi Tire allow list and then you're going to learn how to manipulate an erc20 from a over contract deposit tokens in a over contract this whole

tutorial will take you through basically how to deploy and manage an erc20 on Stark net okay okay so my transaction has been mined my contract has been deployed I should have six point here now right I do now I'm going to tell him test my year C20 and I should get two more points okay and so the whole idea with this tutorial is just this you know go through the exercises implement the functions deploy the contract get feedback on it and move on and so by the end of this tutorial you'll be confident with managing anc20 and customizing it on Stark

net okay um I can take questions if there are otherwise this just wait for me to show off with my eight points and I'll let Luca do the following are there any questions uh there a question about the emac extension is there going to be uh emac I I'm not sure to be honest we have extensions so right now I use um sublim text and you know in my uh here I can

basically tell it you know syntax open all current extensions as and I can tell him a copy the syntax of python so I use the same Syntax for my uh e ID than um than python but um and I'm sure you can do in a lot of uh of editors in vs code there's an extension for emac specifically I'm not sure okay thank you okay cool so this was a tutorial on erc20 we also have another tutorial on ESC 721 do you want to present it Lucas sure so let me share with you so uh the erc721

tutorial kind of looks the same as the erc20 though it manipulates nfts so let's start we assume that you now have a running environment if you don't want to spend time you can use the docker containers um but let's start so let's see exercise one so it says create a near system 21 token contract and there's an implementation provided as a base so let's see what it looks like okay so it's a basic vfc 721 contract let's see what we want us to do so we have to give token one to the

evaluator contract submit the exercise as in the year C7 in the year C20 so the evaluator knows our contract and then call this function so let's see what this function does okay there's a lot of code um so we get token 81 okay we see the player submission and then we assert that the evaluator has the token one here we look at the owner off there's the first assertion then we assert that uh the evaluator has a balance we get the balance of the

evaluator then we get and the balance of the player and we look if the evaluator has a [Music] balance and then we transfer the nft from the evaluator to the sender and we assert that the player has now a balance so to do that it's simple the contract does everything itself so we just have to M an N for him so let's go in token 21 verus 721 CYO so it takes the name the symbol to um and let's see what it does

so it means the first token to the address we give him as an argument so perfect let's use this so we're going uh into the uh let here uh let's go in contract tokens here 721 okay we're here and then we have to compile thec [Music]

okay it doesn't work uh why Let's see we have a problem with this one this one doesn't work and here see why does it strange let's try that again from contract okay it works so we have to be in the

main directory to compile the contract so now we have to get the evaluator address so we go on the r me and then we have all the construct addresses nice evor we take this one so for the name I don't want to bother uh giving it a real name so I'll just do one and one so we deploy thec 721 with our for the name we say let's do one because for symbol same and two we go with the evaluation okay and now what we can do because we don't want to spend too much

time waiting for D transaction we can import um from the evaluator we can import [Music] maybe yeah the this one the uh interface so we don't have to spend time uh okay no we can't so we're not going to do that but the main thing is you can uh create an interface of the evaluator so you can call in your Constructor the submit exercise so you don't have to wait two transactions right now I'm not going to do it because it's going to take too much time but let's deploy the

contract with this let specify the network and then we wait for the [Music] transaction all right and while it's deploying I get the address we go onto the evaluator right and then we're going to submit our exercise so the evaluator knows about our contract and we can do this much for the

[Music] transaction and then while we're waiting we can go to the next exercise so we see call get anal so there's going to be some more customization and this is where the fun CU this one pretty basic everyone knows how to do this so now you have to get animal characteristics that's that looks interesting so let's see exercise two here get an rank so we're going to get a rank with a sign characteristic well it's just the same as the

erc20 now it's going to check in this function all right let's see what this function does so it creats are assigned sex legs and wings then it gets our solution gets the aor address it it asss that the token belongs to the evaluator as in the first exercise so we're probably going to use the same contract right and then it calls this function so this function is in this interface which is exercise solution so we get a hint but we got to implement all this function in the end so let's see get an

characteristics takes the token ID and returns few character characteristics right so we're probably going to have to implement this function and return what we're going to get assigned in the function and then what it does inter that is equal pretty logic and and then if everything is fine it gives us point right so now what you have to do is that only that follow the exercise implement the functions with the same name obviously and then everything is going to be fine so let's see if the transaction was accept pending so pending means it's

accepted but it's bending for a block to be mind so it's going to take some time probably a few minutes and then what we can do is call this function which I'm probably not going to do in front of you because it's going to get it's going to take some time but you can do it and then get your points and you can you can tweet about it and you can tag Lou and he will be happy to retweet so here I'm going to do this just to show

you and here is the wasting time so basically that's it for thec 721 if you have any question don't hesitate U yeah don't have any question so I saw on the chat there was a question by ashl Lord regarding fees on starnet I posted a link that will explain um how to use how fees are calculated right now the what you have to have in mind basically is that storage storing value on Stark net will be relatively expensive kind of like ethereum but doing computation will be very

cheap that's this Okay so we've presented you three tutorials one to learn about Cairo two to learn about erc20 and erc721 I want want to show you k you really quickly um one other tutorial we have which is about bridging between Stark net and L1 because you know the other ones are showcasing things that are specific to things that you can do on ethereum and bridging is where the magic starts is when you get to really do cool things with Stark net so let me share my screen real quick okay let's

go um so the way this work to Summit up quickly is that you know when we think about bridging most of us think about money or assets you know you're bridging E from ethereum to salana you're bridging nfts from ethereum to polygon um and you know that's where like when you think about bridging it's only about bridging assets you only think about money of things of value but you know we could build more bridges you could Bridge merge more things you could Bridge permissions for example you know if I have permission to do something in ethereum I should be

able to do something else on Stark net or maybe I could Bridge computation I could execute something on one chain and then send the result of that computation to the other chain I could BR brdge in instructions you know I could say hey do this do the I could say on chain a do this on chain B so there are a lot of bridges to build um really and what we decided is to build none of these we decided to build a building block where you the users the developers of Stark net can get to develop your own Bridge so basically we only have one mechanism that is about bridging data from one

chain to the other you're not when you're using the Stark net messaging Bridge you're not bridging assets you're bridging data so you're sending messages from one chain to the other and on both end of the spectrum you get smart contracts that are able to interpret these data make sense of it and execute some kind of action the way it works is the following when you want to send a message from star net to ethereum first of all you will use a specific function called send message to L1 and you will just allocate an array of data of value you know and this you can Define it arbitrarily you will Define your own cross layer

protocol and you just use the function you know the address of the contract you're sending then the payload side and the payload so after once you've done that you know you trigger this function the data is visible by stocket and it has a statu so basically um the what happens is that these messages they're transmitted um when uh the proof of Stark net is sent to ethereum so this takes some time but basically while your message is on Stark net but not here on ethereum it's it's status is sent once it is on ethereum but has not been consumed it's kind of like if you sent a letter and it's at

the post office being waiting to be picked up in that case it's called it's in state pending after that it's in state consumed meaning that somebody came at the post office and picked it up so a smart contract came and consumed the message um and so this is basically how this work all messages are received on ethereum um one message can be sent various time it has an Associated counter um and then finally from your solidity contract you will call a function um in the Stark net smart contract called consume a message from L2 and you will basically say okay I received that message please consume it and so what happens at that point is

that this is basically this is basically a way for you to verify that indeed a message was sent to your smart contract and from Stark net so your smart contract can get math multiple certainty that one message one action was sent from starnet to it on E that's how you enable cross chain communication and you know inside that message can be a payload like we saw before you know uh who should receive what token so the address of the token the address of the person the amount it can be whatever you want really um so going from Stark net to ethereum as I mentioned takes a bit of

time right now on testet it's about two hours so you have to calculate a bit when you're doing these exercises or when you're building your application this will get short in time but for now it's this way okay I went very fast on this part um but it's recorded So you'll get time to get back on it and I want to finish because we've been at it for a bit more than an hour now so how does it work on the ense talking to Stark net basically it's the same way on the Stark net contract there's a function that anyone can call it's called send message to L2 you specify the address you want to trigger the smart contract you want to talk to on L2 you spe ify the payload so what you want to say to that contract

and then here there's a little difference when you're sending a message to ethereum the message sits in an inbox and waits to be consumed when you're sending a message to starnet the message is consumed immediately u meaning that uh the function you can call a specific function on the the Destin the recipient smart contract the selector here is used to do that you say which function you want to trigger and this function is defined as such you know we have external function internal functions and then we have L1 handlers these L1 handlers are just functions that are called um when you want to trigger a function from L1 okay in this case when

you're going from ethereum to Stark net the confirmation time the time for this transmission is much shorter it takes about 10 blocks okay um now why is this interesting it's interesting first of all because it's blockchain talking natively there's no concept of validators or people in the middle saying yes this message is authentic you have Stark net producing a proof that is is sending a message and this message being sent to ethereum so it's really blockchains talking to each other which is to the best of my knowledge the only such case in the blockchain world there is no other case where blockchains can

talk natively with mathematical tool without having humans in the middle the second thing why this is cool is that you get to design your own protocol you want to make a a bridge do a bridge you want to do an nft Bridge you can implement it yourself you want to implement an application where the brain is on L2 and the governance is on L2 and then it sends command to manage the muscle the liquidity on L1 you can do that you can do your own Bridges you VI have your own token you can do whatever you want and that's really cool and exciting and the second thing is that there is really a tight L1 integration you can really think of stet not necessarily as a separate network

but as an extension of ethereum since they able to communicate relatively fast and natively they this allows really interesting cross layer Dynamics to pay out and also something really interesting is that if you want to to manipulate assets on Stark net you can from Stark net manipulate assets on L1 in other terms if you want to use an app that leverages other liquidity polls or applications you can use the ones that are native to starnet or you can use the ones that are on ethereum you can use a or curve on ethereum you can use these liquidity sources in your app on Stark

net how cool is that and yes this feature is very much used by players of the ecosystem specifically maker of maker Dow the producers of D they're going to impl their Implement their own Bridge they want to be uh the managers of their own bridge on on starnet and they're going to and they're working on a feature that will allow you to Mint die on Stark net using liquidity that is on L1 on ethereum and finally you can use a a is exploring how to uh EX send a on starnet by maybe having defi pulling or to do a bunch of cool things all right I'm going to share the

link of this tutorial if I did not already I did not yet so wait a second it is it is here okay so we have a tutorial for that feature also wait a second it's here and I invite you to get take a look at it what do I want you to do in this tutorial it's very simple you know we'll just need to first read the contract and you will need to interact with contracts on L1 and L2 you don't need to write any kind of code you just need to send messages and collect points that's really that's really nice and really slow and that's pretty cool then I want

you to read the code and create a contract on Stark net that sends messages to ethereum and I want you to create a solidity smart contract on ethereum that sends messages to starnet and finally in the first step third step I want you to write a contract on starnet that receives message from ethereum and a contract on ethereum that receives message from starnet and that's it it's going to take you a bit of time it's going to be a bit challenging but there you really have access to some Stark net magic I want to State again that these tutorials are are totally free to use you can do them on your own time and you should have all

the resources to do them by yourself if you don't please tell us we want to make it easy for you to jump on stet development so whatever way this can be made more efficient or more easy on the eye it's most welcome so do tell us um join the Discord ask question and um and we'll be happy to answer them and I'm about done I don't know if there are any questions or if you want to say something Leo other than that I thinkk you for for your attention uh yeah sure just some questions um I have a question about the messaging Bridge uh is there any chance the

message the messaging can be intercepted by P so it depends what you what you mean intercepted or spoofed I think there's two attack surfaces your message you know you could trigger a message that is not authentic so you could say to ethereum hey this message AR arrived from Stark net when it really wasn't or the second thing is you could have a message not be transmitted in other word I'm sending a message and then it sto in the middle um for the first attack Vector can we spoof a message the answer is no um when you're sending a message uh the proof that is sent after from stet to ethereum basically will

compute that a message was sent and it will make sure that this message is part of the state update that is put on ethereum so there's no way to stop a message and the only way to add a message if is if there's a proof Associated to it so the only way you will have a message appear is if there's a valid proof Associated to that message now can you intercept the message the answer is also no I've so I've shown you the solidity code in the slides um let me check real quick and you know the the the code is actually really simple um let me share again see like there's literally five lines of code we compute the hash of the

message we check that the there's a message to consume and yeah that's about it you know you just check that the the person consuming see for example here the message the message being consumed is takes as an input the person sending the message so there's no way this can be triggered without having the actual recipient of the message triggering that function so that's the way we implement it there's no the only person who can unpack this message is the smart cont to which it is sent does that make sense yeah yeah actually you are sending proof Vis the

message yep okay I see thank you uh there's another question uh what if the the parameters are not recorded is there any impact and I don't understand the question if the parameters are encoded oh uh I need to okay let's wait about this uh question later okay can there

two implemented on other other chains other chain no for not we're we're just on ethereum and um yeah for now we're just to ethereum we it could be compatible with other evm chains um but this requires effort and tooling and right now we're very much believer in ethereum and that's where most of the activity and the users is are so we're focusing on ethereum okay thank you uh for [Music]

[Music] [Music] is there any Bridges between stocket with other chain other layer choose or side chains like polygon or

arbitrum so so right now no now the you could imagine having that uh basically you know since darket its computation resolves to a mathematical artifact any other chain could do this math so we could imagine something more intricate than this but for now um we only talk with ethereum we're only connected there okay right good uh uh still about the parameters it's means

uh if the parameters in Layer Two is not public is there any impact are they going to be so you're so you're asking what happens if the contract is badly designed right yeah probably not not not open source means right yeah yeah I mean uh What uh if the contract argument isn't recorded what's the impact you know if a message okay so I think I I get the the the question what happens if a message is sent on L2 and on L2 since it's executed immediately what happens is there there's an error there uh well nothing happens it's the message is

stuck and it stays in limbo and definitely [Music] uh okay let's see if there's uh other questions okay I think it's the time wonderful thank you a lot for your time and your thank you thank you thank you for getting us deep di in this it's

a wonderful coding oh thank you thank you Henry thank you Lucas and we hope to see you next time maybe sometimes to tell us more about W yeah definitely let's do that and we'd be happy to uh if you have any questions feel free to join us on Discord and um looking forward to meeting you there yeah thank you thank you very much thank you Lucas thank you byebye bye byebye