Session 3 Smart Contracts
Starknet DeFi Bootcamp (English) · 1:25:00
This Starknet workshop explains Cairo contract classes, instances, storage, interfaces, events, and dispatchers. A step-by-step counter exercise uses Scarb and Starknet Foundry tests, followed by wallet setup, testnet deployment, and reading and updating the contract through a block explorer.
Speakers
Topics
From Starknet DeFi Bootcamp (English), hosted by OpenBuild.
Transcript
hey everyone welcome to this session on building smart contracts on stocket uh this is going to be a super interesting session because you're going to learn about how the smart contract architecture looks like what are the different types of transactions and you're also going to be building your own smart contract and deploying it on staet so in this session uh we're going to be talking about classes and instances of smart contracts uh what are the different types of classes what are the different instances that are there um the anatomy of smart contract what it looks like what are the different components of a KIRO smart contract and of course there's going to be some life coding your teacher for today that's me online uh my name is Gan lakmi everyone knows me as Gyan I'm a developer Advocate at the stet
foundation I'm born and based in India Bangalore India and I can speak English Hindi Tamil and French yes I learned French as a hobby and uh if you want to reach out to me for any help feel free to reach out to me uh on Twitter uh or telegram both of my handles are the same but is at the rate don't get confused between this spelling and this spelling this is my official spelling but this is how people called okay perfect so um yeah this is going to be a great session I hope you enjoy and have the most fun uh take it slowly uh pace yourself and uh this is going to be a very interesting session and a very foundational session for you to learn about gyo smart contract itself
so yeah best of luck and have fun the first session is just all about understanding how the anotomy uh how the classes the contract classes and instances would look like uh let's quickly see this I think you might have seen it in the previous session uh but just to give you a quick recap Cairo is a provable programming language and we write smart contracts for starnet in this provable programming language called Cairo uh the syntax of this programming language is very similar to rust if you since you're already doing starlings and stuff you might see all of those similarities if you compare it to rustlings it's like quite similar but you will see some small but noticeable changes when you're writing using this programming language to write a smart
contract so please make sure that those and those small changes can be very very are very significant messages to the compiler right so um that's something you want to make sure that you're keeping track of Cairo programs compil to Sierra which is a safe inter mediate representation we will try to take a look at some Sierra files but of course they just look like um you know hexad decimals and stuff so we we will take a small example of that as well and the sequencer compiles Sierra to uh safe km so km is Cairo assembly uh which in um in the previous stage of Cairo which was Cairo zero the Cairo smart contracts directly used to compile to casm it had
its own drawbacks and stuff like that but now there is a safer version called Sierra and then it compiles to a casm all right the chasm is the contract that the assembly which is actually deployed on saket now in this one like I mentioned in the Cairo in the latest version of Cairo uh the failed transactions are included in blocks so in the earlier version of Cairo uh these failed transactions were not included in blocks and because of that were the cons that I was mentioning like there's a potential of like dos attacks and stuff and this ER is the one that enables this to happen uh the failed transactions so being able to have a safe intermediate representation is what enables you uh to be able to add fail transactions into
the blocks and because of the fail transactions are added the sequencer is always compensated so you you can't actually attack the sequencer and keep it bogged down and uh we don't see the Dos Vector as we used to see in KIRO zero so you don't have to worry about Kyo Z but I'm saying that we get questions sometimes like why Sierra why do you have intermediate representation this is exactly why we have it uh we want the contract to compile into a safe intermediate representation so that even if the proof is invalid uh it becomes a failed transaction and we are able to include it in Bloss and kasm is KIRO assembly uh of course from the kasm uh we generate a validity proof which then gets uh the proof goes to the verifier and the verifier uh verifies the proof
uh at the ethereum layer we'll see that in just a bit there's a question from Leon what exactly does it mean to to be safe in the cas of Sierra and kasum so the safe intermediate representation is kind of ensuring that the way your the way your Kyo smart contract compiles um so it adds certain nuances to the way the compiled contract can be represented for example in the previous versions there was no branching or anything that allowed certain conditions to take place that you didn't have the ability to have something like if something happens then take this particular action else take this particular action but now with
Sierra we have the ability to determine uh if the particular path that you're going through is correct then you your proof is valid and if the path is incorrect then you then the proof that you're generating is invalid so this is one example of how you bring in safety but there a lot of like these other kind of nuances that um that Sierra brings in uh in when it comes to like types I don't want to type safety is wrong with but basically being able to have a program that can generate a result that could be either valid or invalid so Sierra brings you that ability to do that did I answer your question satisfactory David maybe you want to add something just maybe to in a short
sentence that safe means that if the transaction execution fails it can still be included in the blog and can still be proven before it was not possible so failed transactions were just pretty much ignored yeah okay so now when you think of uh staff net contracts what what are the different things that you get so there are two things that you will see uh you will notice when you are trying to work with a contract so there are two steps to actually getting your written contract to onchain so the first step is called declaration right so if you don't declare your contract then you will not be able to deploy your contract um so this is the first step that is you declare your contract to create a contract class right so this contract
class consists of the chairo code that is compiled to Sierra the ABI that is which are the functions that are accessible and it generates a class hash of your contract class right uh so the contracts that we write the smart contracts that we'll write in Cairo the first step that we do with them is to declare those contract and generate a class hash of those contracts so every time we change we modify the code basically the hash of hash the class has changes so this is the first step that you'll always do with your uh smart contracts now the second thing uh the contract address that you find like say on Stark scan or whatever that is actually a contract instance which has
its own storage the associated class hash that you declared in the previous step and it has its address which is what we call as the contract address so when you deploy a contract on stocket you are actually deploying an instance of the contract on stocket but in order to deploy an instance you need to declare the class and have a class hash for yourself so I have another diagram that kind of explains it nicely that is if you have a class hash say 0x123 you can deploy multiple instances of that contract each of them with their own storage with their own with this particular class hash and having their own distinguishable contract address so
you can see here that the contract address is 0x 981 and another contract address is 0x 248 so these both are instances of this class hash and there is another example with the same which is you have another class hash and you can deploy multiple instances of this so this is very useful because we have I know you might have if you come from solidity background or just objectoriented programming background you might have heard of factory patterns right where you have a top sort of uh Factory which can help uh uh you know upgrade contracts or which can help call other classes keeping the functionality the same in the groups so this uh kind of helps make the upgradability quite
easy and I'll show you an example towards the end if we have some time about the factory pattern stuff but just remember two things so first you have to always declare your contract to get a class hash and you have to use that class hash to deploy an instance of that class hash that and then you get your contract add okay now the next thing is how do you alter uh the stocket state right so once you deploy a contract uh you can basically read from that contract uh so these read calls are free or you can write to the contract where uh it's a transaction and you have to pay some gas fees so read is more like call functions and write are invoke functions so let's see again uh what are the different types of uh transactions
that you can do the first one is declare so you declare and you get a class hash the second is uh if you have to invoke a particular uh instance right so if you have to invoke a function you have to make some changes so you're going to write in the contract so that's going to be like you know you're interacting with an instance of the contract and the third type of transaction is deploying an account so every account in stocket is a smart contract account so deploying an account is also a type of transaction and even over there you are deploying an instance right because you're generating a contract address that address basically becomes your wallet address that you work with in St so these are the different transactions types that we
have uh on stocket and let's take a quick overview of uh how this would kind of look like just ignore this mols it's not the same as etherum mols just think of all of these as transactions so the sequencer receives the transaction and over here you basically uh you know uh the sequencer is the one responsible for creating blocks uh and it creates the blocks and then you get this L2 block and uh you create a trace and send it to the Prov uh the prover will create the proof and it basically it runs and proves the snet OS uh then it sends the proof to the verifier the generated proof and the verifier will you know verify the proof on ethereum so you see
this is the L1 this is L2 and then you have stet core contracts that are also for interacting with the stet OS and I think what is missing in the piece is like you have some uh data backup and like data nodes and stuff where you can create the backup for your L2 so this is like a simple way of kind of uh looking at how transactions uh work on so when you deploy a smart contract also they are going through the same process what can you do with all that you learned that is stet uh smart contracts you can build onchain games um you can work on things like Giza which is verifiable new network execution please don't me what please don't ask me what this does
because I have no clue uh but I have some ml background but uh I don't know what is happening at the intersection of ML and blockchain so uh but whatever is happening it's like really cool cutting it stuff app chains of course we have Madara trees that whole Narrative of building your own app chain being able to customize uh things as per you uh your application and your users needs we have a ZK evm project which is Kakarot which is writing evm op codes in Cairo very very interesting and uh they are just about to launch I think mainnet they are doing a lot lot of rigorous uh testing stress testing and all of that and yeah a lot of other cool stuff right
um this basically explores uh the world for you to build anything on on chain uh but with being able to uh pay lesser gas fees and not worry about like U you know U scalability issues so smart contract an anatomy uh so now we are going to start a little bit into like looking at different pieces of code after these slides the uh there's someone who raised the hand David uh two people have raised their hands okay so for all of the next slides will you'll just be looking at pieces of code and understanding what these pieces of code look like uh what these pieces of code mean a compilation of all of these pieces of code is just your smart contract right so I've just
put different pieces in different slides and then it all comes together and becomes a smart contract eventually so the first thing is um this is how a bare minimum stocket smart contract written in Cairo looks like so what I'm saying is you can't just write something like mod counter contract without any of these uh uh you know annotations and just open close braces that's not a bare minimum contract a bare minimum contract will have this annotation which is your stocket colon colon contract this is because because like I mentioned earlier Cairo in itself is a provable programming language so when we are writing a smart contract for starnet in
Cairo we have to let we have to let the compiler know that this is a smart contract so we have to annotate this annotate it as this as a stocket contract and stocket contracts smart contracts are Cairo modules so uh when you want to write a contract you say mod which is a module name of the contract open close braces and then then uh you have to have a storage defined so a smart contract must have a storage defined even if it is empty so now this is your bare minimum sta net smart contract written in Kyu uh let's go to the next one now we're going to keep on adding elements to this bare minimum smart contract right the first thing we
are adding is of course an um a variable inside the storage so we we have a storage variable called counter now storage variables are variables that uh can be access that can be modified uh you know that can be written to that can be read from and you can access these storage variables uh throughout the contract so uh now this the first thing that we always have is a Constructor so a Constructor is like an initialization function so you have to annotate it as Constructor and the same way for storage you have to annotate it as storage so you add the it's a it's nothing but a function the Constructor so the keyword for that is FN for every function the keyword is FN FN then it's best PR PR is to name it Constructor right it it must
be called Constructor and then you have arguments of the Constructor that you see here one is called ref self colon uh the type of the argument the second name of the argument is initial counter and the type is u32 I'll talk about what is this ref self in a bit so these are arguments to the Constructor and then in this Constructor we are basically writing some type of value which is this initial counter to this storage variable right and uh we are saying that take this storage variable within my contract and then write to it this new value okay this is what this is doing uh and the Constructor is only called once when the contract is deployed and if you don't have anything to initialize then you can
just omit the Constructor it's not something that you need to have mandatory right simple so the next thing of course once you have your storage once you have your Constructor the next you're going to start adding functionality to your contract right so we come to functions so to write a function uh you use the FN keyword name of the function then you send arguments within the function right and if you want to return something if you want to return a variable your function returns a variable then you use this arrow symbol and then write the type of the return variable then within open close parenthesis or open close curly curly braces you write the logic of your function right this is a simple way to uh Define a function now but the topic
of this is not defined a function is called exposing functions what does that mean this means that how can you access your contract functions what are the different things behind being able to access your contract function now the first and the foremost important thing is that whenever you are having your main implementation block right so in darket smart contracts in Cairo you have this concept of tra interfaces and implementations interfaces are defined as traits right which in English means characteristics of this contract which we will also talk about in just a bit but each of these interfaces Define uh what is going to be the blueprint of
this contract that is what are the different functions that this contract is going to have what is largely the logic of this contract and then you implement those functions in an uh implementation of that particular interface right and this particular implementation has two functions in this case which is a get counter and the increase counter now for this implementation block if you want these functions to be able to be called external then you have to add this annotation called ABI edore v0 this is an important annotation that tells the compiler that this particular implementation block can be called
externally so this is the first thing that you need to understand now the other different so now automatically your for exposing these functions to being able to be called externally okay uh now what are the other nuances of calling a function either a function can be a readon function where you just you are just reading the storage variable for example in that function so let's see how you what are some nuances defined in the function in order to do that so when you have a readon function that is a view function you will see this format which is self and then colon at Contract state so this self says that the contract state so I want to access
the contract state of this particular contract which includes your storage variable right but I don't want to manipulate it I just want to read it so I'm going to access a snapshot of the contract state so the E refers to a snapshot so the readon functions take a snapshot of this State as a parameter and then you can read the value so for example counter is the storage variable you can read the Storage storage variable using self so in every function that you Define self should be the first mandatory variable because using self is how you can access the contract state of that function so you see in every
function that you will see uh you will see cells however you will see cells depending uh written in in a way whether it is a view only contract or whether it is a right State whether it is a view only function or whether you can you are actually doing some right now for the view only we saw that the self is just a snapshot of the contract State now in this case which is where you are writing something you are using a reference right so you're taking a mutable reference to the contract state so you see you are saying that this self is actually a reference and you're taking a mutable reference to the contract state which allows you to perform a right operation if you remove the ref in this
case and you try to write it you will not be allowed right so there are three takeaways from this particular this particular slide of exposing functions one is you want to expose all of your functions within an implementation block to be able to be called externally so you need to add an ABI embed annotation another is now we come to the function themselves if the function is read only it's only doing read operations you can have a self parameter and this only take takes the snapshot of the state as the parameter so you will see the at or if you want to write then you have to take a reference and this takes a reference
mutable reference of the state of course this cause gas and this is free okay why do we have this syntax because it is for better maintainability and then um you know you get a compiler error on type mismatch so it's good plus it is important because you deal with a lot of State changes in blockchain just in general and uh it is like you see a lot of hacks happen because there isn't proper access control or there is a lack of understanding of how which functions which part of code can access which other part of code right so this kind of gives you a better understanding of what is readon what is uh external or write and things like that
so like I mentioned in order to tell communicate to other people that what this particular what a particular contract would be doing right you actually write an interface right an interface is like a blueprint of a contract that what are the functions will this particular contract have and uh you can also see like the arguments what are the type of functions are they view functions are they write functions or what right so interfaces in uh stocket require this anotation which is Hash stet interface and uh they are uh declared in the form of traes so you have to use the keyword trait then we use I to denote that this is an interface right so we have I and then
this is an interface for the counter contract right that this is what we are writing so we have the straight called I counter contract and uh within this is basically what is the generic object that the strait is going to act upon right so this trait is basically telling that these are the functions that are part of my program and these functions are going to act on a particular type of variable got it so that in this case we are keeping it generic so when we implement this trait we can tell what type of variable is it upon which the functions of this trait will act so we give that type of variable in the
implementation so we have this trit and then we have a generic okay this can be whatever this can just be T also right I am used to just writing as T but because just to let you know that we are actually going to modify the contract State we have written it as T contract state so you might have commonly seen it in Rust and other programming languages is just T so it doesn't matter if it is T here it should be T here and it should be T here that's it it's a generic variable that we're representing within this trait we are telling that there are going to be two functions one function is called get counter so we just going to give the blueprint of the function there's no implementation of this function so we going to say that the function name is going to be get counter
right this is not taking any other arguments except self argument right that means it the self argument is required to access the contract state so self and it is it is going to take the snapshot it's not going to write so it's just going to read and with arrow uh whatever comes after is the return type so this is a type of variable that is going to return it's going to return a u32 and the second function is an increase counter which is reference like uh basically you're giving a reference so you're going going to be having a mutable access to this type of variable this also tells us clearly that this is a function which is going to aiming to write some so now we have the blueprint of this once we have the blueprint
within our contract we can Implement how we want what is the functionality of these functions so this is where we are saying that we are going to implement the counter contract right the functionality now and we say super because the interface is defined above uh we'll do this in the in the counter Workshop as well most part of the code is here already so uh we have this uh so we are what we are doing is the I counter contract is the interface and now we are saying that we want to modify the contract state so we are uh giving the contract State as the insert of the generics right instead of T we replace by contract Sate and we're going to implement the functionality that the blueprint gave us and the functionality has two functions get the counter which
just returns a u32 and increase the counter which is doing some you know operation so uh quickly this one I have already explained so these are called explicit interfaces where you define the interface and then you implement the interface so everything you're doing explicitly you're saying that here is the interface this is the blueprint and then you are going to implement the same interface with the functions that you have defined inside the blueprint okay so that's why they are called explicit expit Blueprints and then explicit interfaces and then you have the I already shared this ABI embed for enabling the functions to be called externally however you can also have something called as implicit interfaces these implicit interfaces can be of two types one is you can have an implicit
interface where you don't have the you see the interface itself is not written above so you're saying that generate this trade for me that is I'm writing the implementation you just generate a trade for it internally okay so this is more like a implicit interface now in this case we have mentioned that these functions should be external and we have to also mention the ABI so in order for these to be called externally there is another way to do the same implicit interface where we don't mention this AB per item nor do we mention these external v0 imagine that these three lines are gone okay the Orange Lines ABI per item exteral v0 exteral v 0 both are gone but we have the generate generate and we have some functions
that we are having inside an uh implementation these will be automatically private uh private functions and internal functions so you can't call them externally so if you want to have some internal functions that you just want to uh have uh you know U want to call from inside then also you can create an implementation and have a add the generate trade annotation to it so it will automatically implicitly generate a trade for you so these are the two differences um I'm also going to uh quickly run through events so of course in order to communicate with the world what is happening in your smart contract you want events right and for events you have to think of events as being having two types of structures okay the first is an enum called event that you have to
Define and you have to tag it as an event right so that's when the compiler knows that you are now defining some events for your contract you're going to Define some events for your contract so you say that I want to create events for my contract so you create an enum called event you tag it with event and then it has to derive this property that it's a stocket event so this stocket from which the event is being derived is already uh published as a part of the core uh like kybs and you are basically extracting uh deriving that event property for this particular enum right so drop is another property so that it can be deleted uh so it can be dropped that's the idea now
the first part of this is that now inside the enum you define uh you declare the name of the structs uh which are actually the events so you declare the events inside your enum so this is the name of the event and this is the type of the event so both are the same in our case and as you keep writing more and more events at the moment you'll keep them as the same name so now uh for this so you can Define multiple events inside this enum okay so for example ownership trans transferred ownership regained uh something trigger transfer triggered or something like that you can Define multiple events inside this enum now in order to Define what will be emitted as part of this events you have
to create a structure so the events themselves are always defined as trucks so these trucks also have to derive the event property from the St net Li so you're deriving both drop and event property for this particular struct and then you give the parameters uh that this particular event will emit so for example this ownership transferred event is going to emit a previous owner right of type contract address and the new owner of type contract address so who was the previous owner and who was the new owner now you might see a small ex additional thing called the key which is
basically to Index this event faster so when you are querying the blockchain and you want to do a quick search right so this Index this key will allow you to Index this event faster so that's the whole purpose of adding this key to it okay yeah so this is basically you have to remember that an event comes an event requires two things an enum called event within which you will define declare what are the different events that you want to have and each of these events are actually defined as strs within which you will write the parameters that you want to emit okay and um I think this is probably around my last uh slide or something before we go to handson um now the last thing that we're going to talk about is uh how do you call one
contract from another contract right so calling one contract from another contract uh you can do that using this concept called dispatchers so in uh stet in Cairo contracts you can dispatchers are automatically generated from interfaces so for example when you're writing this interface called ID data which which has two functions get data and set data right this is a blueprint of your contract right this there is automatically a dispatcher that is generated for it as ID data dispatcher so there are two dispatchers that are generated one is ID data dispatcher and a trait for it which is the ID dat dispatcher TR right so this is automatically generated from interfaces so we have to use these dispatchers to
be able to call the external contracts so in this case uh for example we have a contract cont called my contract which needs to call some um you know function within this ID data rate so think of this like there is another there's like another call contract right uh so what we can do is we are going to get the ID data dispatcher and the ID data dispatcher trait right of this particular interface that we need to import into our contract and the way we call it is like this so this is the AED v0 that means this uh function can be called externally right and we are taking two parameters the contract state
so we are not modifying the contract State and we are taking a data address which is the contract address of this particular contract right and what we are going to do is we going to call this ID data dispatcher with this particular contract contract address this will call this particular contract and give us the uh address for example so this will give us the this will give us the contract instance of this particular uh data contract and using this contract instance we can call the function within this contract so uh using a dispatcher the function is executing with the storage and context of the targeted contract right and then we have another type of dispatcher which I'm not going to go into which is the library dispatcher so you use this to call a
function in a stateless manner using the storage and context of the current contract so let's not worry about this for now we will work with this which is also going to be part of your homework so the main things that you have to remember the one main key thing you have to remember is whenever you're writing an interface there's going to be an automatic dispatcher that is generated for that interface you can directly call that particular contract which implements that interface as simple as that so this is how you call an external contract from within another contract okay now this uh components is is slightly new it's just like think of these more as like libraries or um you know key components of of uh for
modularity so the way components look it's very similar to the way a contract looks but components are for the purpose of bringing modularity so they can contain functions storage and events and they are more like modular add-ons that you can use in your contract so for example think about an ownable contract right it is something which is very commonly used in solidity like to check whether a particular contract address is actually owner or not so imagine that if you can publish that ownable contract as a component you can use that component within your contract and uh call certain functionalities so that's the whole
point of like components uh components become part of the contracts bite code so you basically use the components within your your contract and they become part of your bite code uh so you can publish components uh right and uh it can be implemented in multiple contracts so this um is a good example but it doesn't have how to use the component so I'm going to uh share my screen and show you a very quick example so I want to show the components example from here yeah okay I'm also going to share the link with you um we don't have to worry too much about it it's not part of our counter contract anyway but it's just good to know like that this modity uh you know uh idea exists so instead of
marking it as a stet contract you mark it as a stocket component You See It has very similar uh sort of vibe as your contract so it has the interface and then it has uh it's defined as a module and it has a storage this one has an event uh right uh so you see that this has an event and this is the struct that is the event itself defined as the struct and it has an implementation uh it has two implementations uh one is an embedded implementation and one is a uh uh implicit implementation and the way you use this component in a contract this is the piece that was missing in that screenshot which I want to share which is you have your contract and then
you kind of just take the implementation from the component right and uh this is the which component it had the uh this particular implementation and then it has this another internal implementation which was this one so you see there's one implementation there's another implementation we are taking both of these implementations over here right and we are just calling the functionality that's it so this is the way you can use the components so you can publish this as a component and then you use the implementation of this there is more Deep dive on the CYO book as well but uh we are just going through like sort of just reing through these Concepts so you are familiar that okay like this ex whatever you saw until now can be useful now that you start to
write the code the first and the foremost thing that I want you to do is I shared a GitHub Link at please uh go to that GitHub link will lead you here the GitHub repository for the counter Workshop please clone this repository onto your systems pleas so you can copy and then like let me go to my terminal okay some random stuff open okay so I would suggest that you kind of create a new directory for yourselves so let me actually do that I'm going to do bcam for9 so within bcam for 9 I'm going to this you don't need to Fork it you can just clone it because you're not going to submit any like PRS or something so
you don't need to Fork it okay and also we would need these installations already installed so Robert mentioned that he has already done the installation in the previous session so you should already have ASDF you should have scarb 2.6.4 uh you should have uh stocket Foundry uh 023.0 and uh the KIRO one extension for vs code so if you would like to use Docker as well you can use uh Docker so I'm going to do the without Docker version but everything that you're doing should also run within the docker as well however this repo already comes with the test cases so you would know whether the code that you wrote is
actually correct or not so this is going to be a very simple like follow along Workshop literally all the instructions that you need are here I'm just a mic for these instructions that is I'm just going to repeat these instructions that are already here and maybe talk a little bit about why we are doing what we are doing uh a major part of whatever you we are doing you have already seen how that code looks like on the slides right so now you have some sort of recall value that you want to get from there when we are solving these problems handson so that was the reason why we have slides we can try other uh sort of things as well later on but yeah so so let's go for the workshop so now uh I have my
terminal and I have this uh the GitHub opened as well and I'm just going to follow the instruction step by step okay the way we are going to do this is we are going to look at so the first step I'm going to do with you and then the next step onwards uh right what I'm going to do is I'm going to read out the step I'm going to give you some hints which are already there over here and then I'm going to tell you that hey I'm going to wait for you for a minute or two until you try to attempt to do the step yourself and if you fail or you're not sure how to attempt this step then I'm going to just come back to it after 2 minutes or so okay we're going to do it that way I'm going to let you attempt
uh the steps and then I'm going to get you into the so the next next as we keep going uh you will become faster and faster and the need for me to just attempt this itself will kind of go away that's the objective right so let's do the first step together okay so we're going to do we just copy uh the G checkout B step one which means that we are branching to a different branch okay so I'm going to clear here and I'm also after I Clon the repository I did CD counter Workshop okay so I'm inside this repository now and I'm just going to check out and move to the first step okay this is a branch which is our first step okay so let's see first what we have inside this
Branch so I'm going to open my code editor I have a V Code I'm also going to uh see the folders here you can see that there are some G folders never mind there's a tool versions which expect expects you to have a specific uh version of the different tool set that we have which is mentioned in the GitHub as well okay there's a read me of course and then you have a scripts folder and you have a dock compose for uh if you're doing it by Docker okay there is nothing else over here as of now we are at step one right and and then what I'm going to do is I'm going to open this in the code editor just in case I'm going to do this for all the steps uh to see just again to you know take a look and stuff we saw
the files right the tool versions that we need are stet Foundry 02 23.0 and Scar 2.6.4 okay so I'm hoping you all have this your many of you have raised your hands okay so now what is the goal of this particular step the goal of the step is we need to initialize the project structure within the Clone Repository by using the scar package manager and enable compilation of stocket contracts so there are multiple uh things to this requirement okay uh when we initialize the project with scar so the first thing that we need to do is initialize the project structure using scarve so scarve is a package manager which is used to manage your stocket
smart contracts it is used to actually manage Cairo uh individual Cairo programs as well as stet smart contracts for us we are now looking at St smart contracts so if you're familiar with rust then cargo is a package manager for rust similar to that scarb is your package manager for managing your stocket smart contracts skyro smart contracts okay and because it is by default a package manager for Cairo you have to enable the compilation of stocket contracts by adding some to the configuration of this package manager okay this is what this goal is it's asking us to achieve this go so what are the specific requirements specific requirements are when we initialize the
project with scarb we have to name the package as counter and we have to do it within the Clone repository okay so we have all the hints now we are within the Clone repository now let's see what it means to initialize a project with scar so how do you know what are the different things that scar can do you can just type scarve help okay uh we see that scar has different commands like we can add remove build uh check cash clean and all of that and then we come to init which is what we want to do because it's asking us to initialize but there is a catch to it we need to name the package as counter right so let's go to scar in it and ask for help so there is an
option called name that we can add which sets the resulting package name right and it defaults to the directory name remember that the directory name is counter Workshop but the instruction for us is to name the package as counter so let's do scarb in it hyphen hyphen name and counter okay we get some warning that the git ignore file already exists all right we are trying to initialize this so it says that get ignore exist I don't have to worry about it now it says it has created a package uh we have already opened our code editor so let's see what that means okay so now in our counter Workshop code editor we can see that few more folders
have been created we have a file called scar. tol that got created for us we have a source folder that got created initially we only had scripts and we had this readme and all of that tool versions We had so inside the source there is a default file called lip. CYO that has been created for us and this has the code of a Fibonacci series if you familiar with that this implements a Fibonacci program and there is a test case for this program so this already lip. Kyo has a default code and this Source folder has been created for us has been generated for us okay so far so good so we have gone through the first instruction so whenever you initialize a new project with Kyo with scarb you will
get a source folder with the lip. CYO which is the default file and it will have the pieces of code in it so you might have seen I think even starlings uses card so you might have seen that uh you you have different files and then there is a lip that encompasses all of them together and then you have a scar. tol and all of that okay uh the sc. toml is actually a configuration file which we will see now okay so it says that create a new Cairo file under the source directory named counter. CYO and add the following starting code okay so I copy the starting code now okay so this is the one that we're looking for under Source it's asking us to create a
counter. CYO and copy this code okay I have copied it now now in the lip. CYO file remove the code and Define the counter module so what we are going to do is we are going to remove this and we are going to say module counter that's it so whenever you define a new Cairo contract that you want to add inside your Source you can have multiple Cairo contracts here uh but the entry point for this to be built bu when scar builds it it looks for all of the files at lip.
CYO so if I just had counter. CYO separately and I didn't mention the counter module here and I still had the Fibonacci code it would just build that Fibonacci code it will not be able to find the counter contract so that's why the best practice when you write code is uh you can have separate files which are for your different Logics and then Define the modules in the lip. CYO so when carb is building uh it will be able to access these modules right it works the same when you are working with Cairo as well or stocket smart contracts written in Kyu okay so now we uh learned how to basically create a scar project uh how to create a new uh Cairo contract
uh within within our source and uh how to add that as a module within the lip. guide uh and now now this they have asked us that initialize the project structure and enable the compilation so let's try to build it now and see if this works okay I'm going to save this I've saved this and I'm going to try and build it okay so it builds it gives me a Target okay however there are some more things that we need to do in order to be able to get some type of like uh in order to be able to get a Chasm right to be able to create that assembly file that we can actually deploy so in order to do that you we can check out the
hints where we say that to enable stocket contract compilation we need to add a Target as the starnet contract we need to specify the Cairo version in the scar. teral right so let's go over here let's look at the scar. toml so we have to specify the stocket version under dependencies so we're going to say that we need version greater than 2.6.3 and we also need to provide a Target as the stocket contract so this is the way that this scar will be able to compile this particular contract uh this particular piece of code as a
stocket smart contract so we have to provide the target at stocket contract and then what will be the version of Cairo so we say that stocket greater than 2.6.3 is what we're looking for so we have two do greater than or equal to so we can check this with the scar version as well and so all of these instructions we have cleared that is check out the scar init command so this was the hint which you know I did it for you directly uh so that you get the flow with me for the first step so we have the scar init command scar init hyen a name package name and uh you can also refer to the cheat sheet for different type of scab commands you can also do a scab help as I did and then we need to
enable starnet contract compilation so we need to add the target as starnet contract which which I've added over here uh and uh we can specify the Cairo version in the scar. tol so this is the version that I have specified now again if I do scar build it should okay perfect so now that uh you can see that after I did the scar build this time it has created a starnet artifacts. Json which has the contract related artifacts right so at this point we don't have anything much because the code itself doesn't have much stuff but you can see that now after adding that dependency I'm able to get the artifacts related to the contract set otherwise it was just compiling the Kyo code as a
Sierra so with step two what I'm going to do is I'm just going to read this I'm going to switch the step two read the goal and give you some time to implement step two yourselves with the next step again uh you just need to copy the step command okay and uh I'm going to again uh paste this here okay so now we switch to the branch step two okay uh for step two let's quickly see uh what is the goal for step two the goal is to add sn4 as a dependency within your scab. toml okay now you know how to add dependencies on scab. toml uh to allow execution of tests with stocket Foundry so stocket Foundry is a framework which
helps you write tests for your starnet smart contracts right in Cairo the same programming language so we are going to add that particular SN Forge as a dependency within our scar. toml so the requirements for to complete this step is in your scar. declare the SN foror SCD package as your project dependency and enable casm contract class generation in your scar. toml Define a script named test to be able to run SN Forge test command and in your scar.
toml set your addition to Target 2023 01 and once you have completed these steps if you run scarb test this will be successful for you so how to do all of this you can find it all in the hints so when you are trying to add this SN Forge STD package you can find it from The stet Foundry documentation how you can add that package right and remember to specify the version of Foundry that the project currently uses that's tweak you have to make from the example that's given here then how do you add the script you have to add a script which is test pointing to SN Forge test for that you will find the
documentation in this other link and then the Edition 2023 is a type of configuration that targets a general version of chyo Prelude so what the Prelude is you can find out more about this but you don't have to go too much into it just make this change add all of this and you should run scard test it should be successful okay this is the step that you have to do I'm going to give you two minutes to do this okay so uh I have branched to step two and I'm going to do these same things as I I mentioned I would okay so I'm going to go to these so there is the dev dependency this is right here right this is what it asks you to add I'm going to add it as a Dev dependency
itself okay so I'm going to say here uh because we are using version 0.23 I just need to make that small change okay and then uh for the next step it says that I need to change the okay I'll do this one first need to change the addition so that is 2023 Z1 It also says actually that I need to enable Chasm contract class generation so I can do that under this target so I say kasm is equal to True right so it will generate kasm files now and uh the last one thing is Define a script name test so for this um you can check the scripts how do you
define scripts so let's scroll down so here it says scripts okay I'm going to take this I'm going to add scripts Define a script name test which should run SN for test this command Okay so I've saved my file specify the version okay so I have done this that the project specify the version of starnet Foundry so I've done this refer to this for doing it I also refer to the scripts how to add and then this Edition okay now I have to do scar test to check whether everything is correct or not so let me do that okay so now it says okay like it uh compiled it and then it just ran you know counter test saying that it works right so uh and then uh test the
SN Forge whether dependency is there or not it works okay so now if you go to your setup if you go to your folder you can see that there is a SN Foundry cache that got added because I added the SN Forge as a dependency right over here so it uh it is you can see that the dependency is coming from Foundry which is The stocket Foundry which is used for writing uh tests right so you see that there is a cache folder that got created for it and then in this step you will also notice that a new folder got added which is called tests within tests is where we have testore step. CYO so you can see that a test has been written
using SN Forge to test whether SN Forge has been installed correctly or not and because we passed this assertion we got a successful message on our terminal that yes your tests have passed so you see that this new folder what added in the step just to check whether the we have added the testing dependency correctly or not so let's go to step three and and again for step three I'm going to give you uh two minutes uh after step maybe I'll have to stop with step five I'll see I'll let's see okay let's go to step three and uh let's move to step three and see what step three requires us with step three we need to implement the Constructor function to initialize an input number and store a
variable named counter within the contract okay so this is easy peasy now uh for you all this should be easy uh just look at the counter contract okay you already have a storage struct defined you don't even have to Define it separately why because a bare minimum contract needs a storage right now as for the requirements you need to store a variable named counter and its type should be u32 okay simple the next is you need to implement the Constructor function that initializes the counter variable with the given input value now for this one you can take a reference from the documentation here from the hints there is on how to write
Constructor but now is where I'm hoping that your recall value kind of comes into picture that you already saw how a Constructor would look like it needs it's a function right and uh remember that if you are writing a value which is what it is asking you to do that initialize the counter you need to have a ref self as the first parameter and then you will give an input value that you need to write and you have to remember that it has to have a Constructor annotation okay so these are things we have already looked at in the slide so this should be very easy now to write this very quickly I'm going to give you one more minute for this and then I'll
start writing by myself okay so I'm in step three I've already opened my this one this has some weird kind of this Zoom thing keeps coming for me trying to bring it down okay nice so I'm going to write counter 232 I'll say Constructor okay function Constructor ref sells contract State because I want to modify that and then um I have to take some input right it has to be u32 and I say self dot the name of the variable counter and I have to write the new input into this perfect once I've completed I can run scar test
oh my God what have I done to get contract for name equal to count which file am I looking at it expects me to also enable Sierra check stored counter wait wait wait wait I would have made some variable mistake uh counter let see make sure stock Target is correctly defined this defin maybe I should do the dependencies above wow this is the magic of live coding have debug live okay let's see uh Target stet contract see if I am in the same yes I
am Constructor if let's see contact address fine okay let's move to the next step even if it didn't compile for me hopefully it has compiled and worked for you so uh so what what issue you having attention it says that for me it says that I haven't defined the target correctly it's failed to get the contract artifact for name is equal to cter did you name the smart contract with capital c yeah and what about the module like the in the lib Kyo is that it's correct only but the file name is counter. CYO right and that's the file name yeah yeah but it's not saved the file is not Sav I wonder if that has
maybe yeah maybe I not saved it that could be it they leave the Kyo file is not saved uh oh I didn't make any changes to it but I don't know no my ky counter. ky was not saved maybe I don't know okay because in the previous one also it needed the counter I mean it needed the LI so it found that and it did everything I guess it was supposed to do okay yay fun issues that we encountering okay so let's go to step four and in step four what we need to do is we need to now get to the more nitty-gritty things that is imp Implement an interface okay so we need to write an interface which will give us the blueprint of the contract and we are
going to do it in steps so for the first step which is step four we are going to write the interface with just the get counter function the get counter function should return the value of the stored counter variable within the contract so remember that get counter is not going to modify the contract State it's only going to read so the way you have to define the function is in such a way that it takes this snapshot right and you need to implement the interface also so you need to write the interface and you need to implement it so let's look at the requirements Implement an interface for a function named get counter which Returns the value of the counter variable the get counter
function must be within the contracts interface named I counter so you have to name the interface as I counter you have to write the get counter you have to define the get counter uh inside the interface and then you have to write an implementation which will implement this by just returning the value of the counter you can take a look at the hints but if you remember every interface is defined as a trait so you have to say trait I counter and then have a generic variable inside that you write your function body of your I mean blueprint of your function and put a starnet interface tag on top of it within your contract you have to impl implement this so that you can that implementation can also have external access so you have
already seen the blueprint of how this would look like and you can quickly code it out so I'm going to do step four now okay so first I will write a trait so in order to say that this is a staet interface I have to mark it as an annotation and my trait should be called I counter and I Define a generic object t to tell me that this trait will be modifying or Reading Writing to some type of variable right and the function that I have to Define is called get counter because I'm just going to read I'm not going to modify I'm going to take a snapshot of this T right whatever
that variable is and I have to return this counter so u32 now I'm going to implement this right so this is a trait I have to implement this trait so now to implement it uh the first thing I want to do is have it as a external I should be able to call the function externally so I have embeded this to be able to call it externally as version zero okay I say implementation I counter Im so this is a very standard way of writing implementation so I'm just going to follow that off now I'm going to write super because this particular trait is outside the scope of this module so I have to write super to be able to
access this I counter and then on what am I going to implement this trate I'm going to have a contract state which I can read or write from so now I need to implement the get counter function the function get underscore counter right again self and snapshot of the contract State because I'm not going to read anything and I'm going to return a u32 so in order to return I need to read the value of the counter so I'll do sells do counter do read and I'm not putting any semicolon at the end because the way the functions work the way return Works in these functions is that if you don't put
a semicolon this becomes the last statement of your your function and if you don't put a semicolon this automatically gets returned so the last value that you write over here will automatically get returned so similar to rust Okay so I'm going to save this let's see if there are any other requirements so to create a contract you will need to define a trade with a name the get counter function should only be able to read the state of the contract and not modify it okay let's check let me see it properly okay so once you have completed this your test should pass you can also once you once the class is done you can also take a look at what are the tests that you know um they have written what what are the tests that are written
and what is happening in the background what are we testing for small small things of course but what is happening now we're going to go into step five so in step five we are going to have within the same interface we have to write another function which is increase counter that increments the current value by one okay so this is easy peasy now uh it's getting easier because we are getting a hang of the language now right so within the same interface So within the same trade I'm going to write the increase cter okay and now I have to modify the value so I'm going to take a reference to that to this particular variable and I just need to increment by one so I don't have to have
any input okay so I'm going to add this to the implementation so I'm going to say self do counter. write but what do I need to write before writing I need to first read the variable value so I say read and then plus one because I just need to increment it so I'm not returning anything here so I can close the statement by putting a semicolon right so the execution ends here so I've added this increase counter which was ask for in the SE five and it should be within the contracts interface name I counter right so I've done the same I'm going to saving too many times okay so scar test and the test of pass okay okay so with step six what we are going to do
is we are going to implement an event remember that whenever we are writing events in Kiro as a s contract we have to have two parts to the event one is the enum called event which will Define the event itself and then the event is actually which will declare the event the event is defined as a struct okay so remember two parts so I'm going to go to uh step six now which is the event right step six okay I go to this and I say now I want an event so first thing I have to do is have this tag which is event okay and
then the event has to derive some traits as I mentioned it has to derive the drop trait that is it can be deleted and it should derive the stocket events trait event I say event all the time okay so this is how we know that this is an event okay we need to have these parameters and first we need to Define an enum called event now they have asked us to define a specific event so it is called counter increase okay that's the name of our event this is what it is checking for Implement an event named counter increased so I'm going to copy this name I'm going to go go back to my editor and I'm going to write okay so
this is the only event they've asked us to Define now I have to Define this event as a struct so for that I don't need this tag but I still need this tag this event needs to derive the trades so I'm going to put this tag this is the name of my event name of my struct and what should it emit what is the value that I should emit when defining the counter variable within the counter increase truct okay the event should emit the current value of counter variable every time the value is increased so what should I emit when should I emit both are here so I'm going to emit counter whose value is u32 you already know and we have been asked to
add a key so that the event is easier to index okay so I'm going to add the key here all right so now I have created this event now they are also asking me to emit the event in the increase counter function once the counter value has been incremented so have not shown you how to emit the event but you can just check it out here in the hint it's already there but it is very straightforward you use self. emit name of the event and then the value that you want to emit so let's go back so in the after the counter has been increased so self. emit name of our event is counter increase and the value we are emitting
is counter and the value of this variable is coming from self Dot counter do read you have to read the current value now right we wrote an updated value so we are reading that we're assigning it to whatever needs to be emitted and we are emitting this event so every time we increase the counter we will be able to emit this event okay saving okay so this is the step six and we have reached the main checkpoint uh which is we have done we have written a simple basic smart contract where we are able to get the counter value increment the counter value by one and emit whenever the counter value is increased so this is our first
checkpoint hey let me step a little bit in and uh let me show you how you actually can deploy the smart contract that we created so we worked uh for the first half for the first part and after that you can jump to the step 15 which basically it's from Step six after you finish step six and below here you can actually reach the check so you can uh go to the step 15 which is actually right down below here and here we have all the necessary information to deploy our smart contract on testnet so initially what you want to do first is actually check that your smart contract uh passes all the test So currently on
my end we are on step six we have our smart contract finished uh implementing the event um part this is how it looks looks like so we have the smart contract we have the interface built and then the contract itself with our storage our uh event enum our cont increase event The Constructor function and then the implementation of our uh interface right now I'm just running scarp test to make sure I pass all the tests uh within this step and now that we passed all the tests we are ready to deploy uh the first part so let me actually grab this uh command line we will switch branches to step 15 JS and now you're passing the
command in the terminal and then check out step 15s now in your project structure will'll notice uh a few additional things in the script folder we have this deploy TS and U TOS TS and then we do have a package Json and package lock Json but we'll get to that in a bit right so let's go back to step 15 the first thing that we'll have to do is install all the necessary dependency so with that you have to install with npm install to do that go into your terminal and write npm install and we manag to add all the dependency and you'll notice that um in your uh project structure node modules have been created good now for the next part we actually need to
have a wallet created so for those who do not have any wallet created we'll go through these steps and uh if you have a wallet created what you'll have to do is just to get your private key and your public key so to do this let's go to step one so we'll have to create a wallet on Stark net test net using either arund or Bravos extension so for me I'll in this example I'll use um arund so uh I'll just get my Brave extension I'll add this to my browser and the same thing can go for the Brows extension um you need to create a new wallet so for this uh you create a new wallet and uh there's some things that you press privacy policy agree you have to set up a strong password press
continue and then here you can choose either a smart account or a standard account now the smart account comes with additional features that uses the account abstraction that we talked about in the previous sessions but for the sake of this example I'll use a standard account but if you're interested into a more secured account with TFA and other features then uh you can investigate the smart accounts great now that I have finished I'll go to my wallet itself and we can see that we have already a wallet on the main net now in our case we'll have to switch to test net so we go to click here on Main net click to aoia and then we'll create a new address right and we'll create a standard account now
that I have my address created it's time to so I'll have to sa my seat phrase so in your uh please do save your seat phas make sure to have this in the safe location and don't share with anybody else now for our next step make sure to copy your address from here and then we'll have to request some funds in order to deploy a smart contract so here you'll either be able to use the faucet that we have or a breach that you can transfer from layer one to Layer Two we go to the Stark faet aolia We'll add our address here and then we'll request some e funds and make sure to pass the capture challenge I'll have to select
all the motorcycles and finally send the request you'll have to wait a few seconds here and once the pro the transaction has been verified and processed you should be able to receive some e funds on your wallet great our transaction has been successfully processed you can access your account and you'll be able to see that you have received some e funds as well now before going to the next step we'll have to deploy our wallet manually and to do this you can go to your account account you click the three buttons here and then you make sure to deploy the account and then this ensures that our account is deployed on test net great now we successfully deployed our wallet give it a few seconds until the transaction has been confirmed you can
also check this uh button where you can see all the transaction and you'll see account activation you can click on it and then you'll see that the transaction has been successful awesome now we're ready for the next step where we create an end file now going back our next process or our next step is actually to create n file in our project structure so to do this you come here on your uh vs code and in the parent folder you'll have to create an N file whenever you're working with n files make sure that you add uh this in your git ignore as we don't want to have our n file uploaded to GitHub because this uh contains sensitive information and anybody can
view it if the repository is public now for the next step we'll have to export a private key from our funded wallet into our environment file to do this you'll go to your Argent account click on your account click on the three dots and then click on export private key enter your password and then copy the private key Associated here make sure that you don't share this private key with anyone currently we're being on test net but still you'll have to follow good practices once you copied your private key then you have to create a variable in your n file called deployer private key and Then followed by your uh private key from your
wallet make sure to save the file next up we'll have to export the public key of the funded wallet into our environment file so I'll copy this here I'll copy the public key to do this you'll go to your Argent account you'll copy the public key which is associated with this and then you'll pass this in great now for the the next part we'll need an RPC endpoint whenever you want to communicate with the stocket network either main net or test net you will need an RPC endpoint in this example we'll use the blast API service but there are many other great Services out there now we'll copy this line here which is the RPC endpoint it's the public endpoint for sepolia testet
offered by blast API and we'll put it into our environment file now we'll save our environment file and go back to our steps as for the final part we'll have to run the script that we have provided in the deploy TS but initially if you just finish the first half of the workshop you'll have to change some parameters as you remember the first part if we go back to our smart contract in our Constructor function we just passed the value and the full exerise contains additional parameters in the Constructor function so on our first part we'll just have to modify this certain line which can be found in the
deploy DS let me show you you go to scripts deploy TS and inside here you will notice the Constructor const here we will remove these two lines as those are intended for the full exercise or the full workshop and we will modify this initial counter variable to our actual variable which is in our Constructor function and this is Val value so value has to coincide to the value that you have here if this has been named differently so for example increase counter then you would have to name the variable increase counter here as well great make sure to save this and now we're ready for the
final step the final step involves running npm run deploy now before running the NN run deployment a good practice is to first run scar clean to ensure that all our builds are cleaned in our Factory and then run scar build this will compile your contract from the beginning and make sure that we are on the latest changes now we're ready to deploy our smart contract to do this run mpm run deploy notice that our account has been successfully connected congratulation you have successfully deployed your first smart contract to actually check our smart contract on the Block Explorer make sure to grab this address copy and then you can go to
either Stark scan or Voyager to check the smart contract now make sure to switch to sepolia and same thing goes for the Voyager you switch to sepolia and please note that it may take a couple of minutes until the block Explorer will index your smart contract so if you deployed a couple of seconds ago and you pass the address you may not notice your contract right away you usually this involves that it takes a couple of minutes until this has been successfully indexed on Stark scan and Voyager so be a little bit patient and in a couple of minutes you should be able to see your contract now let's see actually what we created this is our
smart contract that we have created this smart contract has been built with the class version k 2 and we can actually check our functions or our public functions in the read right contract so we'll notice that we have the get counter so in this case our query this function and you notice that our default is D so to actually switch this to a readable format we'll put decimals and you'll notice that it's 100 is the actual number that we have passed in the deploy so you can see the value it's 100 in this point and now we have the right functions which basically are able to modify the state of the contract as you remember whenever you want to modify the state of the contract you have to pay a certain gas fee for that you have to
connect a wallet so we'll connect my arent X account we'll go to increase counter and then we'll write this and you'll notice that this is a transaction that will I will have to sign and I'll confirm this great give it a couple of seconds for this to be processed and then once ready we'll go to the RAB and we'll able to see if our get counter has been increased from 100 to 101 let's check that let's go to a read let's go to get counter and let's quate the function as you notice is it's not D anymore so we go to decimals and we'll see that's 101 congratulations you have successfully deployed the first part of the smart contract now as for homework you can continue the exercise and uh
finish the second part and then redeploy the smart contract again thank you and now back to you again so by now you're able to write a basic smart contract so you can take a quick look at the Smart contract as well uh we wrote the module first with the simple storage then we added the counter and the Constructor as well the Constructor is writing an initial value to this whatever we are sending while deploying the contract and then we have two functions that we have implemented get counter and increase counter so get counter is getting the current value of the counter and increase is incrementing by one and every time we're incrementing we are emitting an event called counter
increased and we are emitting the value of that counter so and for the implementation I mean we have written an interface which is been implemented so this is like a simple smart contract um you know all the steps now uh to uh write the smart contract and uh one of my small Pro tips for you like whenever you try to learn a new language is that follow the process of read write test spend a lot of time in the beginning reading different types of contracts like don't uh put too much stress on yourself like that you are not understanding the contract just read through lots of different Cairo contracts just look at the code that's why and when you look at something right
when you start writing it um the recall value will be there otherwise when you're starting to write programs in a new programming language uh you you won't know how to debug and where even the minutest of the things went wrong but if you read a lot of code right it's not an advice that somebody generally gives to read code but it work really well for me it works really well for me whenever I learn a new programming language so just blindly spend two three days reading from simplest to complex contracts and you'll find lot of smart contracts KIRO contracts online just read them right just read how the and familiarize yourself with the pattern of
this programming language once you're familiar with the pattern then start again writing small to complex smart contracts and then go for testing as to whether your logic is correct or not local testing and then go for deploying onchain and onchain testing so this should be the process that you should follow like this is a very effective uh method of uh learning and uh something very useful when it comes to like programming languages especially to understand what the pattern of a programming language so the last thing as we wrap up are the resources so you can see that there are you can use ASDF to install your dependencies scarb is of course super super important so make sure that you have that installed um
make sure that whenever you're working with scarb you're checking the versions of Scar and scarb also gives you the version uh of your Cairo itself so ensure that you're working on the most recent stable version cuz that's when you will be able to access the best features Foundry we also have Foundry toolkit for uh uh writing test cases writing tests uh and it's super cool so definitely start exploring that uh and then of course we have a an extension which is a vs code extension that helps uh you know increase the readability of your code itself for documentation we have the Cairo book which is all about Cairo so if you want to get started with skyro uh this is the best place to go at in stocket book you can find everything that you need to learn about stet the
different components of starnet the theory behind them as well as some practical examples on contracts you have The starnet Foundry uh tutorials where you can read about right from setting up to writing test cases different types of test cases you can find on The Foundry documentation and of course for the CLI you can find more information on the Starly book stocket by example um created by the Voyager team is again a brilliant resource where you'll find a lot of examples on different contracts uh for example cross contract calls or complexes calls all of this you can find in the stman by example book and then uh Cairo by example has a similar approach but for Cairo goodes
okay if you're a beginner definitely do starlings it's one of the most fun exercises and you will have a great time U you know it's very gamified so as you keep doing you kind of keep progressing to the next level so very very interesting again uh if you want to step after starlings you want to step into the intermediate level then you have node Guardians the quests on node Guardians are amazing uh just the uiux just the experience is uh really great and once you ready you can always start contributing to the open source repositories on only dust uh and um you know this is a good way to also make some money get some rewards on only d by contributing to the STA n open source projects thank you so much thanks for
joining us I I hope you enjoyed learning about Cairo and uh I hope that you're also able to complete the session and you took away a lot of learnings in terms of how Kyo smart contracts work and you are ready to write your uh first Kyo smart contract amazing looking forward to seeing all of you thank you