3. Development Tools(Scarb, Starkli)
Starknet BootCamp · November 2023 · 1:35:29
GianM introduces the Scarb and Starkli development tools.
Speakers
Topics
From Starknet BootCamp, published by OpenBuild; community: OpenBuild.
Transcript
hi everyone we are in the next lesson from our stet boot camp do you remember last time we talk a bit more uh what is stet we check the the book this is the startet book you know we started here with remix we deploy a smart contract them EAS with remix also we did the exercises with Starling yeah and you have your homework you have finish you know all the exercises here so now we want to talk more about stet the kaido language the smart contracts here in with kaido and we we're going to use a different tool not remix anymore we're
going to use BS codes we're going to deploy with localnet like with katana and tet with forly so yeah but before that we're want to talk more about tarnet and smart contract smart contract itself so let's go for it and yeah here we are here yeah like I said before first you have the introduction video of system then we talk about smart contract remix title starlinks and now we are here so yeah let me work like this much better okay great so yeah this is the process how we can comp our program with kaido so first we have to you know write
our smart contract with KIRO one that is like a version3 right now when we do this when we our smart contract we have to compile and we are going to get some intermediary file this is going to be the CRA file or now it's also called contract class so and after that with this contract class we are going to get the assembly Kyro assembly five so this is like the process we have to go and all of this is going to be you know after this we're going to send this file with to the blockchain to the St blockchain I want to show the example of all of this so this is just for reference and now we want to talk more
about the structure how is the structure of the stet contract we call it like otomy so first we're going to get a contract class so remember this we write a small contract s kaido and then we have to declare a class so this is like the first step we have to do after we write the smart contract we have to declare it once uh and when we declare the contract we're going to get this you know this code on like they say from Kyo contract to we have to compile it from Kyo to crra so this is the first step that we have to do in order you know to interact with the blockchain first we have to declare and this is the first step and here in this file we can find the a function we have like a section in
this Z file when they show the the AI and this is called the class has so this is the process we declare our program and we're going to get a class hash which is going to be you know a hash number and we're going to get a file and this file is going going to include the ai ai content here already mention the class has changes every time we modify the code yeah every time we you know made some it in the smart contract if we declare again the class has is going to be different next time but if we don't change anything on the smart contract and we try to declare one more time we're going to get the same class cash
like we did before so I'm going to explain this also with the code this is just for reference and yeah so this is the first concept uh class clash and contract class and the second concept is the contract instance so this is like you see an inst a deployed is deployed on stet before when we do the declare it when we did the declare it was not deployed it's just like a a class hash you know to take a reference of our need the declare it the CL and with that we can deploy and generate the
contact address so like they say this contact instance you going to have the storage of the smart contract it's going to be associated with The Clash has but you know the CL is the first output from our first uh step and with this uh we're going to get the contact address let's check this example is going to be more clear so remember we can have one class contract of class cash is this one one to three and after that we can deploy our smart contract with this so this can be a deploy a deploy M smart contract this is the instance number one here before we have a instance number two this is the instance number three but
all of them they are going to share the same class C but they are you know yes different smart contract they have different contract address although they have the same functionality because they are from the same Clash has so maybe you can also you know remember before if you have to study Java Java language before we have to create our our class and after we create our class we have to instance our class so we can have as many instance as we we want but the class is going to be almost the same always so this is for a class has one and we have a different one so this is a different program that's a
different class has but same we can have as many smart contracts deployed as we want yeah yeah now how do we interact with the blockchain so like know like ethereum maybe you know we have the read functions and the right functions but in the St ecosystem if we want to you know call a read function we have to you know specify this keyword on our Command we want to call you want to call it's like a keyword to you know to call the read functions and if you want to write something or to change the state of your the smart contract yeah we can call the
invoke so invoke is going to be us it you know to call function that they are going to write they are going to change the state of the small cont we are going to see the examples check it more clear and yeah every time yeah like we we do a invoke every time we change the state we have you know we have to pay a gas G Fe it's going to be a transaction but for calls it's going to be free you can make calls the blockchain as much as you want so free so here again we have the this is the types of transaction remember when we do when we declare program smart
contract we're going to get a class class guys when but when we do in we can get instance and deployment call also we're going to get the instance but most of the time we want to work with this to declare and invoke yeah this is also the overview how the you know stet ecosystem work we have the main pools when we do the validation of the transactions it could be it could receive a transaction or it could get like you know a fa validation but the most important tool here component here is the sequencer so the sequencer is going to take the valid functions is going to order a structure and is going to send it to the pr so the
pr is going to generate small proof we can verify this on layer one with st so here the pro is going to send the you know it's going to make the generate a problem we can verify the layer one matal so doing this process also as well since they are like a tnet is a layer two the main you know the main function of this is like the de going to do the roll up yeah you're going to take a bunch of transactions and do do the roll up generate the pro and send to the verifier on the layer one so continue we're going to check more about the St
contract structure Anatomy here so this is the very basic every time we want to you know build a smart contract in a KIRO we have to add this attribute standard contract module for will be my contract number one number two and inside we have the storage so like we mention here as my contract must have a storage defined for now even if it's empty even if you don't use it but it must be included there and all of these annotations attributes they are always important you know we have to keep the we have to follow the rules in order to get in order we can compile the smart
contract okay yeah you also have a Constructor you have to add the attribute here for a Constructor it can be any value so let's say yeah must be call it Constructor as well only call it once when deploy the contract yeah only at the time we're going to deploy the smart contract we have to pass the arguments for this Constructor in case we have yeah in case we don't have it we don't send Arguments for the Constructor here for for example here they take a a reference mutation of the contract state so we can you know write the state of the smart contract because we pass here A F reference so you're going to check here if going to be bit different if we
only read the function we are going to pass a we're want to define a snapshot we're want to check in the next example for example ah but but this is the events events are always defined as a stru so this is like how a events look like we have to Define here this is also yeah we have first we have to Define here this my event number one inside this en event and after that we have to you know Define this event one that is this so if you want to add uh event to we have to add here my event to um we have to Define structor here my event two so that's the way how St net Works
see the keys we have keys here the keys are indexed and allow quick search requiring the blockchain yeah this is important especially when you want to you know interact or work with the front end side of your contract they're going to be listening to the event so it's going to be easy to to work uh you going to help a lot on the front end side of your project the next one we go to the this um exposing functions yeah like I mentioned before we have the read value the read functions and the right functions so in order to expose these functions we have to add this external d z you know like an attribute and then we
can see a only function or like a view function takes a snap snapshot of a state as parameter yeah you can see the snapshot is this symbol we can see so every time we try to do we're want to define the read function we going to take only a snapshot of of the smart contact St so it means you can IM this like we can we're going to take a picture of the actual contract State and we're going to read it that's it want take a picture of at that moment at that time at that time of the contract State um we're going to read any kind of value
that we want so that that's why here we are symbol in case we want to write here in case we want to write the function it's going to be external and it's going to take a mutable mutable reference as a state so here this is a difference here here we don't have this a snapshop but we have this R so R is going to means like a mutable reference so here we can you know apply some right right functions here we are going to change the previous value with the new value we that we pass here in the arguments well we're want to see all of this in the example later interfaces like another like another different language how also
support interfaces interfaces is actually good for you know good practice so we mentioned interfaces ensure that any contract implementing the interface will expose the given function P so yeah this is like your template or maybe your goals when you start you know thinking about your what your smart content is going to do you can to start with this just you know Define the interfaces that we going to implement later so this is the way we have to call the interface attribute we're going to call a trade I implemented this my contact later so like you can see one more time similar to R language if some of you have experience with r language so we have
this trait so it's the same meaning with r so one more time interfaces has standardized how contracts are call but it's not mandatory but actually it's a good practice so like they also mention like it helps with better integration with existing adds like a tools and that and this is also they say the right way of exposing functions we come you know better like they say only for the implementation block so all of this is some implementation block and on top of this we can you know add this annotation and inside we can Define the the function so this way is much better if we do this so yeah this is a
really very basic way it's going to work we Define external here and external here but this way is much better we Define this on top of our implementation block only one more only one time it's going to help a lot with better maintainability you're going to help you know to the back our contract then another important component here is the dispatcher dispatcher they're going to help us you know interact with different smart contracts inside our smart contracts that's the main meaning so dispatcher are automatically generated from interfaces so yeah uh here for example in this piece of code we just call dispatcher trade a dispatcher but
we did them you know we them like Define like they say is going to get we're going to get it automatically so using the dispatcher the function is executing with the storage and context of a target of targeted contract for example here we are going to pass this is our dispatcher so we are going to pass data address here this is the data address that is different from our actual core is different from our current smart contract so we're going to generate a dispatcher and we're going to you know color function get data function but it's going to be from a different deployer to Smart contract so yeah this is we're going to check example to get a
much better idea of this so like this say library dispatcher I us it to call a function in a stess manner using the storage and context of the current contract yeah we going to use the a current contract but we are going to call data from the different Contra that's it okay so now we just did a quick review of the B uh of the basic uh you know structure of uh stet contract but now let's check more the let's check more the codes U with the real example so we're going to follow this now tooling you know we have this basic installation so remember before we did this the remix you you deploy there your
contract but now we going to install you know the tools that we need in order to to deploy and interact with us as smart contract this time let me open a bit more okay looks much better so there are three famous tools we're going to use one of them is a Starly Starly is going to help us in order to deploy a interact with the smart contract with the interact with stet the blockchain SC is going to help to compile to compile the our code into Sierra you remember Sierra and then also into Kyo andat is like our Local Host you can think like a fever local host or like a
local DEET in order you know it's going to help a lot to connect with the blockchain so yeah we have to follow this installation in my case I already did you can also follow this but we're going to check if we have the version I'm going to open my terminal I'm going to check if I have the staring version do this this way okay okay okay my Starly version Starly version yeah I have this version that's good scar version you know we have to install to open and reopen a new a new terminal in my case I did check if I have yeah I have this version 3.1 good and then the
katana for Katana you have to your but we but time we're going to use only the katana sorry Kat here in okay I have all of these all of these tools and now we come yeah so make make sure that all of this is working on your side Starling version SC version and Katana version otherwise if you get some problems just let us us know how we can help yeah looks good now we have this yeah we are going to follow this tutorial in order to deploy interact
with CYO and St so yeah like I did I I did I already did I apply this commands so then we have this optional part we're not going to check this now yeah just keep it and now yeah we going to use a scar for first time you can more scar documentation but we're going to follow this so with this command we're going to create a of the smart contract so here for example C let me try to let me try to maximize a bit more wait working here okay okay so we're going to go with scar say new we call it my contract okay
follow the same created my contract so here I might find my contract in somewh my contract is here so let's go there CV my contract now you can you know use any you know in order to interact in order to write your programs in my case I have I use Visual Studio codes so I'm want to open this with Visual Studio code so just go do like this code and then yeah I got this so here yeah I got a a template a pretty fine program uh from scar this is the the basic we have the main function we have a you know a different a second function also we have
test here uh the SC yeah we have the package the version the dependency we can have okay let's see if scarp is working well what we can do here is just to build the contract so let's do car build so yeah you can see it has generated this file the SI file in this case so so let's also start test so yeah it has run the test here is working there so yeah it looks like SC is working well we don't need to take too much time explaining this code just
going to delete it and create it from scratch because we're more interested on Smart contracts but we just just you know we just try to play with Scarpa so let's go back to our our book here so yeah like you see we got this like a scar f. Kyo file we're going to write our SM contract here in this file yeah we have the file to integrate the dependency yeah like you can see on this file actually we have to add this dependency all of this in order to really to actually work with a smart contract so we go to the th file and we overwrite this oh no
[Music] see okay we have this we're calling the to the stet this version of stet also we're going to call it here in the in the Target our new values so let's delete this we can try car clean it's going to clean the target much better okay let's follow the okay now the idea is to work with a katana our Local Host so for this we have to set up you know your wallet and your rpcm point to connect with the blockchain but for this time in Katana we have a this predefined uh wallet or account so we just call
like this and they are going to do all the work for us so we have to create a em file and at this content so let's do it now fine um oh okay okay so what we said here we are going to connect to the blockchain with this account this call it K zero but inside here you know it has the public key private key the address but now all of this is mask and J this name and we have this pass the end point of RPC that is going to be our local Katana example here we can rank
Katana just now just follow the katana say old Fe um you can see here it has a lot of pre funded accounts one to three with the you know private key accounts public key since they are on local local host they are not real money but they just P this Json RPC in point in order to work to this so great let's keep Katana running so now to have this so yeah uh we can deploy our smart contract but first let's see how our smart contract looks like so this is going to be our basic smart contract copy and paste here to
the okay this is going to be our smart contract I just call it hello let's say this like our hello War for stet so this first smart contract like we mention it must have U this contract annotation then we have the mode so this is going to be actually the name of our smart contract call it hello this time it going to contain the Storage storage component so for this we have to Define Storage storage and this is one element of this storage I just call it name since this is important remember in kaido we don't have strings it's not
like a different other language what to they have a string but here we don't have string so something similar to string it's like a f fi element so we have field elements we call it like f to 52 so in some way just going to simulate value but it's really limited you only can work with short short like um short stream values you want to see this so yeah we Define our storage so our Constructor we have to you know to set up the values of our elements here so we call Constructor remember we call this rep self we call ref here because it's
the mutable reference of our storage we want to pass the contract State this is like implicit implicit but uh because it's a self you know and then we have to pass there like an argument this value the value of the name and here yeah they call Self name name call Self because it's going to call that you know smart contract storage and name call name because name is the same no the same name like like here and then we call the right in order to to modify the state good and then we pass that this function this uh this argument here uh like before we have to know call this external and get name set name and this
time because it's a get is just only a read function or a function we only pass a snapshot of the smart contract sorry of the contact State we rad the value of name in case we want to change a name we have to Define our set name function here again we pass our mutable reference we have pass the new value we pass the we have this previous value in case we want but I think we don't need it we can try just like this values yeah let's try just like this we have name and we write this is a really simple really you know how many lines 20 25 21 lines of cod so the idea is to start always with
something small really small and then try to Evol improve little by little don't try to make a really big smart contract from the very beginning just try to yeah deploy interact with SM small contact so yeah now we have this we also have here this we call the dependencies or you also have our environment variables so yeah we are done let's follow the book what did I mention yeah we insert this code and then we have to compile so we have to compile this smart contract we have to apply scar build and we are going to check what we're going to get later uh
compile oh sorry SC build let's see how it goes okay it was so quick we got these files oh yeah we have the contract class and the artifa remember this is the this contract class we have the AI some point find it AI oh yeah here so here the AI we can see our function you remember get name here we have like a set name and more we're want to this we're going to use this file later so but this is like the first file that we we get after we apply scar build scar is going to compile our smart
contract good let's follow the the book how it goes after we compile the contract yeah we have to read our environment uh environment uh variables so for this we have to call this source. web let's do it and then we can make sure we have this we already have this uh environment variables we can call it how is the name here T let's see great so you can see our terminal can read that start account is zero so it's working it's good so it's working this now we have to launch Katana Katana
is already launched here it's waiting for us and yeah this is like a we can say the Second Step the first step always you have to build your contract then you're going to get your contract class the second big step is like uh have to declare like I mentioned before in the slides we have to declare our smart contract so we have to pass this file that we got it just few minutes ago so it's like this and this time we're going to use Starly remember we have to switch now before we use Scar and now we're going to use stly declare stly declare and then we have to pass the file
Target Target should be my contract my contract Target should be de here that my contract hello yeah uh contract class yeah remember this is a bit different before it was s Json but now we we use this concept that class when we talk about smart contract so be careful if you have check maybe few months ago you have deployed it you have like you have built compile some smart contract it can be like here Json but now it's contract class from upgrade here let's do it or it okay let's
Analyze This a bit more so you see the important one is here we got our class F this is all all the process that it takes but for us the more important here is if you get this value so it means it's working so that's good we're going to keep it this value we're going to save it later let's check in the book yeah here you can might find some errors you can try to solve it here and then like they say successful command execution you will obtain The Clash has Clash has declared all of these we also did the same we got the different class hash but okay no problem for that so
like they mention consider this hash as the contract class address yeah so it's going more like this but but what happen if we want to declare again one more time we're want to try to do it again declare you can see this um not declaring the class because it's already declared so we get the same Clash has again but what happen if we change here for example let's see um stock storage name rate want to add something here for example we want to add some extra extra value 332 so we have changed the contract um let's try to build again our build let's start to
compile he going to get it has updated these files the content has been updated let's try to declare yeah and you can see now it's a different the first one we got was this 050 but now we got 073 so yeah I just made a small change here but now the the class has is totally different but since we don't need this so just want to delete it I'm going to compile again my my file I'm going to declare again and yeah we keep the previous Clash has great now uh let's move on we have this like a deployant exp smart contract so remember what we did first is car build
we have and the second step is to declare so we call it star declare we got this this uh Clash has now after that we have to do is deploy so remember when we to deploy a smart contract on Katana because we're using Katana here Katana it's going to require what your class house you already have the class house and the Constructor we have to pass our Constructor our example is this time a name it's called and the typ is spell so we have this is the way how we deploy Starly deploy we have the class has we pass the class has and we have the input parameters in this case it's only one parameter is name so it's
going to be stly deploy our Clash H and the name of the of the of the value of the name we want to add but remember let's try to play with something there for example stting deploy we have to pass this here this class has and then we have to pass the Constructor this name let's call it hello again and we got a error so and they explain here why because we have to pass hello is supposed to be the name here the stream value but we have to pass in this way so we have to pass in the F format so we need to convert this short value I mean this short string to a f format how do
we accomplish this we have to call is command so let's do it Starly to string CYO and this case weord it like this let's say the value of name is going to be stet book so let's call it this way uh so yeah now we got the felt format of sted book and is this all of this hash value this is the output and now if you want to deploy we have to deploy like this first The Clash and second the the value of name that this is the value let's do it our way Starly deploy deploy we have to pass the
dash and then we have to pass what this value this F value okay good working here so we get all of these output but the most important one is this one contract deploy it and we have that work no this is the address of our smart contract and this is already deployed on Katana on Katana Katana is working here Katana is working here this is smart contract is deployed is deploy it there on local DEET okay let's continue like I say we got this great so now next step the IDE is to interact with the smart contract we're going to use the read
functions and the right functions with call and invoke so for reading data with call this is a we're going to Starly call now we're going to pass the yeah we just get the contact here so we're going to find this and then we're going to get the name what is the name that we you know Define at the moment we deploy the smart contract so yeah let's call it that way stly deploy oh sorry St call we pass the the address here or our smart contract and we we have to call the function is like a get name yeah see great here we have this value that
is the same with this value so no problem but how can but you know the idea was to read to set the name with a value that was called it stet what is stet yeah here start book that's what we want to see but we only see all of this hash value that it's not e to read so for this you also want to we have to make a new conversion we have to pass to a stream so we're going to pass this Starly pass stream pass stream we pass here stly pass SK stre let's try to pass this one good we got the start Bo let's try
to play with this it might work as well we have to pass the full value great you see we also get this stand book yeah here so if you want to you know to store strings in string values in your smart contract this is the way how you can check what is the real value there if you really want to if you mean to store this value okay it's working now because we just did a compersion with did the parts from this value to this so it's working it's good now we want to modify our smart contract so remember to modify to change we have to call inog we have to to call the the function here
set name so let's do it now stly Starly inoke this time remember it's not called stly inoke remember to get name we have we you know we write call but here we have to call we have to write invoke we pass our smart contract address now we call the selector of that the function that we want to use call it set name set name I want to add I want to change the name but I want to have a meaning there so according to the to this if I input this value this we are going to store this uh string value Omar but so let's try I'm going to input this how it goes so
remember stly invoke contract address uh selector what is the name of the function and we I have to pass the the input argument I want to pass [Music] this good it means it's working so let me call again what's the value okay I'm going to do this start call get name let's see so here it's working I set up this value and it's working here this value this is like on the felt format I want to checking the you know string format I'm going to use this I'm going to copy this value I'm going to delete all of these oh
great so the stram representation is Omar so it's working that's good so yeah that's it now you can play with this and see how it goes so we try to explain with a really small example how to do this how to interact with the blockchain with invoke and with call I also want to show now because you're going to maybe face some errors later and we're going to see what's the error we can face for example what happens if we call if we change here here remember this is our deployed smart contract but what happen if I change here instead of seven I call
nine what do you think is going to happen since this is a contract address that is not deploy yet so the blockchain cannot recognize this address so we can get some error so let's see here you find this contract not found so yeah it makes sense it means the blockchain cannot find this contract why because it's not deploy it yeah yeah so yeah this is one of the functions that we can get sorry one of the error we can get so if you find this error this control not found it could be like um your contract is not deployed uh let's try7 here for example what if I call this get names another contract error here they
just say contract error contract error but I don't get too much information from here but let's check here for example yeah we can check the locks in the atana we have all of these but we can get this entry point not form entry point selector so it means like this entry point is you know the name of this get names so in our smart contract we don't have a a function call it get names we have get name that's why they cannot find here the selector in our AI they cannot find the selector get names so if you find this error and this error ENT point of font it might it means like maybe you are passing the wrong the
wrong name of your function because if you call get name it's going to work good yeah we can also can play still playing here for example let's try to call but let's try to call like this set name set name I don't knowx 55 remember what I'm trying to do I'm trying to call set name but if but what should I do I should call invoke but now I'm calling call so what's going to happen let's see nothing so you see nothing happens why because we are you know doing the we are fting here call should be invoke if we call invoke we going to get a transaction here but we got some empty
empty output so maybe the meaning is like we are we write call instead of invoke so let's do it one more time invoke uh good okay we got this value we got that we got this transaction so it means it's working uh what else for example what is I set name I see that's all sub name just empty set name let's see how it goes oh we just get contact error we don't we don't know what's going on but so what happened here when I call this set name I should pass input argument I didn't I didn't do it so that's why I got this error so let's check here in
the log of katana they say fail it fail it to digitalize param number one so yeah it means like um they cannot read they cannot get the the first parameter that's why I got this error so I have to pass here z x one one one like this and now it's working so like you can see when you are writing your smart contract maybe you are going to get some errors so the the idea is to always analyze why do you get this error you can get some info here from the output of your command or some info here in the Kat logs it's going to help you to Deb your smart contract and yeah we can try many
things for example let's try to declare something that this not exist and like to deare declare this contract here we can declare again our program we have this P but see I change something here I change something here just like this they say no such file or directory it means you are because why because we are we don't have this file here yeah the full name is different so we have passed a wrong P here why no such file or directory so we have to pass the the correct name my contract should be here hello yeah hello that's
it and we get a decare what if we pass on you know a clash has that is not it doesn't exist so let's try this stly deploy we have to pass this this is like our CL has this is the one that exist but let's change here Z and then we have to pass what already C structor is going to be 0x one one one say you see I just got this contract error nothing else but let's check here is a good exception while running this contr here class class F it's not declared yeah it's not declared so that's good so it means we are passing we try to pass this Clash hash but it's not declared so she here
should be e and now it's going to work good and now we got a different instance you know like we talk before the same CL but every time that we deploy we got a different instance different contract address here and then then yeah we can play like this uh I think that's all for the errors with this yeah let's move on let's move on the next example yeah we finish this then now yeah here in the book they talk a bit more the scar and Katana uh this is a hom word for you guys read here a bit more scar a bit more about Katana now we're going to jump into here to here we
have a example and test net this example we're going to run again with scar Starly and Katana and then we're going to run with boly so first to this we're going to find the repo actually it's going to be remember for this example this is a really small piece of code but this time this second example the number of P of cod is going to be it's going to increase so I have the repo here I'm going to send you the link guys I'm update a bit more I have this on my local B this one for example rep CYO this one the ownable stet so we're going
to play with this smart contract the idea is to deploy all of these with katana and let's see how it goes later I have this CCT here already but what you can do is just you know just G clone this repo I'm going to send you the link also later play with this so here for example I have this public yeah I have theable contract here so for this uh we can close this we can stop Katana we can close this example we are done with this and now we're going to open the next example on contract CD okay quote
let's try to clear please clear clear good okay okay it's almost the the same example like before yeah this the example like before but we have more code here let's try to analyze what we have here for example this time we to import this like contract address because we are going to pass like a argument a contract address and we was for this trades try into yeah from the core of the stet so like I mentioned before we can Define our interface for our data we have like a data component
here a data a data element here St so yeah we have a get data say data and this other function is going to work with the dispatcher just leave it like this for now so for get data remember we we Define like this T now yeah this is a more advancing example we don't have we don't call a contract State we just can call this T it's like the trade and it's going to be at the end contract state so yeah we just pass a we Define a snapshot for get data and for say data we call a cell reference we expect a new value here for another functions remember we're going to work
with with the dispatcher so the dispatcher need to take some argument so it's going to take a smart contact address we have to pass this we are going to call some data from this new contract address great and also C the on example we going to work you know the owner of the contract we're going to play with this you know every time we're going to check if this if the owner of the contract can make can you know can realize can apply some can call some functions or can invoke some fun let's see that's why we have this like ownership we're going to transfer the ownership of this smart contract to a new to a new owner so new this new owner
is also as a contract address this function owner just going to just going to read what is the current owner of this smart contract okay we got now into the smart contract itself we call here the dispatcher that we're going to need for example here we go the storage we the storage we have our owner we store our owner our data we don't need this we're going to store our owner our data here now we have defined one event we going to get a stand event ownership transfer ownership transfer in this Cas the same this event and we Define this event here we have two keys we going to
show what was the previous owner and who who is the new owner so every time we emit a event we are going to emit these two values good in the Constructor remember we have this contract State we are going to give a initial owner value so the idea is U the color of the you know the smart contract that is deploying this I'm sorry the user that is deploying the smart contract should be the initial owner we're going to see the example there and we just our data is a fail we just pass the number one here but you can pass any number we can call it U 16 it could be also going to
work so yeah um yeah we have this now we have this implementation block and on top of this we call this external first we let's see here we just like before this is just our get data we just read the value of data but for say data first we have to check like a we call the only only only so it means only the owner can set data here change the state of the smart contract what is only owner should be here here here so what only older is going to do here is going to make aert that the color the color is you know the one is calling this smart
contract this color is the same like our owner that we register before otherwise we're going to see this error caller is not the owner so every time we want to set a data we have to assert verify if the owner okay we contct we're going to send it this we're
going to pass this so this other contract we're going to read we're going to call this function get data let's check later in the example how it's going to work now uh let's talk more about the owner so we have this function as well this is another implementation block so you see different here we implement the ownable data but here we implement the ownable trait so you can call this any kind of name that you like yeah um data yeah here we have this transfer ownership again since is going to change the state of the smart contract we have to pass like this itself we pass the new owner here we
also have to check if um it means who can change the owner the ownership of the smart cont TR only the current owner can do it so it's like uh the current owner is giving up to the ownership of the smart contract so she going to send she going to give it to someone someone else so for this we have this we can read this pre-owner who is the who is the current owner now just read read the owner then we have to write with the new owner so we get this new owner and then we can emit a event yeah this is our event we have defined before above so we emit a event with the previous owner and
with the new owner this is like a it could be like a read get owner or re owner let's call it re owner owner owner here I got this error because I have to change here as well owner read owner my interface here read owner but there might be someone else let's try to find it owner okay I think it's okay should be working now okay read owner yes okay good yeah we we also have here the only owner that we talk before we have some test we want to talk test later next less not now okay we explain about the smart contct let's see if it compiles or
not oh good is working now remember we going to for this example we also want to work with katana so we are going to we have to run Katana so here yes Katana Katana disabl Fe and then we have to set up our environment values I'm going to set up I'm copy this okay I'm going to use the same like before not this not this let me open the other values here remember my example before this was my contract
um I have this uh environment values I want to use the the same for now I'm going to call this I'm call I'm okay I'm going to with this be like this yeah the same okay um now I'm going to read the value Source not let's see if I can read this RPC but I have to read this so my want to clear one more time so okay good now our terminal can read
can read this values so it's going to work so I already did my scar build time I have my value my file is there now I have to declare for declare I have to go with stly declare have to pass the file that this file contract class this contract class in my case is call it Kyo one B2 ownable so let's do it one Target one2 ownable contract class contct class Json great good now it's working is working we got our class house so now that we declare we have to deploy but
remember what is the a Constructor in the Constructor we have to pass address so what is the address of this let's just pass the since this is K zero here we have to pass we can pass this address like um the initial owner is the same like this a katana zero here so no problem there so let's do it see okay later okay I have to do it this way deploy deploy I have to pass the CL house then I have to pass the Constructor The Constructor is looking for a contract address but for the owner
I have to pass [Music] this okay good yeah I got my contact to awesome uh after this um what do we do let's play with this so let me rate some functions there get data let me call the data so stly call this is is leave it here yeah Starly call we have to pass the contract address we have to pass some function here get data data it one yeah remember when we call the Constructor it's going to set up with one okay we can also call
the owner yeah so let's check read let's call re owner uh stly call re owner here read owner owner good so I got this address this is the same address like I have here first so great well well it just they just did a padding with zero that is still fine but the same address at the end okay so it's working my smart contract but let's let's try to modify here the set data remember only owner can do this so let's see it working or not remember if we're want to change something in the state we have to call
in both here at the end we keep the same smart contract address and then we call set data we have to pass some new value let's let's call it 0x 0x see how it goes great it's working it's called get data 0 x22 so it means my only owner is is working well it means the color the color address is this address as well so actually this address is the color address so although you can see I'm using Katana yeah I I didn't use this explicitly this address by using this uh katana but like I mentioned
before inside of this the uh account address is uh this one and this it has a balance it has a it there it's just for you know for a testing so it's working great so let's try to work now with the with the transfer ownership yeah with the Trans ownership or with another contract no first let's try with this other function let's try to deploy one more time our contract and check how this other function work so remember we can keep the the same Clash T but we can let do this
deploy we are going to deploy this we keep our same CL has and let's try to use another different address Aon address is here Aon address is here so we're going to deploy one more time our smart contract but in this time we're want to pass different different owner this he has some contract address that we get there let's see how it goes great so now I have a new project contract in the number two let's try to save it somewhere else contract two contract two is this contract two is this contract one contract one check here this one qu
deploy great so let's click here we have contract one with this with this initial owner with the first one and we have a contract to with a different owner a different initial owner so what we can do for example in this other function we can pass this contract so we're going to go back to the first smart contract address and we're going to pass the second here we are going to still working on this contract one but we are going to pass this contract address to let's see how it goes stly no it should be invoke should be invoke invoke we're
going to keep the first smart contract 04 let check 04 yeah 04 we are going to call now trans other function yeah other function other function and then we have to pass a other contract the other contract is going to be that number two I have to pass the other contract here and then what is going to do it's going to read the get data from this contract remember we just build a Constructor for this contract so when we build the Constructor here the default value is one one so we should expect to to get the number one here so let's do it let working in B another function can get it here yeah now let's try to read
the the value from our contract stly deploy Starly here geta the data is still two yeah remember we just change this on our contract number one but for our contract number two we can we can do the same we just change this this value so let's do stly call let's pass the contract number two this is this one get data great is the is is the number one now um that's how it works but now
let's try something you know um let's try to set data in our second smart contract we have get data let's try to set data set dat I call it like um Z X5 what do you think is going to happened I got an error I got this error so what does it means data executions they they didn't give me that much information data failed actually what's going on here is like um I'm not the owner of this of this contract you see every time that I'm going to try to set data I must to be the owner only the owner can do it but remember who is the owner of this data I mean of this smart
contract is this one [Music] sorry here this one this is the owner but I don't have access to this to this user yeah this is one user that want to interact but I don't have the access for this so uh I cannot change anything on this set data because my user is this one my user this this is my account and this account is related with the with the owner of the first smart contract but for the second a smart contact I don't have the the credentials to to become a user so yeah that's why I cannot make this set data or I cannot even make a
transfer function I'm going to get that the same error so yeah but we can do it with this on testnet so on testet I have my own wallet address and I can play it with the with set data and I can play with theer ownership there but here I just want to show uh this example with katana and how it goes so now let's move to this the same example but with the different environment we're going to do it with goly test so yeah let's stop this now let's stop it let's clear this let's read a bit uh the
book the book here yeah let's into here so now we have to make sure we have the scly um for this time now we have to work with this this uh with arent or bues so this example you must to create your own smart wallet could be a or b any of them and then on that way we if you have that we can play with start go early so we are not going to use Katana anymore but we have to get our wet yeah like they say you have to get bra arent the stet
faet uh you have to find your account and all of these you have to deploy and everything there yes try to follow these rules I'm not going to follow this you can do it because it's a bit sensitive I mean you have to create your wallet you're going to get your C it you're going to get your private key there so I think uh you guys can do this I'm just going to skip it this part but yeah I can help with this with create a signal and everything there so let's say you already have your wallet like me I have my wallet you already have your wallet so if you want to so now we have to create a signal in our uh local local
machine in order to do that uh let's follow this example I already have M but let me let me delete it I can do it one more time it's not a deal clear this give me a minute to delete my okay okay I'm kind of clean I'm going to C this uh let's do it together so let look like this okay so we have to create this local file for the deployer let's just let's try just follow this so yeah it means it got created the file then you we have to to generate this file my my key store so let's do it I'm going to try to follow this oh
sorry here we use a Starly to create a signal the key store from Key deployer we have this my key store one here you can change the name in my case I'm going to use something I want to call it Argent because I have a Argent account here so let's do it agent I have to input my private key so for the yeah you have to open your you know your private key from your wallet I'm going to do it but in a private way okay I I already got my private key you will also can get your private key I'm going to inut my4 great great so let's check the check here so like like they say you you have
to open your brows or Argent wallet and then you have to find to export the private kit I already did it I just I didn't show because for privacy but you just can follow this open your arent look find the the settings export pilot key and just try to copy and paste I copy and then I paste here and then you have to enter a password it could be a a new password for you yes something that you have to remember and then you we we get this new file it's going to help us you know to find the the transactions you have to read this to get more idea
about it uh this is optional it's up to you about architecture what's going on there with the private key public key small wallet address yeah I going to leave it for you there and then the second step you already got this key store file you also need the uh a con file so for this the same we are going to use starl to fetch our Argent wallet to fch our Argent wallet here start fetch we have to pass our smart wallet address in my case my smart wallet address is this is this so no problem
for minutes and this my my wallet address you have your wallet address and then we have to pass this let's copy this okay uh here we can find we can change the name up to you in my case I like to call it ad they're going to know why later arent okay I have this what happened here way oh I think I have to read my RPC output wiress my account
output deployer let's here I think we cannot use the yeah we have to pass a RPC here and so in our case uh let's jump here and let's jump into here oh yeah this now we have to pass the provider before we cannot use the you know the the current sequ Gateway so I have to choose a provider it could be any of them I can Aly Che maybe if you remember if you work with Sol before you
have to pass wherec URL so for this you have to create a Al account or in F and pass the the provider there so in my case I have mine uh my my provider I can show this here dashboard so for example this is the provider that I use for testnet I can check my API this is my ke I'm going to copy so oh okay yeah let's TR one more time but I have to pass here the RPC let's let's
follow what RPC what's the name of the parameter RPC only RPC and have to pass the provider like this go great so now yeah before you can do like like this but now since uh the sequencer Gateway it got duplicated now you have to pass your your own RPC URL here in order to deploy something with starl okay again that's good news there so now let's see U let's let's go here let's see what do we have here uh CV so now we have these two
files that's good so with these two files we can sign the transactions and we can interact with the blockchain so awesome let's continue working on this this is a book oh this is a stly book you also can check there we're going to follow this remember yeah we did this we apply this command now we can jump into here yeah the account and the key store so now like before we have to set up the environment but this time it's going to be according to your file yeah your local files here is my account one but in my case is clear I want to clear this
it is my arent and my arent so I have to copy and paste this and change it with arent so here I have the environment file I have to change it with this this copy here this Bravos I have to change with my loc Argent arent Argent Argent okay and now I have to pass as well the RPC provider this is the one that I use you have to get your own from Alchemy so you go to you create your account in alchemy and just find theet early uh API that this is mine like I mention
yeah so I have this I have this great now I have to read um The Source em source and B let's call it this okay s em B let's see if this is works great now this variable is pointing to this file not like before it was pointing to a katana but now it points to this file so it means working so now let's continue with this what did I say yeah let's jump into here yeah it's pointing there now we have to SC build and declare export we already this this
declare yeah same like like before we have to build and then we have to um declare declare with our um RPC let's see let's SC build one more time great is working SC no Starly declare Starly decare uh we have to pass the file should Target de is this kind contractable contract CL Json yeah I think we also have to pass the RPC RPC is which one is this one I'm using let let's try like like this first how it goes yeah for decare they don't
ask this but for deploy they are going to ask for the RPC okay I got this Clash hash is declar it uh now according to the book I I I should deploy now declare see according to URL recogniz okay okay you can read all of this to get more idea I'm just going to go to the point we got the Clash C The Clash hash oh we can check this on SC scarc yeah let's open scarc let's see if we can check here this contract this CL has
SC for example here I have to change plus go for this go no F no f um testet test search here let's open from here deing component wait let's one more time otherwise yes let's check later then code CR yeah it's not fully declared we still
have to proceed let's let's move on now is this here uh yeah toy contract deploy let's deploy first and better we check the Clash the contract address after we deploy so for this same we have to deploy pass the Clash has and the Constructor inputs so let go for it start deploy we have to pass this this and then what is the constru here the Constructor is we have to pass the
owner in this case I'm going to pass since I'm the owner so I have to pass the address of this here my account you know I already set up my wallet with ar so I'm going to pass the my my wallet address here let's do it my wallet address is this okay I want to pass my wallet address that should be the same like the one I you know link it here uh let's see how it goes great it's working now let's try to find this on car it might be there let's see let's see here wait this car here sech here here take sometime let's take to
the other boaga take with boaga boag okay here go early let me try this okay it found it here with so like they said yeah I just Vis the date go it transactions events message account calls read contract write contract yes loading but yeah yeah now
it's working here my my contract let me try with the other one I think my class Cas also might be here what is my class Cas uh let's try there in BO boly let's see if they can find it oh they found it here and you can see is class it's different for contact address they call contact but for this class cash is class and that's it you can see the AI and The Bu code here uh great so try to find Bo next time you want to explore the transaction let's go back here let go back here okay we have this we have this working there so one
important thing also is you can check now we don't have the logs here remember in Katana we have some locks in this part we don't have the Lo here but we have in the uh here in the Alchemy we can go to here to our response yeah we can update this to our latest responses was on so you you can find the loocks here of what going on you can see this success success just a few minutes ago what we did so in case we have some error you also can check this logs to tr to the your smart contact so let's keep it for now like this okay let's follow
the book for the book will deploy this they have the Clash has and the wet address like this come so to interact we do the same we call the get owner and let's see how it goes let's have to do it stting call our this our contract address and then we call get data that's our name or no yeah g data one and then read owner yeah we also have read owner here owner great this is my wallet address and the owner that's good so I also can try to change that here let's
going to try to invoke invoke there uh read owner yeah read owner I try to set data let's call it 0x0 no 0x 555 I got to input my password great they did it so quick so I update the state of the blockchain I can see here in BO I have this I'm going to check this transaction what's going on this transaction okay this address this hash is related to a transaction it's already seted on L2 so it's going so fasther just a
minute ago I spent all of this the let's wait for minutes in order to to pass to be affected on every one um okay okay okay okay so like you see we have set the data we interact with the blockchain on test name here this is the transaction hash that we get you can see it's easily so quick aced on L2 but it's going to take a a few minutes to be aected on L1 and yeah it's like this
actually so no problem for that as long as it is accepted only to we can work so great we have this We call we apply this call and invoke owners owner so now let's try to do something different so we have to let's try to deploy a different contract and no a new more a new more smart contract but with a different owner and remember when I deploy it then I deploy it with my own with my wallet address from AR this is the same like this like the owner but now let's do it one more
time but let's use a different um wallet for example I'm going to use brows now so I going to provide a different smart um smart wallet address so but for this we also have to you know we also have to store this values for brows here so I'm going to repeat the the same steps like I did before so so let's read the book what should we do um remember we have to go back in this time to the book I have to create I have created this but I'm going to create one more time one more key store but this time is going to be for my bra
here call it bra bra they going to ask for my private key I'm going to pass my private key you know you have to do the same but in a private way I mean okay I just got my private key I'm gonna P it here I need to inut a password it can be any password a new password for you but you have to remember great I got this file now I have to go this fetch I have to fetch like this okay this this account here I have to pass the my wallet address but this time from Bravos
so from Bravos this this one okay this is my wallet from Bravos going go here BR okay I like before I have to pass the erpc URL and for the urpc it can be the same no problem for that I'm just going to use this can be for everything yeah bra good I I have this so now here you see I have my account for Argent and my key store for Argent my key store for brow and my account from brow all of these two I need this two in order to interact with the smart contract here because I going to lose I going to give up for the ownership
ownership of the smart contract from here but I have to set it here to the brow so let's see let's see how do we do Starly deploy this not not deploy let's call this function now let's call the function transfer ownership okay I'm going to transfer the ownership to my bravoos account so invoke here so this is my Argent account now the you know the user behind all of this is my owner my is this one here this is my AR account this is going to invoke the smart contract and this is going to tr
you want to call this transfer owners is going to transfer to my brow account my brow account is this one I oh my brow account is this one okay this is my brow account I'm going to do it I have to keep I have to enter the password for my ar.com let's see how it goes great it's working so now if we call the owner call read owner you can see this is my brows account not like before we have before we call uh owner it was my arst account but now it's my brows account so if I try to set data what's going to
happen let's try to set data say data let's call it ask for this I just got this error internal error so what's going what's going on so like like I said you have to check on your provider here on your dashboard what's going on try to update it you're going to find the answer then you have this WR response and you can see here this one caller is not the owner so it means yeah because it's true actually what we try to do is set data now so if we want to call this set data the owner of the color of this um function should be uh this address but now who is the Coler
the color is this the the Argent one so now we have to change we have to switch our environment variables so use the Bravos uh account that's why I have this here my Bravos yeah it's working there let's change it here on copy yeah really here so what you can do is this you can create a new variable here MB I can call it two M2 so here you just have to change the with your local Bravos great so remember you have to update the variables here s let's try to call
this so okay no no no ah remember I have to update with M2 I did it to M1 should be M2 okay this one this file I want with this file and great now I can get the BRS remember you have to create a second envirment file and update with your second account is Bros in this case so now the color will be the Bros account and the BR account is the owner so it can change that data so let's do it one more time invoke we have this smart contract data with 77 awesome
so you can see I can now change change the the value here the state of the smart contract but for this to accomplish this I have to you know have to know all the credentials for this this wallet address for BRS and AD so good that's good now what we can see also we have to so who is the owner of this we can check again this is the brow account read owner so let's go back to the let's say okay now I want to give this ownership to the first wallet address to the Argent account so let's let's try to do it now we call against transfer
ownership transfer ownership but I have to pass my arent account my arent account is here so yeah transer ownership to my arent account let's read the owner wait let's invoke it's GNA take few minutes for this so okay on let's transer ownership here so now what we can do is let's let's try to deploy a a new contract we're going to see he going to get a different contract
address so let's try to deploy here one more time try to deploy but with our with our brow account we will deploy it with our with our yeah but let's save this contract one yeah let's do one more time this we're going to save our contract one remember this is our contract one here contract one now contract two let's try to deploy our contract two with our brow account for my brow account um I have this this I'm going to get a different account great so I get now this contract contract address U let me save it here
in case okay I have the contact to so from our contract two let's call our contract one so what we can do is this let's see if it is working here let have to call call let's clear I think let's um stly call this new The second contract and then after call we have the get data we have this it's one now we read owner this one this is the same like my my wallet my active wallet so that's fine good after this so let's call the
dispatcher let's call it one more time remember we have this function here other function we have to pass a smart contract and the dispatcher is want to call the the from from there so let's see St invoke called St call this read owner should be dispatcher here should be transfer other function function in this other function like you see I have to pass the contact address pass the contact address from the first one um yeah let's see how it goes great so what we can see here remember so the
dispatcher what what is doing is working here is going to read the data the value of the smart contract number one so it's calling this get data but from the smart contract number one because from our smart contract number two we have the value is one but for the number uh sorry for the second smart contract with Bravos we have the value is number one but here we pass first SM contract and we actually get data there and it is 777 you remember before we have we set the data here we set data to 77 here to
77 and it work so now we call it from our second smart contract to the data there so yeah that's why how you can use on your SM cont and yeah I think that's that's all for now of this lesson we did a lot we played a lot with the smart contract just try to to do the same follow the steps try to get some error try to understand what the error the meaning and practice in order to get more familiar with the with this way to interact with the T okay yeah I think that's that's all for now see you next time