# Loki Code & Events in Smart Contracts

- Channel: [ETHCluj Meetup](https://streameth.org/ethcluj-meetup)
- Date: 2024-10-09
- Duration: 36:42
- Topics: ethereum, ethcluj, eth, ethereumcluj, developers, solidity, decentralized, Loki Code, smart contracts, events in smart contracts
- Watch: https://streameth.org/watch/yt-x2GW4yayIN4
- YouTube: https://www.youtube.com/watch?v=x2GW4yayIN4

## Description

In this presenation Corches Sergiu & Catalin Balut are covering the following subjects:

➡ How to leverage the potential of events in smart contracts
➡ Exploring the potential of Loki.code & the Remix.ide killer that have revolutionized the Ethereum development

## Transcript

hi everyone and thank you for joining uh today we have two speakers Sergio and Calene uh Sergio will be uh will do an introductory talk about using events in smart contracts and Calene will talk about locky code a new ID that can be an alternative to the wellestablished remix ID yeah so um Serio are ready you can if you find the screen sharing button please I don't know do you see my screen or not yet I think Alex you need to stop your first yeah I stopped M try now [Music] um but it appeared that was disabled attendance screen sharing uh okay try now yeah now I think it's fine um do you see my screen now yes all good okay yeah today I will discuss about the leveraging the potential of events in in smart contracts yeah uh in solidity events are a way to log and notify external applications such as user interface um or other smart contract about uh specific urance within a smart contract practically uh events uh serve as a mechanism for emitting and recording data onto the blockchain uh making it transparent and easy easy to access to access the data events um are similar to logs or records uh that um capture important information and um allow external observers to react to them and obtain uh relevant data from the events uh the events are stored on on blockchain as part as um a transaction history and can uh can be retrieve um an event after a transaction is complete and after a transaction is complete practically we will have access to the data from the events um the key role of the events is to facilitate communication between the smart contract and uh the uh and their user interface by allowing a smart contract to record uh execu transaction and significant uh State changes in an easily manner uh yeah events are are um crucial we can say for decentralized application uh for tracking transaction and updating the UI in a real time and monitoring contract interaction the the main event the main advantage of the events are uh that we avoid the avoid pulling uh that means the application don't don't need to to make constant query to the blockchain to get the data they only react when the events are emitted on the on the blockchain also um events in smart contracts uh particularly on the platform like ethereum are most um most gas efficient compared to the other method of storing or retrieving information from the blockchain practically storing data on the blockchain is the most guess inefficient operation in the smart contract um yeah and uh we can say that events are designed for offchain application uh to eff efficiently monitoring and react um uh to the contract activities uh how events work and how we can manage event uh how we can work with the event inside the smart contract is that we have some keywords when we want to declare an event we will use the event keyword followed by the event name and the the event parameters also emitting event uh for emitting event we will use the the emit keyword followed by the name and the for uh the parameters practic um um this practice notify listener of a specific action that taken inside that took place inside the smart contract and also here is an example of an entire flow of how we how we can declare and emit an event inside the smart contract here we we have an event Test smart contract and also a function uh named transfer to which emit a transfer a transfer event yeah um solidity event uh part parameters uh come in two varieties uh this means that we have some parameter which can be indexed or non-indexed what mean indexed events um we use indexed keyword for the parameter inside the events uh to allow an efficient an efficient searching and filtering the events uh from the blockchain and this is crucial for the external applications or for for the centralized application that need to quickly retrieve specific data or the specific event from the blockchain also we have non-index event uh non-index parameters inside the event inside the event um this um this parameter is hard to uh to get outside the blockchain because uh we need to decode the data because the the data which is not indexed is emitted on data field inside the transaction log and we need to decode the data from to get the the the UN unindexed event uh indexed events are generally used by the developers uh since they make it simple to follow the the occurrence of a particular events inside the smart contract uh yeah here is a trans section which an emitted event name transfer uh as you can see here we have a topic array the topic array will contain all the the index events uh as you can see here we have the two address and from address uh as an indexed event and um uh for the first topic we we we have the hash of the of the function signature which is is a cheak cheak uh check function used for for get the hash and uh for non-index event we will get the the data on the or we will get the the value on the data field and also we can uh we can check here uh on real transaction from the blockchain which is the the transaction from the presentation and here we have the the data which is emitted through the the event yeah I will go back to my presentation um yeah the the events also have some um some limitation because um um yeah this one uh on an event which is a name event which can only emit three indexed parameters and for an event which is an event uh which is anonymous uh we can only emit for for we we can emit four indexed parameters also we have some limitation uh that specify the ma maximum amount of the parameters we can have in an event uh this is a snapshot from the from the solidity compiler which uh which say to us that we cannot emit more than 16 um uh 17 element inside an an event also this 17 include the parameter which is indexed and non indexed yeah for getting the data from the events inside the um an application we can use here is a an uh code uh in JavaScript and for for getting the data uh uh we need the instance of the contract and uh also on provider in our case here we use the the Alchemy provider to interact with the smart contract and uh the API of the smart contract and uh the address of the smart contract uh for which we want to get the events and in the right side of the of the slide we have the ABI which is practically the Json format of a of an event yeah uh also we have web providers uh which facilitates communication between the the application and uh the blockchain um yeah um infura offers a SE of blockchain developers tools um and INF structure to access ethereum network ipfs or other layer to solution and provide for developers some apis that can use to send transaction interact with smart contract read blockchain State without need to run their own node yeah Alchemy is also similar like in fura and provide a suite of tools for for developers and uh Morales provide also a backend infrastructure for uh building uh decentralized application and is designed to streamline and process uh streamline the process of developing the decentralized application by offering a fully managed serverless solution that uh practically handles many many of the backend task automatically practically we can use um Morales to get events in real time from the blockchain also we have uh some libraries to interact with the blockchain and get the events which is web3 jazz and ether Jazz uh that are both JavaScript libraries that allow developer to interact with the with the blockchain and also here is a decentralized solution um the which is the graph which practically a is a decentralized database uh who who keep uh data from events for us and uh uh practically the graph makes uh possible to query the data that is difficult to query in the direct direct way the graph uh defin subgraphs which specify how blockchain data is indexed and how can be query using graphql and yeah data is processed by a decentralized network and as a key concept we have have a we we need to define a yam yamal F schema that describe how data is structure a graph API enables develop developer uh to query data and uh we also have a decentralized network that consist of participants who ensure that the data is correct indexed and the queries are efficiency proceed process benefits for for the decentralized application is an efficient data retrieval and decentralization and flexibility and uh uh there are a lot of application who use the graph also the sandbox or the openc use the graph for foret the data from the blockchain and and put in in their application yeah uh this is this was my my presentation thank you and if you have any question question feel free to ask questions uh what's your favorite uh goto for uh for yourself um like Morales or the other two I'm just curious of it just because of the sinly depends what what you exactly need because some web through providers have some stuffs other don't have some stuffs and depends what what you need in in your application but my my favorite is Morales because they also have some some apis for get let's say you need to get uh all nfts from a collection you only you can go and put the nft collection and so stuffs and you get all the data you don't need to to process any data they process all the data for you all right so it's the fact that it's like real time and pretty much automize the fact that you prefer to work with this particular one right yeah yeah exactly do any of you have any idea if uh we have any other Alternatives similar to Morales eventually or yeah there it's a lot in this moment it's a lot of web providers like Pok Network they also have some some provider for the node for the PC stuffs also calent have have some stuffs related with the getting the data from the blockchain and process some data and uh yeah we can use like like I said depend what what you need in your application right so Project based yeah exactly and some web three provider doesn't cover all the chains because they cover the main chains like ethereum binance polygon the the the ch who have a lot of user right okay thank you I also have a question how how do you decide or uh what do you take in consideration uh when you I don't know how you establish uh if you want to store something on the blockchain or you emit it as an event for example if you're holding data in mappings or arrays or you use events uh sincerely events are a a way to to use uh less gas when when when you speak about blockchain we we think about money and in our case the transaction cost so money and if you keep the the data on chain this means you keep the data in mapping or something like that this cost a lot because you need to to make some stuff uh behind the scenes which is the ethereum ethereum VT machine and you you you need to to store the data inside the the blockchain and also when you write on the blockchain you consume guess and uh the reason we want to to use events is that we don't need to to write anything in the blockchain you only need to read the data from the blockchain without keeping the data uh onchain you only get the data in an offchain way okay thank you great other questions [Music] anyone okay in that case um so our next speaker is cathaline thank you ah thank you Sergio of course thank you very much um and uh Kina are you ready to share your screen oh yes um I hope you see my screen y okay so today I'm planning to discuss you about Loki code uh I saw it was uh deployed the first version like um one week ago so I think is uh is a good idea to start taking a look as a developer also on this um uh on this project uh for for first of all for those who starting to build on solidity um and they don't know how to start everybody on blockchain is using remix so remix allows you to um for example okay I have multiple contract AG here and uh it it allow you to um compile a contract and decide um uh what version do you want to use to compile it uh if you for example import some smart contracts that let me see I don't have something like that here not at this point but if you have a smart contract that also have um some imports like open zpp in libraries that everybody is using it's so it's nice that it it also import them so you can deploy a smart contract with multiple libraries uh after you compile it you you are allowed to deploy it it it cool because is allow it allow you to uh to deploy on what chain do do you want also you can add your um API if you if you have already deployed a smart contract and use the interface from here and um what I found on um lowy code it's an alternative to um remix at this point I don't think loky code has the same potenti remix but I think on the on future after they develop more this project they will they will have a strong alternative to remix for the teams so they allow you uh this is the website of the Loki code um they they allow you to the same thing as ramix to compile a project um unfortunately at this point as I saw they um allow you only to deploy your um your smart contract or only on this chain so you can't come with your RPC oh it it's interesting that they made some connection with GitHub so um if you have a project with multiple um team members you can connect the GitHub here and work together with the with the GitHub and for example another use case that I observed um for when we when we do um audit we have to allow the the Auditors to our GitHub now it's not anymore necessary we can just import our project here and they will do the um they will do the audit or directly on the Loki code um what I wanted to present for today was a complex project that I work or Marketplace and I wanted to to upload the project so after you going you log in uh it will uh show you your dashboard here you have an an easy tutorial video about how it works and uh here at the this learn part you have multiple tutorials with what you can do at this point uh unfortunately it have a big problem from my side it can't compile smart contracts that have Imports like as I said on remix open Zine so it compile only unque unique files which is an issue at this point because probably all the pro complex projects have multiple um Imports so you can connect your wallet you can connect your GitHub we can we will play a bit with the template so please choose what you would like to deploy an nft or a token let's do a token for etherum clu okay so as I saw there they allow me to um create a um token which um okay so there is some alert that I will ignore like all the people do on blockchain okay so they have two uh it's it's an interesting part uh this one where you can uh use templates at this point you can use only erc20 which is the cryptocurrency normal token standard uh as a template or the nft template but it has po potential to I don't know extend the this part and maybe um maybe create more complex templates that will allow users to directly deploy their own I don't know Marketplace or Farm or swap pool directly so it has a lot of potential this on this part okay so now we will deploy um an um token okay I will name it [Music] close Okay total Supply I don't know how many I will set it to 10 okay it will not be burnable because I don't want and um where is it where is it okay it it doesn't appear here I don't know why they have um they have an integration but interesting is not here what are you looking for uh they have an integration name be um which allows you to Fork um allow you to Fork a blockchain entirely and it was an interesting inter ation to but I don't know I don't know why they don't have it here at this point H interesting okay so if I'm try to deploy a simpol probably probably I I don't think they will give me the funds so probably I will have to take with the faucet okay okay so I'm using rby wallet they um make make me use test Nets okay and I have an error deploying the smart contract because I don't have any funds um okay I will get the seat phrase and set so now I I will just take some funds to deploy the smart contract if this allows me I'm not a robot yes or I am please sign up okay I think he has some connection problems let's give him five okay okay can you hear me uh yes but you you're breaking up and uh I had some problem with the internet do I still have the share screen on h no you have to reshare again okay just a second okay I'm am back good now I have to choose some rabbits because I use rabbit wallet funny right okay now I can no be yeah so that's the name of the uh this this is what I said um is not what is so this is their website they the ly code have an integration with build bear with build bear they allow you to create a Sandbox practically just a fork of all of these oh my God okay so a fork work of all of these um blockchains and directly use directly work on Fork so I think it's a it's a good idea as the the last test for the smart contract is to do it on the directly on the copy code of the environment that are you interested in for example for ethereum you don't pay um to deploy the last the test the last test on ethereum you just create a fork of ethereum and if everything works fine there that means you can definitely go on ethereum and you will have no problems that's with the build bear now I will take the funds okay lovely now I have the funds and let's go back to okay and now let's deploy it what's your problem here please turn on enable test net under more before sign okay more enable test NS No it should allow me yes okay so it cost me 32 fake dollars and I will deploy it the the coolest stuff I saw on Loy code uh until it's going to be deployed uh let's jump to okay to this um video so um when you compile and deploy a smart contract uh it allow you it's it's very interesting it allow you to to see the history of the smart contract on the Loy code so for example if off come on go back go back so here if you if you are working as a team you can see you can see not only the GitHub history as we know as commits but also the deployment of the commits and the actions on on the OWN on chain um on that smart contract so basically you have a history of everything is happening on that smart contract even events deployment um and actions through the smart contract which is a cool thing and um the cooler stuff I saw I observe that um there is always an issue between blockchain developers and uh front end web uh front end developers because um they have um trouble to inter interrogate with uh intergate the blockchain probably something new for all of them and they use they have um this option uh where you can see JavaScript U I saw on the official um official uh video that you can see the JavaScript code of the functions or the typescript code of the function so you just copy the code from here and you can use it in your app directly they also have the implementation for um web 3GS and um atgs the the known um the known libraries for this so I think it's an easy is an easy way to to um as a middleman for between blockchain developers and uh front end Developers for me that I'm not good frontend developer I'm using this so I'm just copying the code here and paste it in the front end okay now let's see if our token is deployed as I see it's [Music] not oh it is but it have no reaction okay I expect it to move me somewhere um yes okay so I had to use template from here you had the the transaction approved so they FR yeah I know I know but I don't know why uh I expect it to not just to be deployed but also to allow me to to show you um this um this part when where you where you can see the uh the functions but I I get I guess you get the point that you can take the functions in uh JavaScript directly from the directly from the uh Loy code and this will probably allow you to understand better as a front developer what is going on on the black box of the smart contract so that's all I wanted to present um yeah actually I thought at the first moment that Loy code is better than Rix e at this point it's still U um not but it has a lot of potential with the with this um for me at least with these two Futures that uh it's it's about the templates that will allow you to build maybe uh bigger things than nft and also that part where you where they transform directly for you into JavaScript code for example some functions have a complex uh signature with a lot of structures arrays and so on which is sometimes hard to write it on JavaScript so just you came here and copy copy the code and you're good to go oh thanks that's all from me well thanks Ken so any questions uh I have a question related with the build beer you said that uh they made a for for the blockchain this means they get the state of the blockchain and translate the state in a local network I uh I don't think they are taking the the entire like the fork just as an the AVM fork or the not Fork not the fork of the um how to say it from the Genesis so just as everybody probably knows there are small different differences between ethereum and Avalanche for example and so on so probably it helps you with the fork it helps you to um to see these differences directly on your smart contract but not not the transactions itself okay okay okay I understand thank you and about the Imports um do you know when they're going to add the support because it's crucial no at this point I have no idea about this I observe it only when I test it u i I saw their official launch they had they don't have this problem because they just invented an ERC a simple ERC but yeah probably uh this is the main thing they have to solve it uh in in future because it's impossible to to run real projects on locky code at this point yes they they seem to have some interesting idea for features there are not available elsewhere so probably they're going to develop something yeah exactly they they also this was the the free version they are coming in the next months with the pro versions with they will cover more Futures but uh at this point are as I saw there it they are secret so I don't know what will come for with the pro version
