5. Starknet.rs and Dojo
Starknet BootCamp · November 2023 · 1:06:51
GianM introduces Starknet.rs and Dojo.
Speakers
Topics
From Starknet BootCamp, published by OpenBuild; community: OpenBuild.
Transcript
hi everyone welcome back we are in the stet boot camp so this time we want to talk about starets and dojo this is some of the tools that you can find in starnet remember uh we have this GitHub repon where you can find the info about the lessons also this website from open build oh yeah this time we're going to talk about we're going to check the St book and remember before we talk about what do we need to install we talk about St scar Katana we deploy it on testet and Katana so now we want to talk about Starly what is Starly so first you also
can check here the website from STL like I said St is common line a common line tool for interacting with stet so this is like a this is built on top of a stet RS so yeah it's going to be really nice we can find that here so this is a library with on R so you can connect to the blockchain to the to stet using R so this is all the feature you can find it here so in top of start RS we have Sterling that is the C Comm line so I want to check something with st
and so here so the to use St remember before we just to declare declare some declare and deploy some smart contracts but now we can do we're going to check more options what else we can do here so like DI menion St is a common line interface tool the same about star for Star interaction so yeah it use TS to simplify this kind of interaction so we can query and execute transaction on St so first we're going to check some commands and then we're going to create some B script using the Starling to cing on start on stet so yeah this is an
example so you can create your own bash script to interact with stet but this is going to be the really the very beginning so for this we have to open check if you have installed ear or not for so we like this like this okay so here we just going to se in my case I have this is one of the latest cool this is one of the latest version ofly so was fine so I have here so we continue with this so they also mention about the providers there are many providers you mean RPC providers you know in order to connect with the blockchain we need these providers we
are going to provide like a RPC URL to connect our program with the blockchain some of them they are in F Alchemy I think we also have nethermind so you can check there and find the RPC Ur another way how to you know how to connect is with katana is for local de and you can also set up your own note yes if you some of you are interested in this you can check option in our case we're going to test we're going to use these two these two samples first with Alchemy and then with Catana what first with katana let's check here interact with katana for this we have to run Katana remember
uh you have to install Katana first and then run it Katana is okay so Katana is running now so after that you can see you can see here Katana let's put it here Katana here and this is our common light then so for this we can use a starling to retrieve the chain ID so it depends you know this example we want to get the chain ID using Starling so how can we get it so we're going to do like this copy thisly CH and we have to pass the RPC URL in this case we have the RPC and we are going to pass this is the same IPC that Katana provides so we're going to
do do the same here okay ID you have to pass whichc is going to be this one the local host and then great so this is the chain ID for Katana and you can see here this is the Lo about Katana something happen here so yeah they got this method chain ID so the same one we can also check we can use STL to check what is the latest block number on Katana so we can do this we just replace here we have to put block number and then we have to put this argument RPC and the the URL so we can have the St block number and then
we have to pass this argument and then yeah we get zero because we didn't do anything yet here so that's why Katana is still on zero so yeah that's it yeah they say the block number is zero because we didn't declare or deploy something on Katana yet so as well so yeah in order to get this maybe you want to check the block number is different than than so we can declare something here and then uh we can we can check the block number again so this time let's see if I show example here remember our V voting contract let's go there there we have compiled this voting
contract yeah this is our voting contract remember remember for last time we use star hry here this is our voting contract so we have this target this call it oh yeah voting boting contract this one okay so we can deploy this on testet so let's see sorry we can deploy this on Katana and let's see how it goes yeah so let's say we're want to declare this so we are here we can draun St declare we have to pass this Contra class Json file so I have to go Target Target dep and then we have to pass this both in contract contract contract class
yeah Jon Let's see how it goes and then yeah we have to pass the RPC actually have to pass the RPC we have to say we using the katana so we have to pass this yeah try this we have to the account so since Katana is using the default Katana zero let this Z okay great I have declar it so remember uh satana is going to provide you all of these you know redeployed wallet address so here they are asking
for this you can try with some of them here but uh they already have set up this like short name Kat Z so you can use this Katan Z is part on this from this example from this from all of this example preed yeah this one yeah pre preed accounts yeah this is the account that they are asking this one so yeah okay so we get it we declare it and then you can see something happen here they say block one minute with one transaction so it means we supposed to get one block number now so let's retrieve again our previous code yeah we're going to check what is
the latest block number now and if one why because we declare um something on Katana so if we continue doing some more operations like a deploy or invoke calls so you you're want to see that the block number is going to increase yeah this is this yeah same same like here so also they have this if you have a string value pass you can pass Like This Way St Str and you have the string literal that you want to pass in case we don't have a Constructor I mean our Constructor is not going to receive anything like with a string so
we can skip this but you can try at the moment so this is going to you know you don't need to do this two C string to get the ex aimal format for your input you just can put the string like this and it's going to work that's why it's kind of useful and now we can try with test net so remember for test net we want to try to do something like this for testnet we are done with katana so we can close this Katana close terminal yeah we want to clear here for testet we're going to do the same here we have to pass the the RPC URL for a stet we could be Alchemy F any of them so we're going to do like this Starly block
number RPC and then this time we don't have to run Katana we have to close Katana off and then have to pass the testet RPC in my case I'm going to to check here I'm just Al Al I need to get my one so this is one of my May P start in my case uh key show this one so yeah yeah this one so I have to pass like this block number RPC and I have to pass my URL so yeah we got this is the latest blog number now on testnet so you can
see what using go early so at this time this is the latest BL number on goly different Katana yet Kat going to start always with zero body at least for now but now but on this command we're using tet with Alchemy so the block number is totally different yes the lest one is so yeah in this in this example they did it before was this number but right now it's has increased a lot and yeah you can also check the scar scan what is the latest block number blocks can see 918 918 607 606 688 so yeah because we wait for a
let's tip again yeah this is a this is one block number from difference but yeah it's pretty the same so yeah we can check later and see how it goes and yeah so now we're going to try some like invoking invoke commands so for this example let's say we want to transfer some itat from our wallet to another wallet remember before in the examples you have two two wallets here wallets with Bravos and wallet with arent X so they say you can transfer it when you open your brows or your arent uh wallet but you can do the same only with starl it can be a lot easier so what you need
to do they say you have to export yeah need to export your start account and your stet key store so I want to do this I want I'm want to trer from my let's say account my brow accounts so I'm going to score this remember before to do before to do this you have to set up your your account and your key store on the local machine I assume that that you already did it because we showed how to do this on the previous lessons so I'm going to go direct to this in my case the name is a bit different my account agent yeah my account great the second one the key store my key store arent right so the
center is going to be this my arent account so the center is going to be my arent account so who's going to receive the this like a ethereum of course goly early e it's going to be the Argent account so for that I'm I have to pass on this uh commands let's see how it goes first let me try to open this I'm going to open I want to show I want to open this here here I need to get my bra account so yeah this is my brows account so I'm going to P it here okay Darkly invol I want to transfer e transfer I'm
going to P this is the yeah the target address I'm going to send into this how much since this is like a u 256 value I can format like this U 256 and then I'm going to pass a bit more this amount of weight so remember I'm going to I already set up my AR account to send it to my brow account so yeah yeah I also have to wait I have to pass the RPC onepc is going to be this one yeah okay great so we got the transaction has so it means it's working
we can check this on the here on the stock account we want to P this copy oh it's here you see this is the center address so here this is my like Argent account is it here yeah from my AR account to my BR account my BR account is this one 0 D so yeah I and I this amount of E go early it so you can see it's h yeah pretty fast pretty fast yeah so fast and that's it so you can do this kind of transfer with uh starv so yeah it's really useful after that we also have
this handle so the the idea is you know you have to know what are the commands for this and then you have to create your own bash file to run into your local machine so here we can find this example with katana let's clear it do it so quick here for example say this SE provides a step by step instruction to create an custom B scripts foric interaction so yeah we have to Katana is running so we have to open our Katana here katana's Katana Katana is running here
it's good then we have to create a file they create like this touch so remember here create a file and examples we have example yeah examples so here we're going to create right now it's empty so we're going to create this file so let's see yeah we have this file and then we have to edit this file we have to edit and we want to P I'm going to copy and paste this bash file bash content yeah copy so here you can you have to open this file you can use like any text editor could be BS code or
could be any text editor that you have in your computer uh could be beam but now I'm going to use Nano this one text editor you can use the same now keep there so I'm into the Nano terminal say so we're going to press this control shift V and PR it okay I'm going to save it CR s uh contrl X I'm going to exit so yeah that's it let's check if I have let's check what is inside my script so yes all of this okay that's good now we can round the script like this and yeah oh you can see this is the
log on Katana and they say yeah we are we have connected to Katana this is the Chann of katana the latest block number is zero and we need some required yeah we ask for the balance of this account and this account has yeah 1,000 K so that's what our script does so let let's have a look here yeah this is how the bash work so in this case I have this chain basically I'm just passing this and commands on this variable so here I start ID from this RPC we saw it before but now yeah I'm going to paste it here
I'm going to print it here on this Echo like a print that's why I got this Echo and then I got the answer there what is the output from this command the output is the chain ID number and this is the CH number after that I input a second command to get the lat block number I got the block and just print it here the block number is zero and then I pass the account this is the account one of the accounts here this is the first account here first account and I'm going to ask the balance from this account on Katana because I pass the RPC and they say the balance of the account is this one is
1,000 it's great this is one example then we can we have another script with tet we're going to do the same touch create a file we have the skip for testet it's good we going to P this like I say I'm going to use Nano to the test but you can use anyone that you like I pest it okay great now I I'm going to run again oh remember and this time I have to input my testet API URL my T is just check I can find it here somewhere oh
yeah it's this one okay I got it B doesn't yet I'm going to past my URL and also I have to input a transaction hash for example just one we did this this is a transaction hash I copy it here oh and I get this all of this output so let's see what's going on first we read the URL from our tet API URL and then we connect it we just asked for the chain ID of this and the chain ID of this uh poly test net is this one yeah 0 x53 later uh we ask for the blog number
and the blog number is 91 so it has increased from before and then we ask for a transaction has and with the Starly we ask for the receipt details from this transaction so we want to know the receipt details from this transaction so that's why we pass the hash transaction hash and the RPC URL we already got the RPC URL so that's why we asked for the transaction has here I input this one and after that you can get all of these transaction all of the of the details about the receipt of receipt of the transaction yeah and you
can check there and yeah that's it that's it uh so yeah it's at the end is up to you uh how to use Starly how to create your own bash to bash file or bash program to to interact with the blockchain so that's it for now yeah after this we're going to talk about doo do is one of the a really cool Tool uh on Starlet uh let's see how what can we do there okay let's see in a while okay and now we're going to talk about Doo maybe you heard about it before project that
is becoming really famous on the stet ecosystem so what is dojo like they mention here Dojo is a probable game engine and Tool chain for building onchain games and autonomous War so it means like U there is like a framework uh on top of starnet Kyo that is going to help you to build games that fully onch games so it's going to provide some macros from tools inside that is going to help you to develop onchain games cool so this is raply build and deploy onchain games and autonomous war
with doo tool chain so games are defined and governed by the smart contract ex just inter interally on chain and inheriting the unique afford of the BR possible exchange for permissionless ver and yeah this is like basic example on top of that in this case we use Dojo contract remember before we use star contract but um and this time we're going to use do contract we have our module import we Define the in order to define the implementation of our interface we use external PC and then here yeah for example this self word
dispatcher is just on dojo you can use it on on dojo not stet so remember this I just is on with Tojo and this is the macro get the another mro set so this is basic example we're going to get deep into this also some post if you want to know more about what is onchain gaming pro games yeah you you can have great article in order to know more about it for example here we can check a bit more about to architecture remember Katana which is before so actually Katana has been built from do team so also they
have this tool to server that uh is going to index your G your War it's going to provide you some like a graph Q schema also some grpc it is going to be really useful if you want to connect with the front end and also these tools RTC stack RTC and also we have this uh to client so remember from to Tor they communicate through Json RPC and from Tor to the client they said they have gra GPC we RTC and yeah they also have the optimistic situation client side Prov
and from here you can connect you have your entity ID components and yeah you can connect with any FK they provide all of thek JavaScript faer that's the idea also we show this continue yeah from here yeah that's it we can continue so we can check there so we're going to check the book a bit so here also they explained uh what is dojo why Dojo so remember Doo is like a game engine or like a framework that's going to help you to develop your game uh you can check more here the documentation on what is doo
like we saw before we have remember everything if it is on chain everything is going to be a smart contract so this word contract is going to be our smart contract it's going to be like the main SM smart contract on our game and then we going to have like a small smart contracts they want to be like systems and then uh we're going to have some components but they are like modules in this case also modules components they are the same and Tory that is going to connect with the sdks with the front end yeah you can check more about here what is Tory what is Katana what is soo like CLI very realistically to declare deploy
here you to create build test deploy Wars or your games Katana you already know um to you can later it's going to be useful with graphql API see then ecosystem knowledge start start yeah so for this uh we have to install Doo we're going to start with example very soon so what you have to do is you have to install Dojo open your terminal open your terminal okay install dojo and then dojo app so you we going to get the latest version of Dojo right now you can see at this moment is
0.4.1 but later on they're going to release new versions so always be aware about it we want to check we can close this now we can open here we can see for example Katana or t t to version so yeah great we already have um we have this latest version of Doo that's good they also Prov by this manual installation if you just want to build games don't need this it's more like for I mean developers as want to you know improve or solve some issues with dojo
we can play with this but if you want to build games don't need it yeah this is also in order if you want to contribute to the core to the do code base you have to follow thiss if you know R because on the here see the dojo uh this is the dojo base this is the issues so if you know R you can cont it here with some issues and then you can check this this here is mostly R so have a look there um yeah they offer the Discord Twitter even telegram
somewhere you can check some projects there you can check there now the architecture like they mention we have War right here example have War they going to be the core the smart contract so if you're a player you're going to call a system the system is like the actions here the functions it could be like a movement of your uh ler and then you connect with a war so here all of these like a models or components or your data structure that you have it could be your position X and Y that could be your structural model something happens here you're
going to release a event so one event is going to be immediate and to is going to catch this and it's going to send it to the client or to the front end so yeah that's the word it's like a say Central core the models and check the have events they support all of these um methods not too important now and functions as contract methods so you have your smart contact methods they going to be like functions of your system the seed more here like I see models models data your data structure State data your
world data structure and you have to add this attribute in order to you know to make them know this is a model for example like I mentioned before Dojo is built on top of Kyo some examples like they say imag JavaScript and react like a framework do the same so they have the special attributes that only works on dojo like this one model but we can we still can use Kyro have the example of this model there we going to check later more the example some commands get amand of macro Get
Set me config how to we can set up our project the most important part is here we have to add a dependency here like this similar to St F you remember so in this case we're going to add this dojo like dependency we have to show the version also events quite similar like St smart contract authorization yeah we can say we can check later more about it it's like who can yeah interact do the SMART contract so yeah in this case you're going to like say as discuss in the word
chter autonomous War function sub change with the public change this Wars are also open to the public this instructor allows anyone to in face a war by deploying models of system so anyone can contact the war and deploy more model system however this openness also introduce security consideration because you don't want to anybody change game interacting with a model state within a system requires a authorization for a model owner so we are going to set up who can interact with our models so every time I set is call it in system that word checks if the system has authorization to the model so this is
really important important so every time a set set going it's like a write something you're going to change the state of smart contract you call set so every time say this call it in the system the word checks if the system has authorization to the model state or not so for this we have to set up we're going to choose we we have to say this system can update the model state only when the system posess the necessary autorization set is executed execute color execute system set you're want to check the authorization no authorization going
company so how do we provide authorization this is like the way we're going to aoriz like this is p come modify the MS model that's it see this will generate the right response instant to update the model the moves model that's it I also have metadata about your project like this and now we're going to check this and this section so we're going to start with the coding part this is the hello Dojo so we're going to follow this tutorial order to build Dojo so great so decision you doo tool chain
famar with Kao we just to Tool and we work with Kyo few weeks ago so F yeah they talk about ECS like entity component system yeah it's like framework so like architecture like a style how to develop your game this like a it's a design pattern for gaming so in this context system sh the environments logic while components or models M the state of the war yeah the logic is going to be on the system and the components is going to contain the data structures here to about this so first to start let's set locally
on your machine from MTD directory execute this so going to open our terminal first we can set up like that we're going to follow this so we're want to create empty directory going to call it do starter starter uh we going to go into this starter start okay now once we have this we can copy this also in it and is going to create a template for us so we can go from here so okay I'm using visual studio code here we go to here and we
can find all of these files actions models same like here we're going to say we're going to find this um this is all the folders We have Str game actions is going to contain the systems the functions of the system models or data you some helper functions here so do your project K projects primary difference is the inclusion of special attributes STS yes it is like we mention before you see to Define p data models yeah in this context we will refer to these models as components and yeah so we can use models
components we are crafting the PCS remember entity component system we will add to specific ter system entity component system so yeah let's check the models here okay let's check models so first check this moves so we going to have a model call it moves on this m we're going to store the player so the player could be like a player ID so the ID will be like a contract address and then remaining is like the remained steps or moves that it has you have 10 remaining remaining moves for 20 and then the last directions so it's going to move here
see direction is like a no time so a no time it can move to left right up down or by default is know and then can move to any of them of these directions and then we have this like a position position model position model is going to contain the player address as well as a key so this key is important because this is going to help others to retrieve the data from from this structor so you can think it's also like a primary key it could be if you know SQL or databases imagine this key like a primary key in order to retrieve data
from your site also this position and then we have this back two trades because what we have this back two back two stroke so here this like a helper stroke in this case uh we have X and Y so it's going to help as to move you know X for this side and Y for this side so yeah like a after that we can Implement some trait for this B in case if zero or is equal for example function is zero what is going to we're want to check if X and Y they are the same so true otherwise
false and if it's equal so we have to pass another here we have to pass another piure want to check it if both fields are same we have this test where want to check it later test so that's what we have in our models I didn't mention all of these yeah this is like a special attribute for KY special this model this model our mopes model hous a player field at the same time we have the key attribute which for that this model is index it by the player field yeah this how can we index the player how can we retrieve this data um so yeah it's like they say it's going to help
you to query essentially it implies that you can query this model using the player field why because we have this key annotation key ex so yeah position was work and then now we can check the actions file here have the action file we Define the interface simar like Stand St interface going be the same but in this case we Define two function SP and move SP is really common on gaming is like a unit like a you can think it also like a your Constructor or init function that happens at the very beginning of the game and then you can
add more functions like a move somebody is going to move here after that we're going to implement this this interfaces were here inside is we're want to Define our smart contract in this case going to be Dojo contract we Define our mode actions like a module actions we import this from stet fine but also we import this from do samples this sample is our project name actually samples so that's why we can import this position model mob Direction de two that we saw just before and also some U function like this one we want to check it later Al
import the the the field interfaces from above okay now we have this event we have to create the event move it so how is it where when I meet move it if the player has if the player you know did any kind of move you have to meet event showing the player contact address and which they it go now we have to implement the interfaces from here in this case we implement the spound function for this one we're going to need this varable war war dispatcher that's why we we have to access to this how did we get the disater self what dispart and can see is
even more simple here before your Kyo start smart contract you have to build a lot of helper functions in order to get the war dispatcher but here just with one one piece of line one piece of code one line of code you can get the war dispat it's going to be cool then we get the Coler address going to be the player now we can retrieve what is the current position of the war so we can apply this here get macro get command we have to pass remember for position okay if you want to retrieve the position we have to pass a key the key is a player player contact address so that's why here we
pass player contract address yeah so this is going to be the pattern so from the war I want to ret position and I have to pass the key the key is so according to this key they going to search it and going to give us this stru we get this stru here position something is wrong with the plug that's why it looks like there is an error but actually there is not so don't care about this R lines for now here just let's continue yeah I been we we have been here and then we have this moves if you want to RCT the players moves data same this case moves also they require the player as a player
contract address like like P so we pass here great and then if we we're going to apply set so set what's we going to do is going to update the word state with new data set players move Ms okay check here mops so in this case we're going to set this we're going to set these two models we have to pass the model here the first model is this moves for moves for example we have to set we have to add one more we going to set moves is going to have the player contract address okay remaining we're going to set up the remaining is 100 units last Direction because that is not last direction we just we are the spa we at
the beginning of the game so the direction is known in this case for position we have to set up player position here we have to pass a player contact address and then we have to pass this back to data structor B two has X and Y we're going to defy B two set up X like a 10 and Y like a 10 okay so they going to be the init values every time we we call SP want to set up like this next we're going to implement our move function so similar to just before and we're going to call the world dispatcher player the player and then in this case
we can get yeah for example this time get we can retrieve to both models position models and the mops model since both of them they require only they require for player like the key so there is not a problem for that and now we can get both of this position and moves model so if we move if we make one movement so our move our counter our number of moves is going to reduce by one that's why they say here reming is the last value minus one for last direction we're going to get this direction so from you call the up you have to pass that direction where do you
want to go and we're going to set up this here number moves is like a mutable it's a mutable variable so we can this value so the remaining is minus one and the last direction is the that direction we input from our Mo function and then we can check the next position yeah we have this like a next position this is like they say calculate the player next position based on provided Direction so let's check this next position they are in so we're going to open here utils see yeah next position so for next position we pass the the position data structor that we get so this is the current
position but remember this a mutable mutable variable and then we got the section where do we want to go so in this case if you go to left the position is going to going to change the X value minus one because imagine you have your you have your like a mapping there X and Y function so if you go to left it's going to be negative if you go to right it's going to be positive right plus one if you go up it's going to be y + one this and down y + one from me from here yeah x y and go down that's the logic you can implement this according to your
own case this so no problem that we go this next position and set up so actually this next position is going to update this data structure here so we going to be next so we're going to return the position updated we're going to return the the position we pass here we return it after that uh we can check this set we're going to set our work with mops Mo mops has Chang it yeah it has changed it like this and position has changed yeah now this next position Chang so we're with moves data and position and then we're going to emit event imit event with the player address and the last direction right and
then we have the test you can check test then let's go back to the here yeah they explain the event Spa function Mo functionl we have this get command set command that's it so now we can run it locally this is a the funny part of this okay let's let's interact with this oh yeah before that remember actually Cairo I mean dojo this L version they use Cairo 2.4 version so make sure that you have this car this version because you SC you have
Kyo 2.4 same like here make sure you update it to the latest card version in order to compile this um example like I said we have to add the dependency the verion of this dependency and yeah that's it after that we can yeah we have to run Soo I think Soo you can see like a scar it's going to be our C before we did if it is a stet do K Smart contract it's going to be remember we used to do start Bild but we are now in Doo context so it's going
to be so B okay now yeah we got this target file with all of these uh files we don't don't need to check right now so we can do like this okay okay much better so oh yeah yeah but now uh we have to open a lot of terminals because we have to uh deploy and then open the Local Host so let's move to here we are in do starter remember clear in my case I'm going to do this okay great going to open it's going to help me a lot because
remember we have to do also B again and then they say we have to use Katana yeah so Katana disabl oh sorry my tyo okay Katana is working it is a Soo build what else yeah Katana disabled Soo build yeah is going to compile our game in this case everything is fine so it has no errors uh so after that we are going to do so migrate what it's going to do this this will deploy the artifact to Katana you should so we are going to inside here we going to declare and deploy
everything that we need in our for our game so yeah you can use here so migr and then you can give it a name to your project here but in my case I'm just going to make like that or let's [Music] let's start so our warning is going to be a stter this my migration account like my account that I'm using to deploy this remember this account is this one there check here is the same it's a pre funded account so our warning going to be started just like this they call the executor the basic contract and this is
important this is our war address so this is our war address we're going to use it later but also we have to get we get the Clash hash for our moves models for our position models and for our systems we have we get a contract address remember our system this actions we call it actions and this is this contract so we're going to use actually both of these two contracts or word contracts and your system this case I'm I me just have one system but you can have many of them same for models you can have many of them but we we're going to use these two contracts and then you're done and then you can see here a
lot has happened here Katana has happen at least 10 blocks have been mined good yeah you have your more address worke is a bit different because it depends your version they also they say okay check you have this uh version in this case yeah they say 3.4 but should be 0.4 in over case 0.4.1 after that we're going to do the indexing remember we talk a lot about t so we're want to run say open a new terminal and input a simple commment includ your own War address we have to
call to war and pass the war address for this example is this word address like there for our example for our case we have to input our own word address um Tor okay just follow them for example here we can use let's say t War our war address War address great now they expose this to end points especially for the graph ql we want to follow this some example here so the is going to have to retrieve some data that we need maybe some of you have played with this before that's going to
be great otherwise it's not a problem we can check here how to work with this so it's going to show you this website like browser Local Host and we can input we can query some we can make some query and then we can get some data let's see uh for example yeah running we just run this or running the command mentioned above start T server yeah the T server is working Ser on your local machine This Server use SQL light as its database yeah that is also a way how to uh use make persist here your Tory with SQ light you can check the documentation
here I mean on the book you can check that and this is aible accessible with this okay we are on this will automatically organize your data into tables making it easy for you to perform queries to when you run the command you will see something like this yeah actually we did it you can observe that our moves and position models have been successfully registered let's see here you can check here yeah model registered model moves register model position yeah that's it why because we did it migr yeah when we did that migr it register the moves and the position model that's why um they index it here
yeah have register and next let's use the graph uh ID to retrieve data from Models so we can input this um this query so actually yeah we're going to get some data about the models in this case we're going to search for models the ID the ID is going to be movs we want to search about movs okay great so so this is the ID the name we go the class has transction has and when has been created just now few minutes ago so yeah you can see if you get this dat it means your Tory and graph is working so that's good yeah you can something like this and yeah we can useq
to query some values or you we can subscribe to some events and get the the data for example in this case we're going to subscribe is something happen to our entity any entity if any entity has been updated so we're going to be listening to this okay let's copy this copy here this can clean it like this okay now we have this subscription and we are going to subscribe in case any entity has been updated so this time this subscription is listening if something happens on our
game okay let's move to the here so now what we're going to do we're going to use our actions contract address so we have to use our action contact address to start uh to create entities so first we have the models and then because it's the first time we're going to execute so we're going to create entities in our local machine how do we accomplish this I want to put so execute your actions contract address and Spa remember SP we're going to call this spa and inside the spa there is a set you see there is a set and this set is going to write it's going to change the
data from moves and position and graphql is going to be listening to this because inside this set they have a event and you need something uh yeah to publish some data so we're going to see them but we have to execute this command so let's go back to our terminal let's do it here you see I'm using all of these terminals it's also execute and then we have to pass this one remember actions address so so execute and then our function is found and this is like a now we can put the Constructor I mean the input parameters
but spound has do not require any input parameter so that's fine that's found uh okay this trans this is the transac has one more block has been produced more events has been needed yeah here and let's see what happened in our graphql well you see we get this data just now because we execute the spound function entity updated this is the ID this is the key is the EV event ID yeah you can see this is the ID different from this one there are two events and because one of them is for move and the
other one is for position we just have uh created the entities for moves um position great like I say you're going to get this data under graph Q yeah cool and yeah that's that's it inl ID by clicking dogs yeah here we have more options we can we can check we have all of these like buil it queries you can play around with this so some subscriptions they're going to be useful to connect with your client the Ser will provide yeah going to be this has been a basic example now so just have to you try it again to check more talk a more
entities test yeah we can check the test I think we are going to be useful here let's check the test first yeah we have test we have tested the models because the models Implement here this two in this tra implement this two function zero equal so we have to test this two function for example they test this one if we call if we call this um is zero we we have to get the True Value yeah this has to return um a true because in this case X and Y they are the same so the assert can pass so for is equal same we have to pass we have to create a new
value a new structor like yeah this is this is a new structor and we're going to compare this structor with position that one since they are the same so we should should be equal that's why we can run now so so okay this pass equal pass like z pass there is one move test move so let's check here test move so yeah uh this time we have to import our models here this is our models this is also for like our models but deploy it yeah you can see here when we start the test here for example we can set up the contract
address like this really useful we have set up we just passed some value here and we say okay that this is the constant contract address with this value and this is going to be the color because we are doing the testing for testing purpose then remember on this time we have to pass a rate of models yeah position and moves right here maybe you can see we have to pass models array of models we have the clash cash here so here we have to pass the Clash hash remember for position this one for moves we call this CL cash so we have we got the models and now we have the the
models we can Spa our test War this is also util function from the doo cor so we pass the models and then we get the war the word with all the models inside so after that we can deploy our contract yeah remember we have to pass the SOL SOL like this and actions remember also action import action here actions cool action is the name of our module yeah yeah that's it the name of our module um of our system so ation we have to pass it in the class C we have to format it we pass this to and then we can deploy our war
we get our contract address um system contract and we get our contract system contract address and then with here we get our dispatcher Action System so now we have the the system the Action System we can call spawn spawn is like a this is almost same like with it also execute uh actions contract address and spawn so this like this and then also we we can pass like a move after we spawn we can make a move in this case we are going to pass the the right so it means they going to move the right to the right directions after that we're going to you know the system is going to get
updated so we can get the move data from the color so we get a move then we're want to create this variable this is going to be a section type it's going to be to the right side but we're going to format it into F 22 how did how do we get this because we have this our utils no must be here yeah here we uh Implement our in if it is right it's going to be number two so we're going to we're doing this implementation convert from Direction into F 252 that's why it's it can work here so this is like number two now we're going to check the mops mops remaining is going to be 99
why because every time we move some some somewhere our REM remaining is going to be it's going to decrease one number so it's 99 this is according to our logic game we Define it this herea so it's minus one so this should be 99 because it was the unit value was 100 after this we're going to check in our moves last Direction into it's going to be this value two yeah right if it is the if last direction is right so we have toer like this this is for moves now we can check also position for position we
are going to we have to call the we're going to get the value first position which is then new position and remember if we move to the right right is going to increase one this is our if we move to the right going to increase one there is our game logic and why should remain the same and that's it that's why when we do s test it it pass because everything is working fine let's try to move here as well we can call this also execute this we're going to call move let's call it like right here right should be like number two hold it like this I have to pass like call data here call data to okay yeah in this case if
you want to pass the input parameter to your function because Mo for move you have to pass input parameter Mo we have to pass the direction so in this case I I have to make like this call data and then all the in parameters in case you need to pass two parameters this two eight something like this in this case if I do that I got this error because input too long yeah because my function expect only one value not to so yeah that's what if I pass then is also error because I have to pass from Zer to four here I have defin it here from Z to four so that's
why if I input 10 they don't know how how to handle this that's why so in case you want to the your program yeah what I compass for and it's still going to work that's good so I first input two it's moving to the right if I input four it's moving where down so yeah that's that's it remember my playground oh yeah my my subscription is still working minutes ago I received this but just now I got new data because I am um interacting with the with the game so keep updating here at the same time it's keep updating here and here
that's it on these days we are still on December there is a hakone for Dojo maybe you know Dojo Jam so it's going to be nice if you guys can join them and try to build something and yeah uh there are more there are a lot of there are more tool chains here to check out there is also a slot slot is going to help you also to spin up your developing spinning up kak instances so yeah you can check them you can use them there is a tutorial here how to use using slot and you can get your url I'm going to leave this like a homework so you have to show
your deployments with a slot for example yeah your deployment with katana which is your deployment name with katana should be the same of your GitHub user and your deployment name with Tor is this one yeah yeah that's it I think that's all for this lesson let try to to check the book and find something interesting here okay see you next time