Cairo Programming Language II
Web3Bridge·Wed, Oct 9, 2024, 12:00 AM
Transcript
so that's the simple meaning of macro and there are different ways in which macros are used in either r or Kyu so when you see the print line that has the exclamation whenever you see any piece of cod you know that has that is followed by the exclamation so it's called the macro so you have that as that's the macro there's another mro when you all those derive so before the beginning of let say a structure or a function or a module so you can have an ash into the bracket of then you have the name of that particular macro in it also so you can have a derived macro that has copy you can derive a macro so examples of other macro you have the copy um copy drop all those ones they like standard Mar that they can simply look through the the structure and they going to generate those copy code for it so the thing is the way it works is that normally when you have a structure there are some things that you need to like add there are some traits that you need to add to it so you know we have the copy trait the drop trait and the likes so there are some that when they follow a particular pattern the uh the the those tra they can be inferred so or they can be derived thank you so in that case that's where we make that's why we say that's where we make use of that deriv mcro so you make use of the deriv mro then you can do that then there some also there are some macros that um stet also provided for us like that the cairu has also provided for us examples of those are when you have the generate traits macro you have the you know the storage the events and the likes also all those macros too um so what they do can you share your screen as you're talking cuz uh I can't see your screen I don't know if you're sharing okay I've not started sharing my screen I feel like I need to have a visual view of what you're trying to say okay so someone asked a question actually so I'm trying to I'm trying to answer that so so let me just do this okay let me come to M this m yeah we've not got here H we got here no you haven't got here yet so what happened is that those marrus uh before at um compilation time those codes they going to be written out it's just like they like short codes so those codes they are going to be generated out before the program is um is actually like compiled so that's how uh that's how you should that's how you should look at um those macros so these are examples of macro so you have the selector print print line Panic format right right line so all these ones are types of there are types of macro so in the last class I said that okay does any other person has a question I think there's a question so we can just go ahead all right so okay so um two things actually number one is how many how many people here is aware of the St L stackl app challenge so you go to app so how many people here is aware of this if you have solved that let me I need the show how people one two three all right so we okay we have Ah that's nice so um I want to do something so now I want to do something so I want you to in the next some minutes you going to start the app want to see how much of it that you be able to much of the questions you going to be able to solve in the next 15 minutes so this is it so and when you you just going to send the screenshot of that to do you guys have do you guys have a group not really there's no so you're going to send the the screenshot to [Music] um let me sorry I'm going to provide you the email now or you can just create a group for this I don't okay so you're going to send it to that email so if you look at this now you have the intro so what you want to do is very simple you just have to like compile it so this one now there's nothing you are doing just compile and you move to the next one so this one it don't compile why so because the reason is simply because there is nothing here so for it to compile you just need a main function so with this you can compile it then you move to the next one like that so want to see the number that you be able to compile in the next um 15 minutes and so the thing is you should start uh I'm going it's going to run between 5:15 till 5:30 it's going to run between 5:15 till 5:30 so please if you have solved it before for this one you have to start again for this one you have to start again if you haven't solved it before it's uh so we just want to see the number of questions that you be able to solve within that 15 minutes is there anyone that that doesn't have clarity about uh what I've just said hello sir yes you said that for people that have solved it before how do we undo it because you know it's checked green once you've solved it okay you can you can create an in uh what's it called you could get you mode pardon like you can create what is it called so you can like new maybe new private window if you create a new private window that it doesn't have any session so just use that okay okay okay so want to know how many how many we be able to solve within the any time range so how is it yeah so your time started how long does it take to compile because this has been compiling for the past 3 minutes ah as you can see it doesn't take much it does it depends on the system it does oh let me give you an next what this supposed to be let's mute right pleas how many where are you now can just see wow compiling it's still compiling is Wow first one W for those joining we've used um two minutes already so just go to the St Lings app create a new session create a new session and start solving the problem from the beginning so by 5:30 you want to see the number of um the number of problems or challenges that you've solved for e you should be in function two already hello sir some of our laptops are not very fast so the comping is taking time hello sir hope this is not an exp for yeah um I have I have I done it sometime ago but I use Incognito but it couldn't um you know refresh my yeah it zoed immediately it zoed immediately use browser all right all right use another browser if you've used maybe Bravos before you can use Safari or you use Chrome [Music] know [Music] for for I hope this is not an expo the reason I'm doing this is I expect I should have gone past that how is this how is this so fast you have eight minutes left 8 minutes left this work no for got for for 4 minutes left how many people are done let me see show V we done nobody is done yet is it is it don't up to we my own laptop is taking wow yeah compiling is quite slow and sometimes comp find an error you have to and compile again when you sum two numbers you get when you sum two numbers there is possibility of getting something bigger so this should be 16 [Music] so for for hey those of you that com to class you have one minute left okay let's try this some some big numbers okay some of big numbers so it's supposed [Music] to okay there all right so I'm up you should have made your screenshot H so just make the screenshot of where you are know that your screenshot is going to include the time that you made the screenshot that's very sure so just make the screenshot and send to the email provided make the screenshot and sent the email provided wherever you are so and that marks the end of the so how was it how was it hello how was it nobody speaking good not good good you too fast huh you too fast I don't I don't want like my first time with hyu right and [Music] everything is the you know yeah okay how many people did it up to up to en how many people did it up to en you did it up to en let's say show nobody up to loops up to Loops nobody up to who this one is one okay one person two people H what's happening to qu is one just one person okay functions how many people to functions okay um if how many people up to if nobody operations operations nobody primitive primitive type operations operations one okay Primitives okay variables variables is just the beginning I should see every other hand now how many hour am I saying just three five 78 wow okay let's let's look at it from here this primitive primitive types for I hope everyone has submitted sh that's very important hello I didn't submit I quickly submit quickly submit I go to like three or so just please give me some that's Co hello okay so I'm back okay so let's let's let's just continue from here let's see let's try to get this so if you are going to solve this one I believe that all these ones the all the ones before this they they are pretty much very simple so if you look at this one now some big numbers let's look at the test that we have here so some big number to do modify this test modify this test to use the correct integer types okay don't modify the values just the type so here now when you sum two numbers so this one is supposed to be 16 yeah so I've changed this one to 16 so the reason is when you when you sum two big um there's a law in in algorithm you know if you have one if you have uh what's it called end digits when you sum two end digits the maximum number that you can get to be n plus1 digits do you get so if you have unate and unate when you add together the maximum that you can get is going to be that 2^ 8 + 1 so which is already uh above the range that we have here let's test this again first okay there's another issue unexpected return type okay some big numbers where is it some big numbers some big numbers line six line six yeah okay to do modify the types of this function to prevent an overflow when summing big numbers yes it should be unit it umit 16 right you can just give the what inside the parameters I think it should also be 16 which unit eight should also be unit 6 you mean this yeah I think so H let's maybe no like inside the parameter inside the parameter no those one should be unit8 now like here x should be unit8 y should be unit8 then it should give you should give you Unit 16 yeah something went wrong with your code F to compile let's check some you can cast it you can cast it to you know you in 16 if you don't want to actually change the parameters to you know us you can see we have this as s so we can have um let's see now we have do TR to oh oh oh oh okay unexpected return type expected Unit 16 found Unit 8 okay let me just test this one first so we are supposed to uh so this should still be 16 then this one will now be into so what's this test big numbers fied where is test big numbers test some big numbers oh instead of doing the in together you can do it separately like X do [Music] in you moove the parth here so if that doesn't work okay that works thank you so operations one turn the solution of x^ 3 + y - 2 so so how do we how do we do that so you just say that R let result equal to so X to power three how do we do that that should be power right 3 + y and soon so let's try it out about two sh you can just refresh cuz it happens like that something the app is Bugg uhhuh have to so let's yes equal to that will be x dot x the^ 3 + [Music] y okay I did branet x * x x + Yus 2 it works okay that would work sir yeah I think there's there's a power method sorry sir can I please is um zoom in your screen that be so calculate the modulus of X and Y so modulus is simply so you say let rest equal to X so mode will be percentage where is percentage X mode y huh okay what's that so I cannot see you your just speak out okay okay so the one you just did right the op one that you have to do like X time x time x uh yes the power method that you trying to do like have you used it before in because I feel like the first the one you did that work is not really that efficient so if there a power me because let's say I have like 20 you know that I want to you know get the part up to yes you think that's efficient yeah I know there there is power method in K actually there's method in KY I'm going to check in the common collection getting [Music] started should be in the unit so you can check appendix append 12 number 12 okay I so it's going to be a tra under okay operator yeah maybe even this let [Music] yes this is it ah no this is exclusive this B now it's looking like it's not there wow so it's rust so it's actually not there actually it's not there let's continue with this first multiplication will be let res = to x * y so we test next if do not use another function called additional variable so bigger want to know which is bigger or what this so you can just say that if a is greater than b is going to return a else p b right complete this function using IF iFish is return full so if fish is Fe return full else this so what fishy this fing complete this function using IF else if and else if if is return [Music] full if it is p return bar so which means that here we are going to have else if equals who it's going to be done B then else howse this [Music] the last oh the last one sorry sorry about that you so functions call me so we have to call we have to create the function function call me so it's returning nothing comp comp next one call me with this function main it's because this call me so this one now it needs to have so let's say it's unit8 right so you have to add the type parameter of whatever functions they calling so call me again this one it doesn't have any parameter so um like here it is indicator it needs it needs this Norm so we have to just put something here so yeah main this the original print line this uh original price sale price sale price is this is even priceus this this is even X this okay so this is having a where if the don't wor about the function this we are only interested in the signature for now so so you can just type that Stu disturbing you right no it's going to beave somewhow if should it so let's this equals to 51 this 51 here we don't know so this Unit 32 if it's even it's taking Unit 32 so what's this one returning so this one is supposed to return something right so let's this is supposed to unit Unit 32 so this is taking in2 [Music] and okay so let's check that so we have a quiz here calculate price of app that's the function verify test do not change the test put your function there so look at this PR of 35 of app0 of Apple maybe is buying apples okay the price of an apple is calculated as follow an Apple cost three kyox an Apple cost three kyox if Mary buys more than 40 apples each Apple only cost two kyox a function that calculates the price of an Apple so an Apple cost three kyox if May buys more than 40 apples each Apple only cost two k so what we are doing here is we need to take in um you know want to calculate this so we need to take in the number of uh number of Apple so let's just use app here so and the number of app is going to be let's let's just use unit unit unit8 is enough here so and the price is also going to be it can be um 8 Also let's sayit 32 let's just so we just say that if Apple if the Apple if it is um if it is greater than if May bu more than 40 if it is greater than 40 then we are going to return what Apple Time 2 else we are going to return Apple times three as simple as that now you see that here I'm not putting a semicolon the reason I'm not putting a semicolon is so that it can return that's I hope we are we we are getting it already so let's check that oh what happened unexpected okay expected Unit 32 found Unit 8 so let's just put eight here inate is enough so Loop test Loop let's mute count ials to Z make the test pass without changing any existing line make it pass without changing any existing line so we have Loop break counter plus one so counter equals to 10 counter should be 10 so what we just need to do is if we just say that if if counter H is equal to 10 then break so we now bring this break [Music] here this one mute ass result equals to five so you see that in this place now uh after this Loop here withit after this uh this condition is to increase it by one so which means we are going to say um if if counter if counter equals to five wait if counter is equal to five we are going to break it here we are going to break the here it's still the same thing results should be five and and we are also going to return counter AB once it breaks it it that part before the break okay and so um so you can just um take out the break for the break statement on line 10 take out the um C I mean the pareses at the back then um go um bring the counter to the front of the break bring the counter to the front of the break no no no as in on the same line okay then space then put the expression at the back no semicolon semicolon yeah okay thank you thank you for that so what's happening here is when it breaks it is returning this counter value so because we have let um result here so it's turning this so we have the en Define a types so Define a few types so here we are going to have quit Echo move and change color wait e move and change [Music] color so having trouble okay so this one Define different variants so we have quit so it's just like what we had before but there's now a little change here now you see that the echo now has a felt inside it felt 252 then the move the move has uh has a top of say Unit 8 comma Unit 8 inside it um which one again then the color um the change color it has unit sh 32 this should be 32 in two in so so let's see missing toen terminal Comm thanks oh no can be wait um e be B Theo I'm just I'm just thinking could it be B AR B I think I think after the that should be a colon that should be a colon for Echo move and change color like this just a single col [Music] okay missing token comma so that me there to be a okay so there suppos to be a Comm you can just leave it at as one instead of you so this expecting u8 all this ones are expecting u8 not 32 maybe just has to be one one type not three types wait sorry um unexpected arguments type expected integer found what this I think it's expecting just one but finding initial bracket I think same applies for the F because then the F also become yeah oh no need of brackets I don't think you need bracket cuz it's expecting just one like one same you can just remove the [Music] parenthesis like make it just one type you this nice like one like one no like one not get and but you're giving it a to it's telling you it's expecting one but you're giving it you maybe just one type then you can just use that type for two of them okay let me copy this and reload it unexpected type expected call integer you found this so I think the problem here is that this one what we have here we are supposed to take in that two let's try this okay so we are taking two so this is working [Music] now so can you explain that one this last we just finished please complicated in my my eye so yeah we are taking in we are taking the argument as of like this so let's comp and work was not working before so I think Ser of number one the syntax the use of colon then uh then uh we have to like put two two together as a type and there has to be a comma after after each of the types there has to be a comma after each of the types let's check the to here implement the message variant so in this case now the message variant here is quite different so we see that here we have message of we have change color and the change color we have this um the change color is accepting this one no no [Music] no we have state here State as color Okay position quit message let for so in the message we have change color Echo move and change color so let's start with change color so this change color now is taking in is taking uh it's taking in this which is 8 comma unit 8A Unit 8 then Echo is filed yeah hello can you zoom in a bit more thank you thenes I'm not able to see this s move so this move is taking point then quit just quit so let's something went wrong test output to fi wrong color okay I think that's not the only to do most likely okay create a match expression to process different message variant so um in this process here so when you create a match so we are going to match the message right so before that we are going to start with let color we have color after color we have position then quit then no color position with to S right then we now match the message so if the message is If the message is uh what's it called change color so the method is change color it's going to have its own uh if the message is change color then it's going to return um self equal to the change color that we have here it has this argument so we can just take that let's say we have x y z so you can just say um so color here [Music] we so we can Pi the argument here as new color so the color will now be new color then the position will still be position and the quit still be quit so if the message is what's the other message if the message is Echo so let's we are going to take the argument as uh let's take it as s and we are going to ask you to print line with the statement If the message is what again if the message is move so we have mov to a new point so we just see self report P so the color that was there is still be the color the position is now going to be the new new position and the quit we still quit then the last one if you have quit then we are going to self equal to stat the color will see be color the position will be position and which will not [Music] be so let's missing token terminal 53 uh terminal comma okay missing token time now 53 again new color l in toing time now message new position grp so I think you're supposed to use the functions that inside the quit function Echo the move position function I think are the functions this on yeah the ones inside this change color function function it yeah so we can just they almost the same actually so this one be change color I pass in the new col let's check since this this change color is also a function inside this one so you can just do self. change color [Music] missing token terminal for new let's get the into maybe the error coming from the other one that one that's the what you think you have to do it for the others to the echo the move and you have to use those functions s dots move position new points so this will be S that quit missing new color supposed to be Comm here yeah instead of comma instead of semicolon comma in the car comma set of sem end yeah yeah okay change color it's still change [Music] color oh yeah there's Comm like 53 the Comm new color close to new color yeah yeah be I think the command should not be there yes color okay that's reduced so on varable consider IGN this okay so there's no need for this okay so this should work Co thank you for that so options this function I believe we all what options are used for so it's uh option it returns a value it returns something or none so this function returns how much ice cream there is left in the fridge so it's before 10 p.m. there is 5 P left at 10 p.m.
someone eats them all so there is no nothing left so which means that when you look at the we are going to look at the time of the day and we will say that if uh it is before 10 p.m. so we use the 24 hours clock um system so 10 p.m. is going to be what we start with a then p.
m. so 10 p.m. is going to be 22 if time of the day it is lesser than uh it is lesser than 20 two then we return option of what no then we return is it some what is it called five else you found none right let's test that oh to fix this test how do you get the value contained let ice cream equals to this we have to call option then column col then Che I think it should be same for so for this one it's just you you can just unwrap it for okay so this will be option check ice cream F gas usage with two field which which one field this one is okay this one this as to take sh ice creams equal to five this is okay so check duplicate 9 at 9 it is five at 10 five at 23 five at 22 [Music] 5 wait wait oh okay else if um time of the day is lesser than or equal to 24 right so option some so some zero here okay so here they they making us to check for the time of the day so it has to be lesser than 24 so when it is more than 24 then this on target is this some this use the E some and non methods check if optional targets contains the value this the assertion the correct blocks so Asser optional Target do unwrap let's see optional Su optional n okay so we say if optional targets dot is some than those are meths you need to call them [Music] oh what again modify the following lines so that if there is a grade for the course it is printed grade is so so course is this so what you are going to do modify the following lines so that if there is a grade for the course so we have a cost here this cost is going to be printed so it's still the same that we are going to use so let's check if there is an option where is students so you said that if cost dot is s otherwise experience no good display gr okay no no grade right okay so we are going to pause there for this one and we are also going to try to we are going to try to write a um a smart contract using using cyu so with all of these um all of this syntax and this here it's not to sure okay all right so um so we are going to write um we are going to create another uh a new a new smart contract so we know that if you want to do that we use scab can I see your screen you see it soon okay how about now newc 20 so you can see into it and sorry let's check okay have so if you want to write a smart contract in CYO so the number one thing is that yes you make use of thisy that's where all your whatever that's to your smart cont is to be in the le. skyu so let's let's delete this so basically to start a smart contract in in Cairo you need to firstly uh you want to declare your interface you might want to you're going to declare your interface so and to declare your in you are going to write um you have trades so I 20 and yeah okay we already have something like this here so and when you do this you're going to you can put a macro up here and put St net Stace so what are those uh what are those please I can see your screen can you see it now than thank you yeah [Music] so so uh now you define your smart contract your interface you're going to Define it over a generic um States so we most likely we use T contrast contract state so then you know in your ELC this thing so there uh what was it code then you can now list out all the functions that you have in your plc 20 this so number one we have name so for this one you might need to go to where is it yeah see 20 uh yeah 20 looking standard so the interface so the interface that you need number one we have name so name it returns um it returns string so in this place you're going to have you're going to have what name so you see that your name it's a public view return returns view it means there is not changing states now for this one anything that is not changing State when you don't want to change State you take it as a uh you you take it as a snapshot but if you want to change State you take it as a um as a reference so you always start your uh your function with itself then in this place since it is not taking State um it is not modifying State then you're going to use this uh you can see that I'm making use of art this art so this art is representing what snapshot so we don't use string here we use felt 252 right then you can see see symbol also symbol the same thing is going to return 252 decimal it return total Supply it will return um 2 256 so balance of now when you want to take balance of a particular contract you want to take the balance of someone so let's check balance of you take the balance of the owner and it Returns the balance of the owner so this one is going to be owner so in this place you don't use address you use what contract address so everything is a contract address so this contract address that we now that we now put here we have to import it so we say it's in the we use net contract address then decimals total Supply balance of they not have transfer so transfer you are transferring from you know uh from a particular address to we are transferring to a particular address so we are going to declare that so let me leave leave a space here function transfer so just like I have said you are going to use self now for this one we need to what pass it as what as a reference and in this place the contract is going to be see contract state so you can see the the person you transferring the contract transferring to the amount that want to transfer you have it here so after the transfer then you have transfer from so transfer from so the same thing so from Two and and value so this on to is value right so the transfer the both transfer and transfer from the return bull both transfer and transfer from the return bull so the return bu then we have approve so for approve we have spender value and it returns bull of success so we have approve spender value and it Al also returns bull then we have allowance so allowance is uh is a view function right so for for a view function we are taking the snapshot we taking the snapshot and we have the owner and the spender uh we have the owner and the spender so this is uh how you write more like an interface this is how you write an interface in your your smart contract you know when you're writing a smart contract in solidity also you're going to start you mostly you can write it without an interface but you mostly start using an interface then when you want to write the smart contract itself you have um you are going to have instead of uh contract the name of the contract so here you have uh the name of the contract is so then in this place you are going to have a mro that we tell tell the compiler that this is a contract right now going to tell you that this is a contract so the first thing that you going to do is you want to uh the you're going to declare the what's it called storage so you have uh you have stru storage so in this place all the so the things that you want to store your what your state variables so the name the name the symbol the decimal the total of that you want to track then the balance of you have the uh balances not of the balance is now for this one is not as map use um Legacy map so in solidity you have mappings in this place you use Legacy legy map so yeah you know you usually have key and the value so for balances you know you you are using the contract address to get a particular um balance then you also have the allowance the allowances okay so you see that for allowances now in in Sol you make of two two dimensional mapping right you're going to say the mapping of owner to spender the mapping of spender to the value so but in this in this case 2D mapping is simply taking the inut as a t t of the two contract addresses and you map them to um what's it called M them to the to the uh to the owner so that's simply how that's simply how you do it here now the next thing is going to be in solidity you have what we call the what the Constructor right I hope everyone is still with me yes sir yes we're here okay so in solidity we have what we call the Constructor The Constructor is basically you know at uh deployment when you want to deploy include the Constructor so in this L also you have a you're are going to have a function and you call it what Constructor right so and you have you need the macro to let uh the compiler know that sorry to interrupt which intelligence are you making use of I need to know to this is the so to make it know that this is the Constructor so in the Constructor you have a reference to uh to self so the reference to self is going be contrast it then you are taking the arguments that you are taking you are taking the name right the symbol and the decimal so we are not the on setting the total Supply we are not just we are not the setting the total Supply and we don't need the we don't need the Boolean this in our in our Constructor so when you take the name and all those so yeah so you going to say self.
name you can see this is the normal way you assign it uh you assign it in in solity also so we we pass this as a reference to self so s do name equal to name the name that you've passed in s do symbol equals to symbol the symbol that you passed in and S do decimals equals to decimals also then you now know that in solidity we have uh we have four types of identifiers right we have we have four types of identifiers we have um we have internal uh private then what's external and public so these are the four types of identifiers that we have so and this we can see like so we know that internal it means that internal can be called in the contract and also in the in the contract in it private can only be called in the contract external can only be called from the outside and public can only be called can be called anywhere right so but in this case now we are just we are going to divide it majorly into two internal and what external or external or public public so which means external is both external or public anyone that you can call from outside is uh anyone that you can call from outside it's external or public anyone that you cannot call from outside is private so anyone that you can call from outside the way you call them you uh you use a particular mro for for them so you can use either this macro you can use either this macro external for this one you put it in V you can use this mro for it or you can also use um you can also use Ab embed version zero so you can use either of these two so which means that when you use this macro on uh on on a group of functions then you know that they are what they external and of course your your external functions they the ones that you define in your uh in your interface right so which means that we can now implement this particular interface you can now implement this particular interface so since I've already scoped it into using this us super ic20 here then in this place I can just say I can just say Implement ERC 20 implementation uh implementation of what of ic20 now you know in this place we used a generic T contract state so in this place we are not going to use contract State we are no longer using generic Implement rubish okay so this Implement ec2 implementation of ic2 then we have the contast state here then you can now start uh you know all the functions so the first one here is a reference to self and it returns this felt so in this place it's going to be reference to sell you can see so before in this place we using t to den know that it is generic but in this place this is a concrete implementation of of it so here we have self. name this self. name you know we are making reference to this storage here so we now say dot what do read do read do we get so then after this we have uh after the name we have symbol right after the symbol we have decimals so the same thing we are just reading them then the total Supply also total Supply we are just reading that what again balance of so balance of so this one we take the this of the owner so it gives us the balance of so we are taking we are looking at the balances to get the balance of of the of the owner so we are reading that then we also have allowance so allowance is also so yeah so let's just read the allowance allowance so self owner spender so we are reading in the allowances the allowance of the owner and the and the spender okay so the next so we now want to do all this trans transer transfer from approve and what allowances now for us to do all these ones so there are some things that we usually there is something that we usually do that uh you know there's something that we usually do instead of calling transfer we are going to create an internal function that is going to handle you know all those transfer uh and the likes like that so how do we create an internal function this one now is an external function right so if you want to create an internal function there are two ways you can you can just create if you just like write uh the the function it goes you can just if you write any function outside of what you have in that place so the is going to take it as an internal or private function so but if you also want to another way you can also do it is you can make use of this mro we call it uh generate rate yeah so this one you use this for uh for implementing internal functions so for this one now we can have uh so for for this one now we can have let's say transfer we can have a an internal trans an internal function that handles transfer right now what this one is going to do is that we we have want to transfer this is going to change state so where are we transferring we need to look at from from address from which is a contract address to which is also a what a contract address and the value so and it's going to so what this one is going to do is that number one he's going to make sure so there are some checks that you want to uh that you need to look look after that number one the address that you are sending from is not address zero the address that you are transferring from is not add the zero you want to make sure that the address that you are transferring from is not address zero I also want to make sure that the address that you are transferring to is not address zero so how do you how do you check that so you say so number one is you say that let address zero so which is a contract address who so we have contract address constant so if you go through the what C you are going to see some of these things if you go to the uh the KY book you're going to see some of the Constance that you have there so this Contra uh this one now you have to put it into scope so in this place you say use contract address so we also need to use that one also yes we also need to use this also okay so if address prom if from is equal toal to add Z then we are going to ask it want to assert that the address from is not equal to zero Asser that PR is not equal to address Z [Music] so you also want to assert that address two is not equal to address Z you also want to Asser that the value is greater than zero I also want to assert that the balance of the person that you want to send from is greater than or equal to the amount that you want to send is greater than or equal to the amount that you want to send then after you've performed all this check after you've performed all this check then you're now going to say what self. balances. WR you're going to write for the the person that you are taking it from so for this one now for this we can create another internal function simply update to Simply update uh to upate the balance of you know different like that but let's leave it this way so the person from the new balance is now going to be the previous address Min value this one the New Balance now going to be the previous balance plus plus this so with this now and it's going to return true if this is successful so which means that if you now want to implement transfer from here so if want to implement transfer from here we are simply going to so in this place for transfer we are uh we you know when you are using transfer it means that you are sending from your own self so we are going to say that let MSD send so that it's the message send MSD send D will be equal to so this one we we use what get color address get color address so this one now we have to put it into scope you have to put it into scope where is this again you have to here get color address so you know everyone understands msgd sender right yes yes yes so you can see that we are still making use of the solid dig ter so that it's going to be easier so since Ms sender this is how you get your MSD do sender there's no MSD do sender in this place you you do what get color address so when you've got the color address then you can now do the uh you can now do the transfer so in this you know in Kyo you don't use Capital so the hey I'm writing rubbish so you have this then in this place you are going to put your MSD sender in this place so you have two two is the the person you sending to and the value is what yeah so when you just you can see how how beautiful this is the real this is going to uh it is this transfire that is going to perform all the checks and after performing all the checks it's going to you know return true so true that this one is going to return we are taking it here and this one is now going to return it to this one you can see that this is returning so that is how you perform with transfer now the reason we we use that one is so that we can use one so understand so he said that we'll be able to use one one stone to K two BS so if you want to implement transfer from now transfer from so we already know uh transfer from MSD do uh what is it called for transfer from we have you want to transfer from this person to this person and you have this this so because thing that you are going to check before you call this function before you call this transfer function because if you just yeah we just have MS that you want to make sure that the the person has allowance right so you you first that what let allowance equal to self.
allowance from the the MSD sender it has an allowance with the person that you are uh that you want to that you want to transfer from so when you've done that you Asser that you see in solidity you usually do Asser like that so in this place you just uh in this place you you simply uh you don't do r or this thing here for most of the things that you are doing here you are asserting so you assert that the allowance is greater than or equal to what or equal to Value so if it is not if it is not say what insufficient allowance so you need to take note for f you use uh single colon right not double please so insufficient allowance now self then you're going to you're going to transfer from from that person to the two and the value then you're going to rewrite the allowance you're you're going to deduct that allowance and that's all so that's transfer from then the next one is what is approve the next one is approve you want to approve what do you do so if you want to approve a spender of a particular value right so you you the MSD sender you get the callor address of the person that that is calling so you just say that what self. allowance. right for now you can see that here we have the key the spender the owner and the spender they are the key here you have the value here and you return uh bull so that's how you that's how you approve what's the next one allowance okay we've done allowance already so you can see that we've we've written uh what's it called a simple year20 contract now your assignment is going to be to make this more robust you should add mint bone you should add mint to it you should add bone toat and and what again and what again so uh and an additional thing is that you're also going to complete the reading of the Cairo book and you should figure out how to add an event you should figure out how to add event to a contract and you should add events to the contract and what again you should add events to the contract where appropriate you see that if you check the alc2 standard there the events are basically two and they are where you are supposed to use them so that's ah sorry sorry sorry so do you have any question as as regards this I'm going to all right I want to ask a simple question actually um if you want to keep track of um the MSG that deployed the contract how can you actually do that Sor what what are you saying okay I say if you want to you know keep track or you know um yeah keep track of the enter that deploys the contract how can you do it oh okay so for for that one there is a uh there's a universal deployer so in the in the constants so in the Kyo architecture there's actually a a small difference here so because there is a there is a universal deployer here okay de and contract actually The Simple Solution that you can um that you can make use of at the at the moment is just uh just like pass that if you if you need it as an argument just pass it as part of the as part of the variables because for in the stet architecture so there is a universal deployer so which means that the address this might not like work the same way that you want but before the next class I should um I should get back to you on if there is a better way of doing that so is there any other question okay please just talk no okay sorry sorry sir how how do we get a recording of this class because I would personally like to go over it again what how to get the recording of this class in previous classes okay just go on your calendar your calendar the the recording will be automatically attached to it so the cend that you use to join this one you go and check it again after the class you're going to you're going to find itk oh so that's the email we use in registering right yes the calendar yes the email used in reg so just take your calendar okay so um this is where we are going to stop for today so when you do the you should write your contract and uh um push it to your GI and you should send the link to that same email address you send the link to the same email address so you have you have three days to do it you can see can I get this Cod can you get this code yeah so you can just put it in something might be buggy or something okay let me check let me check I can chub right yeah longest time no [Music] this one of your problems with using you might not know how to copy and paste okay hello sir yeah can you guide us on how to install the intellisense you're using the intellisense oh oh I'm using it's copilot activated so I'm using Co so this let me just put it here and I think it was a stickes or is it a okay this Secret update make public okay it's now public s please can you also add the dependency the dependency dependency is just St like this uh there isn't we are not using any external just stet that we [Music] no so when we do we going to get all the things that to yes okay so enjoy enjoy your weekend anything about your your copilot you didn't say much about oh yeah I said I'm using coo um coo you can you can check it out I not be able to get copilot so I'm using the paid version actually so are you the one approving the recording the access mine is restricted am I the one approving the what the access to the record I'm not doing I'm not doing but you should be able to see it like immedately you leave right I'm not the one you can ask the management they going to respond to you request for the access so any question I guess sorry so you say you're using copilot and Co no I'm using C so it already has all this stuff inside it so it's like vs code also just integrated into it and you you can you can put um co-pilot in your vs code also works can we use V code for this Ty of course of course so any other question oh we want to be using AI I thought AI is taking over the it's going to everybody jobless that will take your job using a you can work you can work faster so they don't have to employ another person and you be happy so all right bye guys see the next time we meet thank you good night sir e e
Automatic transcript — names and jargon may be misspelled.