Writing Cairo Smart Contract on Starknet I
Web3Bridge·Wed, Oct 9, 2024, 12:00 AM
Transcript
so I'm sure you all can see my screen right okay thank you there all right before we start writing the code let's have some foreground and background to writing Kyro smart contract on stet so I'll be reading through one of the key applications of the Cairo language is writing smart contract for stet Network stack net is a permissionless decentralized network that leverages tax technology for scalability as a layer two scalability solution for ethereum stet aims to provide fast secure and low transaction costs stet are programs specifically designed to run within the stet OS the stet OS is a CYO program itself which means that any operation executed by the stet OS can be proven and succinctly verified smart contracts can assess stet persistent States through the OS enabling them to read or modify variables in stagnate State communicate with other contracts and interact seamlessly with the underlying layer one to start writing your Cairo smart contract you need to have installed SC so to even start writing anything CYO I'm sure you should have installed scab and get your installation ready so the difference after installing scab with your CYO program and your CYO smart contract is that you add this flag that you add this flag and this dependency all right so scab facilitates smart contract development for stet to enable this feature you need to make some configurations in your scab. CFI first after installing and creating a new scab project so scab new whatever in your scab. ml F you are to add this stet FL this taget depend depy to your list of dependencies if you have any and add this flag so next enable the stagnate contract compilation of the package by adding a Target the stet contract section by default this target will build a Ser contract class file which can be deployed on stet so remember the first class we had I explained um s to us so we can quickly refresh our memory on as to what s is can I say can I talk yes you can okay so Sarah is more like the language KY get compiled to it's like the subset of the something I can't remember the comped version of compar to on the lower level okay does anyone else want to try does anyone El can hear me yes can hear you I think SRA is the um language that Cairo is compiled to to ensure that it does not panic when it is in production or when it is um deployed as a smart contract like it's like a middle point between the Kyo language and then the Kyo Assembly Language okay cool but is here language I think it's like a stream of like commands because when I checked the s file I was just saying B codes something like bite codes hex sh okay okay you both are correct so s is the compiler that compiles it from CYO to cousin which is Cairo Assembly Language all right so if you omit to specify the target your package will compile but will not produce an output that you can use with stet below is a minimal sc. file required to compile a crate containing St contract so the normal um package the name of your project the version of the project then the dependency flag because this is a stet smart contract you need to add the stet flag as a dependency the stet um dependency and the version of stet that you are working with also because you want it to compile you want s you want it to compile to serial code you have to add this so remember was it you guys um okay I don't I don't think it's I don't think I don't think it you guys you see I would go over it again when we instantiate new project all right so this is setting up your file your your project to accept to start writing smart contracts that'll be accepted by stet so this is a general introduction of smart contract that we all know this is what you've been doing for the past four months so you should know what smart contracts are if you don't know what smart contracts are by this time I don't know I don't know what you did with your four months here all right CYO programs and stet contract what is the difference who can tell me the difference between CYO programs and stet contract you can just unmute your mic and speak what is the difference between contracts yeah go ahead okay um I think uh difference between Cairo program and St program is St smart contract is design to only run on stet OS while Kyro program can function as every other program and can be run on any other distance as long as you're using the the Kyo VM okay thank you very much AB all right so that's the difference all right so and then once you right a Kyo program for any K program to be executed it needs to be a main function for the Cairo program to get executed just like writing rust or what program needs a mean is it c a c right A C programming language that needs a main function and Java and Java okay cool so they need a main function for any other functions to be executed in the program yes so when once you're writing a CYO program it will require a main function but once you're writing a Cairo stet smart contract you do not need a main function to implement execute those um the file is a different ball game Al together so main is only for is only found in Cairo programs anatomy of a simple smart contract so this is a um a smart contract and it's a storage smart contract now okay I think let me just read this before I make do my explanations this is a a contract you can see the flag stet interface it has a trait of I simple storage and a generic type and it has two functions or what do you call this without the implementations what are they called what interface okay yeah but I'm referring to the function without the implementation once you see a function like this right without the implementation what does it what is it called an inter fun it's called an interface function signature who said that function signature okay who said is an interface I did okay but do you know what interfaces are yes I do after I his response I figured I was wrong why why do you think you are wrong um because you said function like the Declaration without implementation um the interface has to be like the like everything put together so when everything is put together in that tra that's Mak it an interface yeah that's awesome that you figured it out nice nice yeah so this is the function signature because doesn't have the implementation but it carries the entire um signature of that function and they are both wrapped up in this street so seeing something like this you should understand that this is referring to an interface right here you have the flag stet contract and in this flag you have a mode a Mode called simple storage in this simple storage you have another flag called storage sorry yes you can ask your question was someone trying to ask a question all right so you have a mode simple storage you need another FL code storage and under this flag we have a stru called storage and this storage has a a variable called stored data and stored data is a unit two8 outside we have another flag called ABI and bed AI embed has an implementation called simp storage of super high simple storage so this implementation means it is implementing this trait called I simple storage calling the first item set and the implementation for set and get with implementation for get so this is a very very simple smart contract all right what is this contract contracts are defined by encapsulating state and logic within a modu annotated with the stagnate contract attribute the state is defined within the storage struct and it's always initialized empty here our stru contains a single field called stored data of type un 128 indicating that our contract can store any number between 0 and 2^ 28 minus 1 the logic is defined by functions that interact with the state here our contract defines and publicly exposes the functions set and get that can be used to modify or retrieve the value of the stored variable you can think of it as a single slot in a database that you can query and modify by calling functions of the code that manages the database so hope we all understand the the use of stru in your smart contract I think let me go let me let me start from there so what is struck guys I feel it's the same use case for solidity just gives you like a [Music] structure yeah okay structure for your data type is that all yeah just gives you like a logic for implementation you can also use it in traits when you want to um work on traits for your for your contract so I just see as same thing just get you like a structure let say you want to implement um like a book book this so you just need like instuctor to put in data for the books the book that the person bought the person's name so for each person now each person that comes to your Bookshop you have like a stru that collect their data then you can use it in your trip CU I saw them using that in Tri okay does anyone else want to explain to me what St is guys you've been you've been writing this for the past four months or three months and some of you have been writing it way before you came here can I can I come in come in please okay um so basically um something similar to uh struct is um the way we have object in JavaScript so struct in solidity for instance is just a in Ciro is a generic type actually so it's used to group um some um dat that's that's related so to group some data that are related we make use of struct okay is that all like is that all so after grouping this data what happened we also use we use it actually we use it to store that are in a kind of key value pair yes so where is the data stored the data actually is stored is is is attached to the Keys okay nice okay uh so struct is according to you guys is a structure for for data types is a structure for to arrange data types that are similar or to arrange items that are similar or refer to a particular field but what is the use of struct asides just arrangement of data aside it being a complex data types that is formed by other um data types what happens to a struct what happens to the information in the struct once that smart contract is deployed what does the TRU do okay so most of us don't don't really bother we don't really care about about it we just want to write our smart contract and deploy to the blockchain yeah we are not really bothered about that right cool but you should understand that this contract you are writing is going to be deployed and what execute smart contracts let's make it interactive this is something these are things you know don't don't don't feel scared of few um I I'm going to swallow you these are things you should know by now so just say it what is AQ smart contract the compiler EV the evm that's for for yeah yeah so the evm executes the smart contract so that means what does that mean that means the the Buy code right that the even understands for that smart contract is stored there right yes yes okay cool now we have stru and you said struct is to give structure right so once this structure has been given once this input are entered what happens next where does this input go to what happens once this structure is given it gets to oh boy so you have a struct you want to get a structure for something and okay takes different types of data and you on when this function that executes this truck is called it will take this this this this and this from this person right then pass it as the values to the various um um parameters in the struct right so once these values now are passed maybe age name and stuff is passed what happens to these values to the state thank you they get St to the state right yes whool it get St to the state that means the Str doesn't just give you the structure for your to write your implementation in your smart contract it doesn't just stop there once these values are instantiated initiated or whatever you want to executed or or implemented or whatever you want to use English you want to use once there are values these values will automatically get stored to State and getting stored to State means there is a slot have you guys done something called slot parking or have you tried to build a smart contract and then you see storage too deep or something too deep stack too deep errow stack too deep you didn't you don't you know that the struct that is giving you that error you're getting that error from something from your struct or you didn't research to understand it properly and that is why in arranging your stru you have to arrange your struct properly if you you're you're calling age and you're using unit 256 that is not logical because there's nobody that lives up to the number the last number in 26 so anytime you instantiating age it is proper for you to um to initiate it as a unit8 right what is the last value in a unit8 you have the analogy that someone will live to that to that age or at most that age or you in 16 depending 16 is even very large so say you in eight then maybe something else you have to allocate spaces according to that particular thing why because you are you have to consider the machine you have to consider the slots the space in memory where this information you are storing is going to stay is going to a slot stores one variable and a slot only has the space to store up to 32 bits and if it is not full the next item in your struct is supposed to take up the next it's supposed to take up that space so if from the beginning I assigning age to be Ur 256 that is already 2 bits it's age is already taken up a whole slot in the memory and then the next item you put 256 256 you 16 and stuff it will take up in the way it will save in the memory you know that that's the way you wrote it in your St is the same way it will get executed right one by one it it is not smart enough to look through it and and gather all the UN a in one place to put them in one slot to save space and then move all 16 or whatever or join un8 16 un this to form the 32 bit and save them in one of the slots I want you to understand what is going on behind the scene when you are creating a struct so once you you you you say when you say you are creating a structure yes it is also for implementation and also for storing these values to State and once you're storing these values to State you should remember that it is going to be stored in a VN they use an allocated memory space for these values to be stored and in this allocated space there is like a divide it is divided into slots that what call slot pking right it is divided into slots and each of these values or information I stored in each of these slots so if you have a unit 8 you have a unit 16 in your struct you have to rearrange it so you have your unit8 first unit 16 next and stuff like that so that the first the first two or three variables should form 32 bits the three of them will be in one slot and then if there's a un 256 that U 256 I um variable should be towards the end of your struct so to stop that stack to deep errors you get you have to rearrange the order of your struct so that you can conserve space so why am I telling you why am I asking you this and telling you this I want you guys to really understand go back and reflect and research understand what is actually going on behind the scene because in Cairo you are it is more like you are almost closer to the machine than in solidity that just gives you has just affected almost everything for you okay but you understand where I'm going to and do you do you now understand what happens at the end in the stru the full life cycle of data in a struck do you get now yes yes I do okay so Victoria yes yeah so so I want you to understand it well you know you're public speaker don't go for my hand B all right um let's come back here so let me take this again so you get what I'm trying to say the state is defined within the storage struct and is always initialized empty here our struct contains a single field called stored data of type unit 1 to8 indicating that our contract can store any number between 0 and 2^ 128 minus one so that automatically means if you are storing any number higher than that there supposed to be an error right the compiler is supposed to throw an error because you are going overboard the logic is the defined by functions that interact with the states here our contract defines and publicly exposes the function set and get that can be used to modify or retrieve the value of the stored variable you can think of it as a single slot in a database that you can query and modify by calling functions of the code that manages the database so after my explanation of the struct and the SL do you now now to some point understand what this part is actually talking about talking about the slots the storage and stuff yes yes yeah it makes sense to me now okay cool Co cool what about you Benjamin Abraham KY the rest guys in the class in the call yeah yeah benjam you get yeah yes ma'am yes I understand what you've been explaining okay cool cool cool all right so the interface sorry guys if I'm slow we're supposed to start writing code but I really want us to understand what we are doing properly so you don't just write medal code just because you know CYO syntax but you write code based on you understand what the VM is you know it's a CPU a virtual CPU and you know it uses um the same machine language and that is why the compiler is doing the work and then it's um it's confile down to machine code and it is stored there and it has a space and it's allocated um space to every item in the smart contract every variable in the smart contract stored in those slots that have been allocated so when you are writing your code you will not just write any out code just to make sure it is working as stuff you will write code understanding economics at least to some little part understanding the computer understanding the VM and the best practices for writing the code please that is why I'm really taking my time to explain this to you so in case you you feel it's boring I'm sorry about that I just want you guys to understand the backround the the back end of things before you start writing your code properly all right so interfaces okay interfaces represent the blueprint of the contract they Define the functions that the contract exposes to the outside world in Cairo they are defined by annotating a trait um guys please give me a minute e okay guys please just give me two minute I just want to pick up a delivery outside can you hear me yes yes okay thank e e okay sorry about that so so sorry about that I'm back okay hope you can see my screen yes okay so I was talking about interfaces interface represent the blueprint of the contract they Define the functions that the contract exposes to the outside world so we all know what interface is all contract interfaces use a generic type for the self parameter representing the contract State we choose to name this generic parameter T contract state in our interface but this is not enforced and any name can be chosen in our interface note the generic type t state of the self argument which is passed by reference to the set function seeing the self argument okay note that note the generic type T contrast state of the self argument which is passed by reference to the self set function this this is a generic type what does this mean it means this is a contract you referring to the state the contract state that means the state of this particular smart contract this whatever is inside here must giving you must be giving you values or giving you access to the state of this current contract wherever this interface will be called so that is what this means now it is saying here um that it is passed to self as a reference now in this once you are setting setting is a right function why is it a right function it is a right function because you are changing the state whatever you pass in here is going to update the state from what the value of the current state is or update the state meaning the state has not been initialized with anything yet it is empty and then whatever you set here will automatically be send to state so it is a right function that is why it takes a reference it is referencing this contract state it is referencing the contrast so anytime you see this reference remember that we are referring to a right for function we are referring to something that is going to change the state of our contract and when you see just self the get function it means it is giving you a snapshot of the current state of your contract so you are just reading you are not updating or writing to or instantiating a new DES you're just reading so for reading it is just ref is just referring to self but for writing you have to reference the self and make the updates make the change before it will get reflected so this self is just the snapshot of the current state it's just returning the current information in the state of this smart contract while this Returns the current information of the state smart contract and gives you the ability to update that information in the states okay I just hope we are understanding this so where was I okay here um seeing the self argument passed in a contra function tells us that this function can assess the state of the contract the ref modifier imp implies that self may be modified meaning that the storage variables of the contract may be modified inside the set function on the other hand the get function takes a snapshot of T contrast state which immediately tells us that it does not modify the states and indeed the compiler will complain if we try to modify storage inside the G function so by by leveraging the tra and implementation mechm from Cairo we can make sure that the actual implementation of the contract matches its inter interface so we all understand what is going on here right yes okay cool is it just em Manuel that is following no ma okay I'm here so do you understand going on yes I do okay Daniel yeah I have a question okay cool okay um from the definition of interface you said um it declares our function that we want the outside world to see from the contract yes so if let's say we have a smart contract and we are writing a private function if we don't uh decate in the interface will this still work as is should or we have a private function a private function yes ma'am the private function is private to that contract alone even if the contract is inherited the children cannot even in private function only within that function that contract sorry so you cannot you cannot add the private function to an interface okay okay yeah yeah yeah because interface is is um is actually um giving you the concept of inheritance but controlled inheritance where you inherit just what you want just what you need right all right thank you not the en yeah yeah yeah you're welcome Daniel Daniel Joseph okay Victoria ask your question okay so is it like in CYO does the same public external and private also apply for interface because solidity you have to do external for the other cult see yes as long as it's in the interface right it has to be external is the same concept of smart contract everywhere the only difference is that because of the language the Lang this language is more closer than solidity that is more high level so just a the the language syntax that would change but it's the same background knowledge of a smart contracts it applies every year that makes sense thank you you're welcome Daniel Joseph is Daniel Joseph in this class yes I am I'm in Noy place that's why oh if you a noisy place can you hear me yes I'm using my [Laughter] earpiece um ky ky yes ma' yeah so do you understand yes Ma I do thank you so much okay Emmanuel okay okay what what about the ladies Mary and IG are you guys on the call I really know everyone by name are you with us okay at least most of us here understand what is going on so yeah I'll proceed um Victoria so here when you are implementing the interfaces you have to add this flag before it was exteral flag that was here it has been changed to AI embed blah blah blah so what does what does this do it makes sure that every function found this implementation is made external that's what it does so users can access it okay so let's let's proceed so we can start writing code some almost five oh let me take this public functions defined in an implementation Block in the context of Stack net a public function is a function that is exposed to the outside world a public function can be called by anyone either from outside a contract or from within the contract itself in the example above set and get are public functions what we call an external function is a public function that can be directly invoked through a stocket transaction and that can mutate the state of the contract set is an external function because it can be called by anyone and it can mutate the state that mean change the state of the contract a view function is a public function that is typically read only and cannot mutate the state of the contract however this limitation is only enforced by the compiler and not by stet itself so we discuss the Implement implications of this in a later section get is a view view function set is an external function that mean it is public and has the ability to change states to change the state of the smart contract now um okay since the contract interface is defined as this in order to match the interface the public functions of the contract must be defined in an implementation of this trats which allows us to make sure that the implementation of the contract matches its interface so what this means is that in this implementation block here any function you pass in here must have been the function signature must have been called in the trait if you try passing in any function here that wasn't specified in the trait it is not going to compile it will return an error if you have three functions here you have function set function get and you have function update and you only write function set and function get in this implementation your code will not compile because everything in this trait this is an implementation of this trait so it has to execute Implement every function found in this trait okay however simply defining the functions in an implementation block is not enough the implementation block must be annotated with the ABI embed v0 attribute this attribute exposes the functions defined in this impl implementation to the outside world forget to add it and your functions will not be callable from the outside all functions defined in a block marked as this AI embed are consequently public functions because the simple story contract is defined as a module we need to access the interface defined in the parent module we can either bring it to the current scope with the use keyword or refer to it directly using super so this is what it means when we Define the trait if you can see in this contract this trait is outside this module so to be able to assess this Strait you have to import it into this module and to import it into the module you can either use the use keyword or use this super flag super then double colum and then call the name of the trait why because it is just an immediate parent it is in the same file so you can use super to call it and you can use the use keyword to call it and whatever you you save it at the end you just when you say Implement simple storage of whatever is the last item you saved it here you just call it you don't need to go super with the colon any longer so that is what that part is trying to explain when writing implementation of an interface the self parameter in the trait method must be of type contract States please take note and understand this thing clearly don't confuse it when writing the implementation of an interface so this is not referring to the trait now it is referring to the Implement part in the module when you implementing that trait the self parameter in the trait method must be of typ contract State remember remember in the trait you wrote it as T contrast state right yes so you wrote it as T contrast State now in the implementation you remove the T you are now implementing it it is no longer um generic you are now implementing it so you removing the T from it and just calling the contract state that is what this place is talking about so the contract State type is generated by the compiler and gives access to the storage variables defined in the storage struct additionally contrast State gives us the ability to emit events the name Contra state is not surprising as it's a representation of the contract state which is what we think of Self in the contract interface trait when self is a snapshot of the contract state only read access is allowed and emitting events is not possible so you understand what this place is talking about so when we are um okay here additionally contrast gives us the ability to emit events but when it is a snapshot of contrast states only read access is allowed and a meting event is not possible so with this do you know that I've been working with event and I've not noticed this so with this it means that you can only emit events when you are changing states but once you're getting the the snapshot of the state you won't be able to emit event well we're going to try it and see all right so to assess and modify the contast states now that means we are now implementing the functions the set and get functions two methods are commonly used to assess or modify state of a contract read which Returns the value of the storage variable this method is called on the variable itself and does not take any argument self. St data.
read then write which allows to write a new value in a storage slot this method is also called on the variable itself and takes one argument which is a value to be written note that right may take more than one argument depending on the type of the storage variable for example writing on a mapping requires two arguments the key and the value to be written just like like this self do St data write then passing the argument you want to write into the Maring here or into the storage here all right so that is the overview that is the anatomy of a smart contract do we have any question so uh if I you correctly here so if I want to write interfaces I have to use staits for the interface can I use trait without um like interface like I just want to write normal traits instead of using interface you just want to write normal trait this trait now can it be only use on interfaces yeah what that is what trait is majorly so if I want to declare State I must put that um what did they call it that they stet inter I have put at the top WR I can't write like just straight up like that so I have to use yeah like I want to use trits like normally inside my code okay yes no you can work with trait so you mean something like your typescript right how you implement a tra yeah yeah you can Implement your traits like that but I really haven't done anything like that I only did that I think once and that was for a normal Cairo program and I think Ross also yeah but for a smart contract if you are writing a smart contract you cannot just Implement trait trait is an interface the trait is actually the interface so just like your solidity when you want to write in an interface of erc2 you put I erc2 in this one it is the trait in this um in Cairo the smart contract it is trait that you use to um Define the function signatures that you want to be implemented this makes sense thank you I understand you're welcome okay any other question the guys ask question now what is going on are coming not yet time the questions are what when we start doing the Practical all right so everyone is clear like it is very very clear to us what I'm trying to explain right yes yes yes it's clear okay all right cool so having explained that my next STS okay so that is the anatomy of a startet smart contract here is building a St smart contract so um at the anatomy it explains a very very simple stack smart contract so understanding that gives you the foundation you need to to build upon when writing your stack smart contract no matter how complex it will be starting from there gives you the um foundation and understanding it gives you more clarity when building your smart contract so in building start smart contract um can I go through this okay I can go through it for start what is time okay all right so in this session we will be taking a deeper look at the component of the smart contract step by step when we discuss interfaces we specified the difference between the two types of public functions IE external functions and view functions and we mentioned how to interact with the storage of a contract at this point you should have multiple questions that come to mind how can I store more complex data types how do I Define internal SL private functions how can I emit events how can I index them is there a way to reduce the boiler plates H luckily we be answering all these questions in this chapter considering this smart contract so this is a full smart contract the reference smart contract for this chapter and let's just go through it to understand what it's doing now in the previous one it just gave us a foundation of a smart contract but in the reality when you are writing a St smart contract you'll start with this flag on top your file so use stack net contract address before you go to your interface flag where you put your trait rep public trait the name and this one takes three functions Stone name get name and get owner Stone name is a right function because and it takes in the parameter of name as a fil 252 um we've done data types right you guys have done data types in CYO right yes yes yes yes okay so it t name as a f 252 it takes registration type registration type is a name registry um type so this name registry should be a complex data type so we are going to check what what this data type is um sorry we have function get name it is just a snapshot of contract states to get the name you pass in the address address is a type of contract address and then seeing this it means that this function is meant to return it's meant to return a 252 that means it's meant to return the name and the get owner is a it's just a snapshot of the contrast State and returns from the name registry testing so either this is a struct probably this is a struct so name registry person and here it is returning registration type from name registering so when I say when you have this colon what it means is that you trying to assess a function that is in another implementation block right yes yes yes name mod exactly so it is in another block from the trait this is not here so to assess this tra here you have to use super dot this so to assess anything from here you be call the name of the module and the name of the of the item you are trying to access like this name of the module and this so I feel this is either a struct I'm not sure is a function but let's go through with it okay so this is the module name registry it is using stet contract address get color address Storage storage access storage based access address it calls the stru flag storage flag need stru storage and this TRU Story takes in the following field names name is a mapping of contract address to F 252 owner is a person so I feel this person is a data type so it is either a structor something else registration type is a marking of contract address to registration type so this registration type to is also a either a struct it should be a struct then total names total names is a unit 128 so this is the information that will be stored to storage and it is emitting an event to emit this event you need this flag called the Drive drop and the stet event so to emit an event use an enom to specify the event stored name is a data type of stored name now this thir name would have to be a struct so after specifying the event they gave us the event and the data type in the enum now we have to implement this data type called St and to implement this we use a struct also mind you you have to still call this plag derive drop stet event well when you call this TR stor name you have to pass the key flag that serves like an index thank you so taking in the user the contract address of the user and the name of the user and if you have um different events if you want to emit more than one event this en on event would have all the different event you want to emit so stud name will be stud name maybe WR will be right read will be read then the way you implemented the struct for the St name you will implement this same thing for the different events and the various parameters you want the event to emit now also note that this struct stor name is not a storage struct this struct has the storage flag this is a storage struct so everything here is either writing to or reading from the states okay any other thing you define outside that is important that is needed you have to make sure you call it inside this storage to be inclusive here so the things you cannot Implement here that he want to do the computation outside the storage they'll be done outside the storage but then their value will be stored here finally so we have stored name stor name is the event here we have theive drop said start next store and we are calling a struct called person he passing the address and the name now we couldn't do this inside here because you don't want to you want to remove most of the implementation oh yeah is it implementation I'm trying to say or computation or whatever from here and also because we are trying to instantiate this as a mapping Legacy map only works in this story struct you can't call Legacy map outside so since Legacy map is an is a what do you call it um is a mapping that contains a key and a value you can just do it this way where you have a stru that has a key and a value and then you pass it here so whenever you call owner it will call person and return person to you here is an Inon still passing the flag derive drop said stet stop okay this is for the registration type either it is a finite registration or an infinite registration and then it is called here for registration type so once you pass in the person's address you should see the registration type for the person so all these extra struct inms or whatever help you to to move most of the computations and complex stuff from the storage you do them outside and finally pass the values here okay so hope we are good um next Constructor once you have a Constructor in your code you will have you have to pass the Constructor flag passing the Constructor flag makes it know that this function you are calling or implementing is the Constructor function so this Constructor takes in is a reference Constructor normally all all Constructors are reference now they are right functions because the state is actually is always initialized as empty is a Constructor that P the first inputs or the first values to state so the Constructor references itself and then takes in the owner before you can deploy it so to to instantiate this you have to first call Self dot names do right self. names. WR so know that you anything in this Constructor majorly is implemented from this storage struct so it is only things from the storage truck that you can easily call like the self. names. WR so we call this names is a mapping so it takes in two key and value key contract address value fi 252 so once we call names.
WR it is the key the owner dot address and then the value is owner. name remember owner right is a person struct and it has address and name so to get the address you just say owner. address and owner do name then self. total names. WR you pass in one because you are instantiating it now then self owner.
WR owner so what this means is you are instantiating this passing this owner as the parameter to instantiate this instruct this Constructor owner takes in two Fields two inputs so whatever you rewrite in the first input of owner it will take it as the first item here and whatever you write in the second second item here push this ones to names so in this struct names now have one person in it then s total names WR one it will come here total names instead of it being zero will now be one then self. owner. WR this owner here anything you pass into owner will be passed here so you've just instantiated the owner as a person so you have passed um um this thing value to address and to name for this particular owner so anytime you pass the address of this owner are supposed to get the information of this person all right so instead let me not confuse you guys too much this is what the Constructor does it instantiates the values in the struct now we are going into the implementation of the trait because the store name the get name name and the get owner so Stone name is a reference to self now if you can remember it had T contrast state in the trait now in the implementation you have to get rid of the T name is a f 252 and registration type is an Ino called registration type now to instantiate this you say let color be equal to get color address and then self do store name you pass in the color uh what is going on here it is calling itself here you passing the color passing the name and the registration type so what happens next I think store name is an internal function like a private function okay unless there's a private function here that's it oh wait oh okay underscore I just saw it okay so it is self doore store uncore name I thought it was this one all right and then the function get name get name just self. names. read address whatever contct address you pass here it will go to these names you know names is a mapping it will pass the address here if there's any address like this in the mapping it will return the name for you so self the names read Returns the name of the address you passed in then function get owner is to return a person's so it will return self.
owner. read so who do you think what do you think is going to be the output here I'm be sure if you are following me so it's it's going to return the person stru so the name and and guys address the name and the address name and the address who which name and address is he going to call it for the G function is the name and the owner of the person that deployed the contract at least or the name of the the name and the address of the person that actually passed their name during the deployment as one of the Constructor arguments okay thank you very much I just wanted to be sure you are following all right said the owner the read is going to return this person here so whoever is here is who will be returned here all right stand alone function this is an external function function get Contract name mind you this is outside the module get Contract name so just the name of the contract so you know this one you don't need to do too much work for it this is the name of the contract you already know the name it is not going to change so it's it's it just they just called it name registry is the name of contract okay now this is a private um yeah a private function internal function now with internal function we have something called generate trait when you pass this flag and you call generate trait you you know what this external tra flag does right it makes this function external um this generate rate what it does is any any um function you call you implement here because this is an implementation of internal functions any function you call here the generate trait behind the scene will generate the trait for it so you don't need to regenerate the trait for this so whatever name you give this implementation just know that the trait will be the same name plus trait so we call this in internal functions so the trait name will be internal functions straight automatically generate tra will generate the trait for this private function and what do you think it will generate even though you are not seeing it on the contract just looking at this and and with the idea with the whole story I've been telling you about considering the VM considering the compilation everything that happen what do you think will be generated here during compile time as a trait for this the function signature for store name please um I don't want Benjamin to talk again sorry I don't Benjamin Vicki or Emmanuel to speak again or Abraham this fall I don't want you to speak again sorry I want another person once this once this is compiled what traits will be generated for this implementation emuel David D KY okay Steve one of you should answer this question what tra will be generated here where are you getting where are you getting address function from where is get address first are you trying to say this one get owner stage address is this what you mean this is not part of our implementation if this is what you are referring to and stone is not the way the trait is going to return it judging by how the trait is being formed so yes you halfway there but this is not fully correct complete it K me what is going on a hello Mom MH yes sorry I didn't get the question so I said looking at this implementation right the generate tra would automatically generate trait for this what you all right sorry I'm listening this yeah so I'm saying once the trait is generated for internal functions what would the trait look like here we are implementing the trait okay so what would this internal function Strait be contract [Music] address wow so you're asking someone for answer amazing all right um D video are so closed they just one thing out you've gotten everything but one thing is off one thing is not correct just one thing if anybody knows what that in is please speak up anybody can speak now all right um he made mention of the contract state it should have been a generic type instead of the actual contract St thank you very much so what was it supposed to change there so what is this supposed to change here to make it a generary St okay sorry the contrasted today we do you get well this is cool I'm happy people are getting so here where you put ref self in the trait it will be T contrast state it is in the implementation that you just call it um contrast State okay cool nice we are following all right so this is the implementation of the internal functions trait and it's a stone name and it is the cont address P 252 the name and registration type then what does it do with it once it get it it create a variable total names and say total name is equal to self total names do read you know total names now at this point our total name is one right so that you here when we deploy the this contract in the Constructor we set total name to be one right you remember right so we have something in the total name so now we want to add another information to the struct we will first read the what is in the struct the total name 10 self the names. WR user and name user will be this contract address name will be this F 252 then self the registration type. WR still pass the user contract address and pass the registration type that the user selected then self. total names.
write we read the previous number of total names and add one to it so that it gets updated so it will read what total name is currently then add one to it so at this point the total name will be two then self. emit so now we want to emit the event called stor name and Stor name has user and name in the struct so we pass the user address and we pass the username so this implementation has been done in this internal function and then we can call it here self. stame we passing the color here it is supposed to be user right user is a coner address and our user we are referring to is the color so in solidity in Cairo get color address is similar to MSG do sender so whoever whatever address is calling this function is the address we want to um be saved here as color address as um user to this person address and the person will pass in the name and then the registration type will be passed in and then this St name function will be implemented Okay so that is the work of the stone name and the work of the internal function is to get the implementation of this Stone name so that it does the implementation as an internal function and then passes this to the public function then there's also a free function and this function doesn't have any flag attached to it so without any flag attached to it it might not be it will not be accessible to the public but it will be it can be called within the contract so get owner storage address is reading the snapshot of the state and it's returning a storage based address and passing calling self. owner do address okay so own is a person so it's getting the address of Thea so start B address was imported from Storage access from stocket Okay cool so they write in the storage access to access the storage there's a storage based address so I think what is going on here I'm not really sure what do you guys think is going on there um Vick you can speak okay so just to be clear this generates traits so that means you don't need to actually have that trait imately you do the implementation to generate the trait for you yes for only internal functions only internal function yes oh I don't think I get like only internal functions if it's a if is a function you want to expose you need to generate the traits and then the implementation will be the functions in that trait but is an internal function that you are not exposing so everything you implement here generate trait will generate a trait for it but if it's like like an external you know these functions um are external right they are public you need to have generated the trait you have to generate the trait for these you cannot just use generate trait for public functions generate trait flag only works with internal functions wait so if I'm just using it internally that's in only my contract why do I need the trait the trait is more like like I said is the interface for your contract so you can't you really can't do anything within your contract or yeah anything within your contract without an interface there has to be a structure as to how that function will be defined or called because um I'm not so sure of this but everything at the back end works with function signatures and that is what is checking the correctness of your implementation so if your implementation is not not following the the correct um function signature that has been defined it will return an error because it's expecting a specific type so for the interface to to work for your implementations to work it needs an interface the interface defines the structure of all the functions that will be called in your smart cont and the and then will be implemented later on so for this one you don't need to Define it but if you want to Define it fine but there's already a predefined method that is stored in this flag that helps you to Define your trait your internal traits this is a public trait so it is this will only generate a trait for you for this internal function all the functions that are listed in this internal implementation the trait will be generated for you because it has already been abstracted and called in this generate tra flag buts with internal yes so my yeah this was exactly what I was asking about earlier for the internal functions can I get okay thank you um Victoria so all my functions right would have to be inside and Implement that I can't have like a function just be on its own because you can like this function we see here so the my idea of interfaces right is that you you use it as a a structure so that anyone that want to use your your contract can just um get the interface and get the you know contract address and you know just implement it just like it is Sol but now I'm seeing that I'm generating trait for private function like why do I need um interface for a private function since other contracts not be able to see it to implement it it gets I don't know if I'm making sense yes yeah you're making serious sense I'm making serious sense okay let's check why private interface is needed right I don't really I didn't really pay attention to it so so let's check it out so it it was explained was explained somewhere around here private functions so let's let's understand it functions that are not defined with the external flag or inside a block annotated with this are private functions also called internal functions they can only be called from within the contract they can be grouped in a dedicated implementation Block in components or easily import internal function all at once in the embedding contract or just be added as free functions inside the contract module note that these two methods are equivalent just choose the one that makes your code more readable and easy to use so what are the two methods this could be a group of functions about the same topic or this it could be a free function so what is generate tra attribute where is the trade definition for this implementation generate trait attribute is a special attribute that tells the compiler to generate a trait definition for the implementation block this allows you to get rid of the boiler plate code of defining a trait with generic parameters and implementing it for the implementation block with this attribute we can simply Define the implementation block directly without any generic parameter and use self as contract state in our functions the generat rate attribute is mostly used to define private implementation blocks it might also be used in addition to ABI per item to define the various entry points of a contract so you can see this next session using generate trait in addition to ABI embed attribute for a public implementation block is not recommended as it will result in a failure to generate the corresponding Abi public functions should only be defined in in an implementation block annotated with generate rate if this block is also annotated with the ABI per I per item attributes okay so you can use generate trat for your public implementations also based on this but it is not recommended as you can see here it is um used for private implementation blocks and using the generate trade gives us this self in our functions so if you can remember when we wanted to call when we were implementing store name we used self doore store name it gave us the access to just use self underscore store name because it was defined here but then I'm looking for where this was called so we see the difference so if you don't want to use trait to reduce your boiler plate code this is what you do you don't declare the trait anymore in your mode your module you put your flag a per item and then generate tra then the implementation your Constructor and then for every function you pass into this if you want that function to be public you add this flag external um attribute to make it public so if you're using this method you have to you can implement both your private and um and non and public functions in the same implementation block the difference will be the flag you will be passing to it so if you don't pass any flag it is an internal function but if you pass this flag then it is a public function so if it has a ref that means it is a right and if it doesn't have a ref that means is a view function view public function so yeah I think with this we we have gotten the whole use of generate trait but it is majorly used with this internal functions because if you check standard codes of um serious project in the ecosystem they don't do it that other way orless maybe new project that coming now or some security threats and stuff that makes them implement it or maybe they just want to just do some crazy stuff and then they implement it that other way but this is a standard for writing smart contracts at least if it is more readable and understandable imagine seeing this as they start where are you imagine seeing this at the start do you would you understand what is going on here if you've not understood the concept of the trait generate trait a per atal you would understand what is happening here right or would you it doesn't look readable am I talking to myself no no no so if you if you see it this way it doesn't really look readable and understandable it needs someone that has really been writing the qu to understand what is really going on here but with this is still not very readable but you have an idea you see that it is called an interface and then you see it implemented here in this implementation you see the Constructor and stuff it makes it easier to understand what is happening here you see it is it is calling this function and then you see the function here so without understanding so much about CYO you can kind of deduce what is going on here because it is more readable but once you're an OG like Victoria then you can write it the other way so I'm trying to understand I'm trying to see where this was called I'm trying to see where this was used because if it isn't called anywhere you can't call it once it's deployed you won't even see it because an internal function you only see it in those are internal transactions I don't think you see it was this called anywhere it wasn't right get owner storage address it doesn't C anywhere here okay so it doesn't called anywhere here storage Bas address it wasn't called anyway here yeah all right we're going to find out what that is used for that last function okay so um next um so far are we clear is there any other question okay any further questions if not then are we good to go should we start writing our smartphone C yes it's only Vicki and Emmanuel that in this class what's going on are We tired it seems I've talked too much no no for the action okay um is this readable I'm sure this is readable right yes okay so we want to BU up a new Kyo project so what do we how do we create a new Kyu project so we are sure we are following so call it for me while I type it oh who said that Benjamin Abraham okay cool okay so what is the name of the project what name should we give the project our first smart contract okay cool we have instantiated our first smart contract the new window okay I think this is this is readable right yes okay thank you so what is the what is the next thing we need to do edit our TL thank you so what should we add under depc and then the target okay so we adding this we adding this to the dependency and then we are adding the target to compile to S and we save okay so rc. skyro I need all these things Okay so first thing we do use St net so what are we call cont so the next thing is our traits so before we call the trait it has a flag and the flag is called stet what is this correct yes that's correct okay do we need any else why is it crying um doesn't need anything else so okay just for the tra so what are we building what is our first contract about give me ideas now what who is speaking get name get name I set name set to l oh yes too list okay to do why are you sh yeah so what what are the functions for to-do list that are needed add to do right right yes yes I need to add it to do and name does it take any parameter um to add a to do what does it need it just needs description right yes and maybe dead for to add that and description name and description and then status name and description right what is okay to to a person title of the yeah what the title what do you mean by title if there's a description what do you need title for idea what to do is about like like a header I'm not you know if you see number one and then the name of the the to-do you are to do and then the next thing you see is the is if you've done it or not so I don't understand what you mean by title can you like explain we are adding a to-do now to a list so what is the title there for is it like what is it for I think what we need ma is just the description right and deadline probably yes yes okay so description of the to do and deadline and deadline is what what data type is deadline u32 should be2 you size new size and then the the deadline will be returned as an Epoch time now right yes u in 32 can handle Can U in 32 handle EPO size the current size can someone check 1 * 2 is it 1 * 2 ra to power 32 - 1 2^ 32 uh what am I doing EP time is actually in 32 bits yeah but it keeps on increasing time is is seconds is the number of seconds since the world started so as long as the project continues EPO time is going to increase so if they want to use this project in the next 20 years hipop time might have grown from Unit 32 to unit 64 I'm just saying what is the current Epoch time is it within the range of a Unit 32 at the moment so we it's actually the range of 32 but I think after like 20 years it should expire like should go B I don't think it's up to 20 years again so okay so we add to do are we expecting it to return anything once we add it should return a Boolean right so what's other function up to to so if you want to update description and deadline okay then someone say get to do right so get to do because it's a list it should probably be an array so this will get to do first and then self contra stit we don't need to pass anything and then it Returns what uh uh what is how do you okay without without tra sir we check the we check the documentation anything wrong there fix it so function get to do s and then we pass the index right yes index would naturally not be more than so what will it return stru yeah it's supposed to return instruct okay let's just let's just proceed then we'll come back to this so once want to update update also needs the index of the particular to we want to update right yes okay so we are sure of the first two but the last two a too sure about it so what is the next thing St next contract contract Okay cool so next mode to do what want to do and in this we have uh storage we have our stru so even though you do not Implement stru you can just leave it like this if not your code will not compile if you don't have a struct a storage struct right in your Cyro code it will not compile so we'll still use this in the mode and then next to do we don't need to instantiate it with anything from the beginning we do not need a Constructor because it's not supposed to have any information right we can set what can initialize owner can initialize owner why do we want to to do that the will be the only one that will be able to update some things Okay Okay cool so is it contract address okay so we can either use the color at this point using get color address but it seems it is slightly different when you're working with get color address when it comes to deploy let's just have to import it to use it yes we have to import it um I'm just thinking just it if we encounter any error fix it so get why is it not a completing yes color address so I think I want to write something here because I want to check properly owner the contact address so let color be equal to get color address and then self dot owner do right we don't need this anymore if we're using po address sorry but I don't think that will work because the caller will be the deployer universal deployer exactly so that's why we need the owner that is who will be the owner that's why we need the owner in the Constructor but we don't need the color for this step add be un we have to add code the owner to add code the owner yeah so we have to hard code the owner okay so this is all we need for the Constructor okay that's all we need right um are you guys still with me yes yes yes okay so next what's next our public functions Okay cool so how do we start AB blah blah blah then in right yes v z v zero like this I'm not sure yes why did we use v z okay I don't know what's up let's continue okay so now we are implementing to do list is it for off so I was saying we could use the use use our first smart contract or colon colon Le colon colon to-do list I to-do list here or we can just write super and here we are setting it to Contra to okay so another thing we need to do is create a folder a file called to do Kyo sorry I forgot that was the first we're supposed to do once we came here so everything we copy here put it and paste it here you to do leave.
skyo is where you add your modifier so we are adding mode to do so it's going to be reading this too file for us so I hope you guys thought what I just did all right so the first thing we want to do is Implement add to do and to add to do I just copy this so to I have to do where are we adding it where are we meant to add the to do the new to do two so which document send it to I think you need a struct actually to okay so in this struct we can have something called too list right an of to-do list right yeah so so not we cannot um have an aray in the stru but we can have a legacy map we can have a mapping sorry I have a question yeah what's the difference between this Legacy map and Dictionary h Legacy map is a normal mapping in noral also helps you to do mapping but not in the struct not in storage so map yes helps you to do your add your mapping to storage directly but dictionary you can do your you can do it outside and then the value you'll send to one of the one of the variables that will hold the results in the storage struct okay yes so for too list so what are we supposed to pass to this should have you should take a unit8 right index yeah as the index value of to I think so to ju okay so we need to create a struct and to create a struct was the flag the theive right now we theive Dr said right now we derive was it St St was it stop yeah okay let's just it is it this one I think here sorry okay yeah this so the drop said and stet store so this drop should be capital and then make it a public but why is po giving me issues so struct to do should itce or because is this least that should hold the entire to right I'm correct yes yes too and the Todo will take the description right say the description headline description us F 252 I should take a deadline get it soon now that should be all right and [Music] um what else how do we make sure this value you can have an like something like an ID inside the stru this yes you can add like ID so so we able to track what to do okay cool so we use the ID as the as the key key okay cool all right so next should we do the implementation here or let's do the implementation in an internal trait okay let's do it in an internal so we get fully used to everything right now start our learning in the right track generate tra okay so we are implementing private implementation of private implmentation traits and we need function _ add to do the same information I need to return need return in the main okay so to implement adding to do what do we need to do so call Self dot description right self do sorry what is the name L too list WR what we are we writing uh uh so ID how do we track this um zero zero can start from one or Z any we are meant to read from this how do we read this can we read like this yeah you can actually can do that to yeah from the storage this one yes okay cool cool cool so self to list read what are we reading to read we still need to pass in the index and I'm trying to get the index okay sorry BR if we want to do that depend based on this our what call we are implementing it we need to like have uh what do you call it now tracking like this Index this is what they used we were using this to track how many people you can do this you can can you see yes yes like they use this to track how many registration had yes you can have it outside so as we are adding to do it to be incrementing yes so to save us um stress so who's call it to do ID to do ID should be a it so at this point would we would be reading to do ID instead please all the rest are following me yes okay so now we've read what to do ID is at this point the next thing is to write so self too list do WR ID what what is it taking to list is only taking ID and destruct and destruct okay so that is ID whatever ID is plus no no no don't it will be self Dot sorry once we've read it then par current ID right equal to ID one one so that is what we will pass in here current ID then can can't we save um like like using the key and can say let variable Legacy the too so that we be able to initialize our variables I think yes yes as instead so something like this right where we say where we called owner as the variable and calling yes owner do name owner do so for here but let's see okay we have to sa it inside the variable first so what should we call it too too should be the to-do struct yes okay so current ID um um so do we need this ID here so let me be sure what is going on here we have address name and this Tes in um to do list takes in this and it to Second parameter should be the yes so that means we should initialize the struct first yes that I'm saying first create initialize variable for the struct to right yes and then we just pass it what is ID should be current ID um description you have to bring back those okay to do do uh description yes or you can just do it this this way even know pass it here as what is the best way to what is the best way to do this instead of description you can just say too yeah too dot description right to do colum to do colum to do but won't the two toos be shadowing each other yeah that is shadowing here because we can let's there's a to in our parameter don't maybe we don't need to add like this I'm just bringing that one instead no need of it to do anything can just use the to do that in the par can just yes write it straight to yes yeah but um the current ID should be defined inside that struct yes yeah that that's true that's true that's another thing to consider ID so we need to initialize that to do first we need to initialize that so let's let's follow this and see how they initialized it it just wrote the address and name and this owner only needed address and name and this our to-do list needs um okay we need description and deadline okay and description and deadline description and deadline then we need um something else ID and to do so to list and deadline I to do but we can make this a a 2d mapping instead so as a 2d mapping it takes in it takes in the it doesn't need it's not supposed to be a 2d mapping but suppose if it's a 2d mapping then that is when we can easily initialize this then this but I'm sorry but I think we can we we can just um Define the too normally and then we just write it into the um Legacy map the normal way self. list do WR the ID and then the Legacy map but first of all we need to define the to-do itself so maybe instead of passing the to-do directly as a Str except maybe you want to um generate the to-do inside ad to-do function and then pass the to- do struct directly or just pass description and the deadline let's see this first so let's to do be equal to so I think um ID so idid should be current ID then description should be description pass and dead line should be the dead line first so here can just pass out to do yeah just pass to do this is supposed to work if if everything is it's okay this is supposed to work okay so here where we have add to do we'll just call Self Dot add to do and pass um description that's what it needs and deadline right and we return true because returning a Boolean uh okay um so okay so what next let me add a function let me the normal function to read this to-do list so this function is to get to do but we are returning it if we are calling it we need to add a key right if we returning this okay yeah if we returning this we need we need the keys to be returned so you you get what I'm trying to say right yeah um we can actually create um an array an array that we can push this the the cool okay so the next one let's just get to do you get to do is okay so to get our to um sorry move this and [Music] this so to import array so use I think is four you can check it so that we are sure we are on the right track so to get let to ARR TR new right so to do as um array so the next thing is we want to read and to read we want to use index to read so we can do a look so I does it work without this it's just to define the keyword Loop yeah sorry sorry okay so we look and in the loop so what are we doing what's the next step I think we need to Define two variables outside yes one the total to do counts and then the second one will be the index that will be using to read so what is it count count to be self do read I mean self do use count how do you call it do id. read Okay cool so what is the next the problem now is after our to do we not increment to yes we incremented it before yeah yeah but not reflect on the to do ID in the sorry this was just reading okay that is that the last thing actually thought this was s do blah blah blah read WR thank you for reminding me all right right current ID okay so it's complete so here what you said anybody say something you can go ahead so um let me quickly check the loop function to be sure I'm on track is there anything for [Music] loing General programming concept I mean common programming concept rather another two number two okay [Music] true okay so we'll be checking if in there X is less than um if index is less than current count current count plus one be current count plus one can use while instead while is easier while index is less than say while index is less count plus one so hope we together no while is another loop on it own instead of using Loop you can use y is another look yes okay this so while okay cool I'm feeling I'm feeling weird about this okay while index is less than count plus one okay why IND is less than count plus one append um should it should we atend now let's let's read be equal to self dot too list do read right yes index and it's only the index we need yeah it's just the index thank you go read then oh is read not a keyword it's not us error it is okay so next thing is toodu pend so then there no break index increment but I don't understand why we are doing count plus one plus one you know if index is less than count it will never be equal to count or should we put while index is less than or equal to no but when it get to to count it to stop right yes it should stop we use less than it will never get to it will never be equal to count but since index is starting at zero why is why is it like plus one again I think the problem is coming from the way we actually implemented it the index should actually even start from one from our implementation because the first ID we be having when we start is one so I think if we want to have it start from zero we have to move the addition after the this so here we can stop at count plus one because that particular index at that moment is the last item on it to do because of the implemented it actually with with this oh oh oh oh I get it now so the um the we didn't Implement ID to start from one we just read it and just added one to it where whatever it is I R start from zero index start from zero an index in an count index from since IND starts from zero then we don't need plus one do you do you get what I'm saying actually start from zero but here we are passing the ID as one and we are setting it into this to do and into that um our our storage struct so if it is zero it is actually not one and that is why I am adding plus one so once it's so whatever the last count is the plus one I was asking about was the first one in the wild sh yes now this in this while yes that one we are reading okay what is to do ID so index you be one index our index should be one in this um get to do then oh since since our starting point is one we started okay this is where we started thank you we don't need it we don't need the plus one we need we we need it Ma we need it based on based on the fact that our index is starting at 1 oh oh since is an array yes yes yes yes yes yes sorry sorry sorry sorry yes I'm sorry I think weing this thing I'm sorry but we are actually reading from a legacy map and like I'm say like I was saying it is because of our mentation that is why we are having need to add this plus one sorry M please if we don't if we don't want to add this plus one right we need to current ID addition after to after yes yes yes not before so if we don't want that plus one we just move this current ID addition downward so we'll be using the ID as the ID of it to do then after that we can it yes yes are we okay now you have to add plus one to the we need the plus one we need the now also one last thing yeah you need to make index mutable thank you yes we need to change the data because I discovered you cannot do greater than less2 data type of what the index index and account okay we did not set data type right yes data type of count is that what you are saying hello is you okay okay okay okay so we need to change are we okay now yes why did I get okay so I just want to I just want to try to test this just this two to add to do and to get to do but they they you called actually add what I think it actually adds to an array just the way we have they append yes yes that's what it does so what are you trying to say I I thought we are actually getting instead of in yes now we are getting but to get is a marking so we have to push the items into an aray so that we can easily read the array okay okay okay okay okay okay so will now return the array to be able to read what we push to the mapping okay okay yeah somebody raise your hand okay so okay let's try this out um we hope everything is okay um so once you've written your Cote the next thing to do is to build okay now this is the main problem version conflict so we used um our smart contract version one cannot use tacket version 2.2.0 because it requires tet version 2.
6.3 so I need to update my scab in case you guys come this error you need to update your scab well I think we have here okay okay let me use this 2.6.3 um when is your when is your next class Wes next week Wednesday now when is the class to end I can't hear you seven s oh so I'm meeting it to your time no worries no worries thank you okay so it's taking some time to sh okay so let's check oops um okay please walk okay so let's correct our errors so our first a okay so so for the return type of implementation function I too L dispart get Tod do is incompatible with I to do L dispat tra get to this expected an array type of AR yeah isn't the arrow so oh should it contain to do um you went it to return to do is returning to to do okay so next what at interface type annotation [Music] type annotation needed AR okay next ar ar ar ar array okay so I think array is the culprate then what is this okay so let's see if this works it doesn't we have to go and check out to call and array okay so missing semicolon line 51 am I supposed to okay and um to do do append ref argument must be a mutable variable this must be a mutable variable the array and what else okay so let's see okay variable not dropped oh you need it to be dropped guys let's check out call and AR properly I'm trying to see how to return an aray [Music] if anyone has seen it please please let me know so we don't waste so much time are you guys with me okay yes yes yes I just sent a link to CYO by example [Music] okay okay so I I already trat and this trat new [Music] uh what we are on track we are actually on track with this um I think the reason it's saying that dropped something is because that attribute what I think the drop attribute was added to the trads that is why you need to um import the Trad to use that like like Aras a return type what do you mean import the trait sorry that use array then AR yes some this I'm supposed to work yeah okay so it's not an aray so this will it will be an ARA of of of different to do why is this a [Music] problem sorry please can you go to your [Music] um your um traits first one um you are not you should use to do like in use to do um to-do to-do the struct because he does not know the struct inside to-do module so like the line line seven now this too inside your array it does not know it this your trait yeah thank you yes yes yes yes wow and I pointed that out how did I forget okay see hey okay we did it thank you so much so the error the first error was my stab version and the second error was because we're calling a function inside this mode a function inside this modu and so we had to um reference it this way so yeah guys so hope you understand what I just did what we just did yes yes okay so next is um oh i' love to test this but our time is really really up so maybe in our next class if if I have a class with you guys someone else will be taking you guys on testing so I think I should just complete this there was no quick there's no quick way to actually test it we have to write another testing file like another contract for testing unlike normal CYO programs so I'm sorry let's quickly update and then get so to get to do won't be as tough as this because it's already already taking the index so to implement this all we have to do is all I have to do is self do too list do read I will pass the index and that's all do we agree yeah okay thank you um the ladies are you still on the call yeah yes are you following or did you get confused um yeah I got confused along the way but I find Sor about that that's a problem withy um Benjamin you've not been talking David um okay yeah okay true sorry so you're following right everything is going well B David David how is he going oh great nice um who was with us from the beginning that a is a still with us a are you still on the call yeah he's Still's on the but his laptop's um mic got SP wow um a is enough Nicholas yes Daniel Daniel Joseph yes I'm still on Transit wow okay Nicholas all of you are getting it so it's only only Vicky that don't get it you're going to write assessment I going to do a test now no no no if don't get it better say you didn't get it to there's an assessment like immediately after this class okay okay all right it's fine Abel Bo people said you got it why are shocked so so the assessment because I'm I'm really sorry I'm I'm entering into your time so your assessment will be to implement the last function updates so how what do you guys need should I um push this code to a repo and share the link in the in the telegram chat yeah you can put it in just yeah in okay cool cool so you guys should um implement the last function update so you don't do everything from scratch again and that will be your assessment and I don't know um we were meant to do more than this we're also supposed to do contract interaction but I hope um probably if you guys have time again we can meet before Wednesday if not we hope the the class on Wednesday would handle it but you have time should just out to me and Sam so we just fix another class so we we tidy up this project we just built we deploy it because we cannot I don't want to write test for it because you'll be doing testing another class so deploy it and try it on chain to see if it works as expected and if not would bra stor on what we did wrong why it didn't work and correct our mistakes hope that is fine yes then we'll do contract interaction so we do we build another contract and try to interact with this contract from that one in the next class after making sure that this contract is perfect the to-do list is perfect so I will just move this to G send the link to telegram you guys should um um work on it by you don't need so much time it's very easy by 900 a.m.
900 p.m. today should it should be ready submit your G with your update to do function in it and some will track it from the list of those that have submitted there then you guys should talk together and fix a date and let me know let some also know so we fix a class and round off this particular project I don't want to rush you guys because I really want you to understand what is going on behind the scene how everything is Computing so immediately you finish this program you start writing quality code not just any alyo code real quality code that is production ready that is my aim that is my own Aim so I wish you guys the best so I'll be posting on gist have a nice evening everyone and I'll be hoping to hear your response for the next class bye everybody bye bye bye bye thank you yeah
Automatic transcript — names and jargon may be misspelled.