 Thank you so much for joining after lunch. You had before lunch an introduction to the speedrun Ethereum, an introduction to Ethereum, and I think should have by now a general understanding of what Ethereum is and the beginning of understanding of how to code and develop applications on Ethereum. I think now we are going to enter the weeds of Ethereum and really start doing a workshop, which is the challenge number one, right? Yes. Number one, and I'll let Tam actually introduce the workshop. And Tam is a member of Bidogiddo and also creator of the Qwallet, right? No, yeah. I'm a maintainer. All right, all right. So please welcome Tam for the workshop and hope you enjoy. Thank you. Thank you, guys. Welcome back. So I'm going to go through this decentralized taking app challenge. It's part of the speedrun Ethereum. As you were all told, speedrun Ethereum is a really nice way to get started with building on Ethereum. This is supposed to be a workshop. So if you would like to, you can just try to follow the steps with me and do the challenge. We'll see. So you can go to speedrunetherium.com and this is the decentralized taking app challenge. So what's this challenge about? Basically, it's a group funding effort. So you can imagine that you have an idea and you would like to raise some money. You can create an app and let everyone in the world to chip in to send you some money. We will set the goal, like for today, we will go for one eater. And if you reach that goal, we will send that eater to another smart contract. And if you don't reach the goal, we will make sure that everyone who sticks some money or some eat can actually get back the funds. If you would like to follow along, you will need nodes, yarn, and git. And this description is really nice. I will just go through all the checkpoints and start from scratch by cloning the repository. Yeah. Actually, I already downloaded this like half an hour ago, so if it won't work, I can just switch. Yeah, I have some backup. It should be there in like a minute. OK, so what we have, let me open the code. The code is not there. Oh, yeah. Sorry, I should follow the descriptions. So now I need to check out the branch. And I should be able to see what's inside. There are two main packages. One is HeartHat. We already talked about HeartHat. HeartHat is a really nice tool to get started to build on Ethereum. It will create a local blockchain for us. And also, it can manage our smart contracts and deployments. And we have an SGS folder, which is basically the front end. So in my terminal, I'm going to do the yarn chain. Oh no, I need to yarn install first. Sorry about that. So yarn install just downloads all the dependencies. And the yarn chain is going to start our local blockchain where we can test our smart contract. There you go. And in another terminal, I'm going to type yarn deploy, which deploys the smart contracts. These smart contracts are under HeartHat contracts. We have an example contract. This is the contract. We would like to send the EAT. And we have the Staker contract. This is the smart contract we are going to build today in the next hour. Is it better? Thank you. It's fine. Yeah, it's fine. Maybe the next one. Thank you. Uh-huh. Is it better? All right, so what we need first is we would like to track the balances. So if someone actually sends some EAT to the contract, we would like to know what's the balance. And a nice way of doing that is a solidity type called mapping. We would like to know who was actually the Staker, so actually the address, and the uint, that is going to be the balance. Also, I'm marking with this variable as public. The solidity compiler will actually create a getter function so we can have access to this variable. Let me just deploy. This one line again, yeah, lots of mistakes. I'm dead. In order to start our front end, we can hit Yarn Start. This will open at localhost 3000. If you look inside the next JS folder, this is where our app lives. And it's really powerful because you can just start creating anything, and it will instantly show up. So if I just type hello, hello is there. Also, so far I only wrote one line of code to track the balances. And there is a debug contracts tab. And you can see that this function shows up. And you can read individual balances. Obviously, as no one had stayed so far, if I just grab this Burner Vault address and try to read the value, it is going to be zero. So our next step would be to write a stake function. And everyone can call that function, send some eat, and start the crowdfunding. So in order to create a function in solidity, you need a function keyword, just the name of the function. Right now, we don't have any inputs. And this public is the visibility specifier. Public means that I can reuse this function in the same contract here. And also, it can be called externally. Also, I mark the contract payable, which if so otherwise, I won't be able to send eat to this function. We would need to know that who was actually the one who called this function. And there are some built-in functions we can use. One of those is message.sender. And the amount which was sent, you can access it by message.value. I really like the solidity docs cheat sheet. So if you go to the solidity docs, there is a cheat sheet. And you can look up all these available stuff that you can use. So you can hear that the message.sender is actually the address, the sender of the message who actually called the function. So we will use these. We want to store the balance. So you can do message.sender is equals message.value. Also, we want to make sure that if someone calls the stake function multiple times, we just increment their balance. So actually, it should be the previous balance plus the current value. Also, you can make it a little bit shorter. I think if you use some programming language, this might be very familiar to you. So these two lines of codes are the same. I'm going to deploy it again just to check how everything is going. So at the debug contracts tab, I can see that I have a new write function. And also, I can send some eat. If I try to call it, I will have an error because currently, the balance of my burner wallet is at zero. And I can just grab some funds from the faucet. So we are testing locally. It's really easy to get some eat. Also, if I want to stake like 0.3 eater, there are no floating numbers in Ethereum. So with this little button, I can just calculate the proper amount, which is multiplied by 10 times 18. So once I called send, two things happened. First of all, the staker contracts balance went up with 0.3 eat. And also, the balance of my burner wallet just went down. You can see that it actually went up more than 0.3 eat because we had to pay for the transaction. So this is the skeleton of our stake function. The challenge also asked us to create an event, which is a really nice way if you want to build an interactive app. You can create events at Solidity and the devs can listen to those events. In order to declare an event, you need the event keyword. I will call it stake. And I want to know who was the one who actually staked. And I want to know the amount. And after I incremented the balance, I can do emit stake and reuse the message that's sender and the message that's value. I'm going to deploy again and check if this part is working or not. So I'm going to stake like 0.25 eat. I need to convert it. And if I check the events tab, it will show up. Also, just for sanity check, if I just take another 0.2 eat, I should be able to read the balance and it's incrementing. So this was the first part. So far, we have a stake function. But there is no way to get the eat out of the contract. We can only just send some eat. But we also want to forward this eat if we reached our goal. Today, our goal will be one eater. I can just copy this line. So this is a constant. I call it threshold. And we would like to collect one eater. So we are going for multiple users. If I just create an income middle window, I have a new burner wallet. So it's just like simulating that I had one user who already staked and someone else is coming along and tried to stake as well. The goal is to reach one eater. Also, we will create a deadline. So there will be a staking period. And also, once we reach the deadline, we're going to check if all the staking or the balance is adept to one eat. And if so, then we'll transfer the eat to another smart contract. And if we didn't reach the goal, then we can just let all the users withdraw their eater. So we are going to create the deadline. This block timestamp is the actual timestamp when we are going to deploy this contract to the blockchain. And for testing, I'm just going to use 30 seconds. So we can just test if it's actually working or not. I'm going to create a new function called execute. I'm marking this function external for now. Previously, I used public, which meant that I could reuse it in the same contract. And that can be called also externally. I'm not planning to use this execute function inside this contract. So I marked it external, but others can still call this function. What I would like to make sure that this function can only be used only after the deadline. And the key word I can use is require. I'm going to create a condition. So this is how you make sure that this function, which can be called by anyone, can be executed only after we reach the deadline. And we can just specify an error message like that line is not there yet or something like that. What we want to know is what's the balance of our contract. I'm going to create a new rinse to store that. Call it contract balance. And I need the current contracts address. I can access that like this. So this is the current contract. And it's the address of the current contract. And I can just get the balance in what I'm missing. So what I want to do is to check if the current contract balance actually reached our threshold, that one ether. And if so, we will do something. And if it didn't reach the goal, we will do something else. If you reach the goal, you would like to transfer all the funds to this example contract. This example contract variable is declared here. And during the constructor, the address is set up properly. Let me check. So this contract has a complete function. I would like to call. Also, I would like to send the heat. And you can do that with curly braces and specify the value. Oh, no, sorry, that's the wrong case. So if we reach threshold, we're going to call this example contract. And we're going to send all the heat. Otherwise, we would like to make sure that everyone who sends already some money can withdraw their funds. I'm going to create a flag for that, which is a boolean called open for withdraw. We'll set it to false. And if we call this execute function and the threshold is not reached, we'll let people withdraw using this flag. Let me check if I can actually need a good smart contract or I had some typo. That's so far so good. So again, if the threshold was not met, we'll create a function which will let people to withdraw their money. First of all, we need to know how much, what is the balance of the current user or how to call this function. Also, we want to make sure that this withdraw function can be only called once we set the open for withdraw flag to true. And I will use the require again. And the error message will be something like not open for withdraw. Sending heat from a contract can be a little bit tricky. I will just type out how we can do it and explain a little bit later. So this line will transfer the user balance to the sender. What we want to make sure is that this function can be only called once. So before we start to send the balance, we would like to make sure that the same user cannot call it over and over again. So I'm going to set the balance to zero. Also, this call message, we return to variables. One is an indicator whether it was successful or not. And the other is some data. We don't really need that data. So I'm just skip that part. And I want to make sure that actually this call was successful. Every time I like to just hit your compile just to see if my code still compiles and I can deploy it so far so good. Let me check the UI, what we have. So now we have an execute function as well, not only a read and a stake function. And if I try to execute, I will get an error message because we haven't reached the deadline. That would be nice if we could just actually know how many seconds we have, because right now we only have the deadline like this. So that's why I'm going to create a view function just to know how much time we still have. I mark this function as view, which will indicate that inside this function, I cannot change any state. So if I would like to do state changes like this, because this function is marked as view, and I try to deploy or compile my smart contract, it should fail, telling me that this function was declared as view. So I just cannot modify the state. Also, this function will return the time left, which is going to be Uint. What I would like to do is just return the deadline, and minus the current timestamp. What I would like to make sure that it might be a negative number, so if we already reached that line, I just want to return 0, that there is no time left anymore. So I'm going to check if the deadline is actually greater than the timestamp, so we still have some time. And if so, let's return how many seconds we still have. Otherwise, I'm just going to return 0. I think it's always a good thing to test, sorry, it's not return, it returns Uint to test what we have. Another way to deploy is with the minus, minus reset flag, that we'll just completely create new contracts, and you can start from scratch. Time left says 0. Oh, the return statement, sorry about that, thank you. Time is a little bit difficult on local tests. If I just try to execute right now, it will say that the deadline is not reached, but the time left shows that 29 seconds, I just need to create a transaction. I can just grab some more funds and refresh, or I can also just do some staking like I would like to stake 1EAT, and it says that there is no time, so I should be able to call the execute function. So I stake 1EATer, this is just for a test. So we actually reached the threshold. If I call execute, the transaction was successful, and the balance went to 0, and it should be at the external example, external contract. So we reached our threshold, and even there is a nice UI for this, we actually staked 1EAT, and we have this success message. But there are lots of problems with this smart contract, and I'm going to work on those a little bit more. So one possible problem can be if we already called this execute function, let me create another scenario. So let's say that we won't reach the threshold. I deployed it again, so this is a completely new smart contract, and I'm going to stake only 0.2EATer, and I will wait a little bit in order to reach the deadline almost there. So I can call the execute function. Oh, it says that line is not there. Maybe I just need to refresh. All right, so I was able to call the execute function, but because the threshold was not reached, actually the money is still here. And one really big problem can be if someone comes along and tries to stake again, we still let them stake. On the other hand, there is just no way to get that EAT back again, because when he will try to withdraw the EATer, oh no, it's a success, so I made a mistake. Why did that work? Oh, sorry. So actually, when I didn't reach the threshold, I set the open for withdrawal to true. My bad, let me try it again. So let's imagine that actually there is enough EATer in the contract, and I will call execute till six seconds left. So staking was successful. We transferred all the balance to the example, smart contract, but we still let people stake. So if I just stake another EATer and I try to withdraw, it says that actually the contract is not open for withdrawal. So what we want to do is make sure that once we call the execute function, we shouldn't really let people to stake, or at least shouldn't let people funds stuck in the contract. So I mean, we'll just add new requirements. And one of the requirements is going to be that if we already called the complete function, then this completed flag will be true. So I want to make sure that the staking is not completed yet. This actually means that the staking was already successful, and we reached the threshold. One more thing we can do is that actually the staking was not successful, and we already opened for withdrawal. We can also just require that the contract is not open for withdrawal. So there will be no way to call this execute function multiple times. And actually I would like to do kind of the same for the stake function. But as code duplication is not really a nice way, I will show you how you can create a so-called modifier to bundle these requirements into one single modifier. I'm going to call it not completed. And instead of duplicating these lines of codes, I'm just going to have it at one place. And this special syntax allows us to actually call the function. So I'm going to mark the stake function with this modifier and the execute function with this modifier. This will make sure that if we already finished the staking, then we shouldn't be able to stake. So funds won't get locked in the smart contract. Let me check if the code still compiles. So I can't just grab this variable from another smart contract. I just need to access it. And actually as this is a variable and was marked as a public, the Solidity compiler just created a getter function for it. So the proper syntax will be this, or at least should be this. I think now we're getting there. One more thing which should be nice is to create a receive function. So by default, smart contracts cannot receive any money. So if I try to send money to this staker contract right now, there is this little facet. Sorry, I'm just going to copy the address. And I have this little facet. So what I'm trying to do is just send one eater to this contract. But it fails with an error and says that there is no fallback or receive function. And I'm going to implement that one. Receive is a special function. So we don't need the function keyword at all. Receive function has to be marked as external and payable. And what we want to do is just pretend that if anyone sends some money or sends some eats to the contract, then he's also a staker. So I can just reuse my stake function from here. Let me deploy this again. Skip the parentheses. All right. Just one more test on localhost. And after that, I will try to deploy this. If everything goes well, I will try to deploy this to a testnet or some mainnet. So let's pretend that from this account, I'm going to stake like 0.5Eat. I need to redeploy my contracts. So again, let's pretend that from this account, I stake 0.5Eat. And I'm going to open an incognito window to get another burner wallet. And from this account, I'm going to stake 0.5Eat again. So the balance is one eater. I should be able to call execute. Also, we can just use the staker UI, which is basically the same. It just shows that we're good. We reach the deadline. We have also a simple stake 0.5Eater. So it shows that I stake one eater. And that other guide also sold at 0.5Eater. So we're at 1.5. I should be able to call execute. And we get this nice success message that we were able to reach the goal and send all the money to the external smart contract. If I try to execute again, I should just get an error message that staking was already successful. Also, if I just try to withdraw, it says that it's not open for video. So there is no way to video. And actually, there is no balance to video also. Also, if I just try to keep using the smart contract, even though it was successful, and I just want to stake some more eat, I will also get an error message that the staking was already successful. So this smart contract, I think, is kind of ready. What you can also do is there are tests written for this challenge. You can hit yarn tests. And it runs five tests. And all of these tests are passed. So actually, there should be a lot more testing. But let's pretend that we're good. We tested our smart contracts through the UI. We run all the tests. So we should be good. I think the next step could be, instead of working on our local blockchain, to deploy to a public test net called Sepolia. But for that, I need a deployer account. I can create a deployer account with the Yarn Generate. And I can test count with the Yarn account. I will see this address and all the balance, which is going to be zero. And I'm going to fund this deployer account with my punk wallet. I'm going to send. So this is just test eat. And if I hit Yarn account again, then I should see that my Sepolia balance has went up. It's not there yet. Let me send it. I can try it again. Also, we can use the Sepolia Eater Scan to check on our deployer account. And yeah, it shows that I have some balance. So I will be able to deploy my smart contracts to the Sepolia. I'm going to edit the hardhat.config.ts file. And instead of working on localhost, I will fund this to Sepolia. So I can just hit Yarn deploy. And instead of deploying the smart contracts to my local chain, this will show up on Sepolia. It takes some time. So also, I will start to ship my front end, which will probably also take some time. There is a scaffold config.ts file, which points to hardhat, which is basically localhost. And I'm going to change this to Sepolia as well. My contract is still being deployed. And I will use Yarn Vercel to ship my app. It will take some time. Let me check how my contracts are. So it seems to be successful. Let me check. Yes, you can see that this deployer account has four transactions. I found it with some EATS. And there are two contracts created. One really nice tool as well is that if I just try to open this contract and go to the Contract tab, I only see the divide code. And probably people won't really interact with this smart contract if they don't know the source. So we can just verify the source with Yarn verify. So if I come back to the Eater scan again, then I can see that actually my contract was verified. And I can see the source code as well, which makes it a lot more easier for other people to look into what's happening here. And yeah, this is the Vercel build. It will take two or three minutes. And we will get our front-end ship to a public URL as well. What I wanted to also show you is that how you can submit this challenge. So if you're after this, you go home and you start working on these challenges, you will start with the NFT challenge. And then you will follow with the decentralized taking app. I'm going to connect through Wallet Connect if it works. Oh, no. Let me open an incognito window because I already solved these challenges. So I will need just a new account. I will use Wallet Connect, which is a nice way to connect wallets and dApps. And I'm just going to spin up Punk Wallet. And I have a new burner wallet and try to connect in. The first thing you need to do is just hit this register button. You can use MetaMask or any other wallet. It will just ask you to sign a message with which you can basically prove that you own the account, this specific address. And once you have that, you should be able to submit this challenge. I just need the deployed Vercel URL and the smart contract from Sepolia, Eterscan. I already have the staking contract. Which one is it? The staking contract here. Oh, no. So this is going to be the contracts URL. And yeah, actually the app should be visible here. Let me just check. Oh, no, so many tabs. So this is a public URL. And we should see the same app we built on localhost. But anyone could reach and connect their wallet. So in order to submit this challenge, I have the URL for the front end. I have the URL for the smart contract. And I can hit Submit. And hopefully it will go through. It's just loading. OK. So actually I need to sign this message as well in my wallet. And now it says that challenge submitted. It should take only a few minutes. And the status should be changed either to, oh, it's already accepted. So actually this was the decentralized staking app challenge. I would like to encourage you to go to Speedrun Ethereum and try to solve it on your own. And if you have any questions, let me know. Otherwise, Kevin will follow up with the next challenge. Thank you. Any questions for Tan? Can you tell us about the example external contract that you created? What is it for? Sure. Right now it doesn't really do anything. So this is just a test. So that's it. We send to that example smart contract. Actually it just stays there forever. So if you would like to create a proper staking app, you should make sure that the funds are actually sent to a proper address or a proper smart contract or to a person. All that question maybe? Oh, you're good. OK, thank you so much, Tan. That was great. And we have Kevin for the next workshop. So we'll be the next face of the same Speedrun Ethereum suite of workshops. And we have Kevin Jones that some of you might have met this morning. He did an amazing introduction about Ethereum and the technical aspects of Ethereum. And then he will now do a workshop on Ethereum. So yeah, please welcome Kevin Jones again for this amazing workshop to come. Testing one, two. Oh, that's good. All right. Got your attention. What's up, guys? Thank you so much, everybody, for being so dedicated today and staying the whole day. Really, really appreciate that. So I hope you guys are learning a lot and hope this has been really helpful for you guys to understand more about how you guys can get involved. So we're going to basically continue off with the challenges from where Tan went off. So if you guys go to Speedrun Ethereum, at some point, you guys need to get a wallet. So I already have MetaMask installed. So we can actually come in here, connect the wallet, use MetaMask, and then now we're signed in here. So Challenge Zero is actually really easy, like anybody can do it. It literally takes like 20 or 30 minutes. So I would give that as your guys' goal today is try to do this. Try to find 20 or 30 minutes to sit down and figure this part out because it doesn't really involve any coding at all. You guys can just walk through it this really easily. Obviously, the staking app you guys just saw is a little more complicated and also goes for the token vendor. The token vendor is definitely a little bit of live coding. But at least you guys have an understanding of what you need to do. So we're going to focus on the token vendor today. So we can click that. Oh, and actually, we want to connect to a different one. Let's connect to this one. So when you first, you guys might not have seen this, but when you first connect your wallet, you can register as a builder. So you can just click this little register icon. And that will kind of create you a speedrun Ethereum account. And then we've been talking about this all day, but everything you do involves signing a transaction. So what you do is you send a message here. And you say, I want to join and register as a builder. And you give your public address and you sign that. So that actually creates you an account in this open way. Anybody can do that. And then you have this little punk wallet, which is really awesome. And then you have a portfolio as well. So you can come here. You can add your social media contacts. And you can see all of your existing challenges that you've worked on. So we're going to start and do a challenge. And then we're going to be focused on this one here, which is the token vendor. Now, once you get through these three, you actually get invited into the build guild. So your profile gets upgraded. So that would be my challenge for the next couple weeks is try to get to that point as well. OK. So what are we going to be building today? So let me zoom out a little bit. Actually, maybe that was better. So the cool thing about smart contracts is they're kind of like vending machines in the ethos of Ethereum. So this is really cool because you can interact with the vending machine to do whatever you want. And so what we want to do is create a vending machine that allows anyone to go to and be able to buy tokens. So basically, we want to create a token vendor. So someone can come, place, send some eth into the contract, and then get back some kind of token in exchange. In this case, we're going to be calling it gold. So I love gold. So we're going to be focused on that. And we are going to utilize what's called the ERC20 standard for that. Now, if anyone has ever heard of Open Zeppelin, Open Zeppelin is a security company for the Ethereum for multiple blockchains. But more specifically for Ethereum, they've created these token standards. So we're going to use this ERC20 token standard, which is basically just a token for Ethereum. And we're going to mint some tokens. We're going to be able to edit our front end so that people can come and buy some tokens. And then we're going to publish this and then make it available, so similar to what we did before. So the first section is just going to be setting up scaffolding. So if you are not familiar, we've seen it probably a couple of times now that we've gone through and set up scaffolding. In this case, we need to clone the scaffolding challenges repo. And in this case, we're going to go into that directory. And then we're going to check out this particular branch. So the challenges repo has all the challenges in it. So you can actually go through and look at all of them. But we're going to be focused on the second one, which is challenge two. And then we're going to do any yard install. So now I'm using what's called Tmux, which is a terminal multiplexer. So that's why you see these four windows. Actually, I'm going to get rid of one window, so you just have three. So everything you do in scaffolding, you need a few windows open. So I've gone ahead and I've already checked out the repository here. Sorry, I know that's hard to read. But if I do a get branch, we can see that I'm on the challenge two token vendor. And I've also went ahead and did the yard install. But you'll need to go through and do that. I just went ahead and did it to save some time. So after you have that up, so it's always the same kind of commands. First, you're doing yarn chain, which spins up your blockchain. Very simple. That's going to spin up all of those play accounts with the ETH and stuff like that. I'm going to play around with it. And then I'm going to go to this second window. I'm always going to have that one open. And now I'm going to do yarn start. So this is all in the same directory. So I checked out a directory called C2. So we can see that we're in there. And we can see as well here, get branch. There it is. So now I'm going to do yarn start. So that's going to spin up the front end. So you always do those two things. And then you keep those running. And the nice thing about Tmux is it just shows you. I would look at Tmux later. You don't have to do that for today. But it's really helpful. And then the last one is that we're going to do that deploy. So we're just going to go ahead and deploy whatever contract is there just so that it's deployed. And we're just going to make sure that it deploys successfully, which it did. So it tells you that you deployed it successfully. It tells you how much gas it cost, which is really useful. And it tells you the contract address. So now we know that we've gone through this environment setup with all those commands. Yarn install, yarn chain, yarn deploy, yarn start. We've got everything working. So now we can load up the app. So again, Scaffoldy runs on local host 3,000 for 3,000. It's React with Next.js. So we've got everything up and running. And it's working. So we have the debug contracts tab, which is here. And we have, it's a little slow for some reason. I think the internet's kind of acting up a little bit. So it might be a little slow. Let's see. OK, that was very slow. It's not normally that slow, I swear. But we can see here that we have a contract that's already deployed. And we can see that it has some details. Like it has a name. It has decimals. It has the gold GLD symbol. And it has a supply of zero, because we haven't minted any. But let's go ahead and load up the project and take a look at it. OK, so here we have just the standard Scaffoldy project. Inside the hard hat folder is where we're going to spend most of our time today. And then inside the contracts folder, we have two different contracts. We have a vendor, and then we have a token. So the cool thing is you can deploy contracts, and you can inherit contracts and connect them together. So that's kind of what we're going to be doing in a little bit here. But I want to just go through the first kind of steps that it's going to ask us here on the token. So the first thing it's going to say is, OK, you need to edit your token file, the Solidity file, to basically inherit ERC20 from Open Zeppelin. And then we want to also mint 1,000 of our tokens, times 10 to the 18th power, to our front end using the constructor. And then we're going to deploy that using the reset command. After we do that, we should be able to see the balance, and we should be able to transfer stuff around if we want to, OK? So how do we do that? It's actually very easy, because your token Solidity file that comes with this project actually already has the ERC20 imported right here. Let me go up a little bit bigger. So we already have it here. Now you'll see that this particular package comes with the ERC20 Solidity file that lets you create a token. So when you import this token like you do here, you can then inherit the token inside of an existing contract. So you can see here that we have a smart contract that's called your token. And you see this little is right here? So this says that this token is an inherited token from this standard or this existing implementation. So basically we're saying, OK, create this new token, use the ERC20 that's referenced here, and this will get you access to all the variables, functions, modifiers. Basically everything that's inside here is going to be available to you in this contract. So that's really, really powerful, because this contract is certified as being a trusted and, well, touring complete, I guess, or feature complete contract. So we can see that we already mint. Well, we already create the name of the token. So it's called gold. And we have the symbol, which is GLD. But what we need to do is actually mint the tokens. So we actually have it already written here. So we can just uncomment that out. But what this is going to say is, OK, well, we want to mint these tokens to an address that we specify here. So what we'll do is we'll grab our burner address here. So we have a burner wallet, right? We don't have to worry about MetaMask right now, but we already have that here. Copy address. And we can paste that in here. So what this is going to do, so underscore mint is a function inside of ERC 20. So we can call mint, pass in an address, tell it what quantity we want. So we want 1,000 times 10 to the 18th power, because we want to get 1,000 of these. But we also want to get them in full way, right? So we have a larger amount. We can break it up into smaller increments, OK? So all we need to do is save that, and then we can do a deploy-dash-reset, OK? So that's going to take the contract, going to redeploy it. And you'll notice that we get a new address. So before we had this address here, now we have a new address for the contract, which is here. And we can also see that the gas increased too. So we went from 564 to 614,000 gas. So as we start adding to our contract, the gas increases, OK? But at this point now, we can come to our app. We can grab the address again, and we can check the balance of this address, right? I check the balance there. Cool, it says 1,000. I have 1,000 of these tokens. But I also could check metallic.eth. And I could see if he has any tokens. Oh, why is that not valid? I think it's because the internet's not working. That's there it goes, OK. So he doesn't have any tokens, but I have them. I'm more rich than the TALIC. OK, so you get the idea. We've created now this total supply has changed from zero earlier to 1,000. So now I have these 1,000 tokens. So we kind of know that we're moving along, right? We set up the environments. We created a mint. So we minted these tokens. We can balance them. We can also transfer the tokens. So if I want to pull up an incognito window like this and go to localhost 3,000, I can get a new burner wallet. And I could transfer some tokens if I wanted to by sending to this one if it loads. I'm not sure, but the internet is just slaughtering this demo a little bit. Oh, 4,000 milliseconds. OK, well, that's OK. But we'll see if that loads in a little bit. Otherwise, we'll keep going. OK, so if I wanted to, I could actually come here and I could transfer some tokens right here. But you can see that when we imported all of the ERC20 standard, we get access to all of the functions that are in there, right, which is really useful. And there's also modifiers as well. But it's really cool because we can start exploring to see what functions are available. So let's keep going. OK, so now what we want to do is we want to create a vendor, right? So what does a vending machine do? Well, it takes in cash or fiat or, in this case, ETH and then it gives back something. So we want to give back some tokens. So we need to set basically a price variable for how much our tokens are going to cost per ETH, right? So that's the first thing we want to do is say, OK, we want to say that in this case, we will define a variable for the vendor. So this time we're kind of done with the token. The token doesn't really have much function other than just minting the tokens. And we'll probably have to change this in a little bit. But for the most part right now, we're just going to focus on the vendor from here on out. Let me zoom this over a little bit. OK, so the vendor is very similar, but it's not an ERC20 token. It's just a standard kind of smart contract. But what's important is we're actually inheriting the existing token address from the other contract. And we're also importing it like this using just the Solidity file. And then we just have this very basic vendor. So what we can do is we can define a variable inside of the contract. So in this case, let me just reference this to make sure. Yeah, so we want to just drop it basically in here. So we're going to say basically, OK, for every this, so this is an unsigned integer. The 256 is like the size, the max size of the integer. So you could actually lower this a lot more if you wanted to. You could do like 128. You could do 64. Just for the sake of a thing, you always want to put what it is. You could also just do uent. And it would just give you the max, which is 256. But we're going to just do uent 256 because that's kind of best practice. We're going to make it publicly available. We already talked about that. That means that it can be accessed inside of the contract or externally. It's a constant, so we don't want it to change. And then we want to just want to call it tokens per ETH. And then we want to define 100, right? OK, so we can do that. We can save that change. And then what we want to do is import ownable next, which I think it's going to ask us to do that. So at some point, it's going to ask us to do ownable. So inside of smart contracts, every smart contract needs to have some kind of pattern for access control. So if you're going to store ETH inside of a contract, you need to find a way to get it out. Because if you put it in and you don't have a way to withdraw it, it will be lost forever, right? So what's cool is Open Zeppelin, again, has created a set of contracts called the ownable contracts, or the ownable contract, I should say. And it's right here. So we can import that like this. And we can say that your vendor is ownable. And what this is going to do is it's going to give us an access control pattern for our contract so that later on, when we want to withdraw funds from the contract, we can check to make sure that someone is the specific owner. So let's save that. And let's try to deploy. Let's see if it works successfully. OK, it works successfully. So what else is it going to ask us to do? So we want to create the buy tokens function that's already available in the vendor. It says that it should use the message value and the tokens per E to calculate the amount of tokens that you should transfer to the sender. And then we also want to, it's going to ask us to emit an event. And then it's going to ask us to update the deploy script so that it deploys properly. So for this, what we're going to do is we are going to see here. So here we want to create a payable function. So in this case, that's the withdrawal function. So we want to do a function. We want to call it buy tokens. And we want to make this function public and payable. So publicly available payable is so that it can receive funds because we need to actually send some ETH there. So the function is called buy tokens. It is public, which means that anyone can interact with it. One of the first things that you'll learn with Solidity is that you can create require statements. You guys probably saw this earlier. But we want to basically require that whoever is interacting with this particular function actually is sending some value. So the first thing we want to do is get the message.value. So we might have talked about this earlier. But there are what are called global variables that are available during a transaction. One of those is the message value. And one of those is the message sender. So message value is how much actual ETH is being sent in the transaction. Message sender is the public address of who called that. So we're going to say, OK, in order to call this function, you actually need to have sent more than zero ETH. Otherwise, you need to send some ETH there. And then we're going to set the amounts. So uint 256, amounts equal message.value. I mean, we could do this a little bit different, but we could also do it like this. We could say, uint 256, tokens equal amounts. I love AI. It's mixing so much easier. So what we're going to do is we're going to say, what was the amount sent in the transaction? And we get that from the message value. And then how many tokens should we actually mint based off of that amount? So the way that we get that is we can say the amount times the tokens per ETH, which is defined here. And then that will give us the amount of tokens. And then we can also do uint 256, get the token balance. So your token dot balance of, and then we want to say, address of this. I think that's right. So then this is going to get the current balance of the smart contract. So basically what we're going to do is we're going to load the contract up with all of the tokens that it needs to be a vendor. And we're going to allow people to withdraw from that your token or purchase from that contract. So we need to be able to get the balance. I'm doing this in a very explicit way so that you can see these different ways that you can interact. There's probably a more optimized way to do this, but at least you can get an understanding of what that looks like. The next thing is we can do a require statement to basically check to make sure that there's enough tokens in the contract to be purchased. So what we can do is say require that the tokens, there we go, require that the token balance is greater than or equal to the amount of tokens that need to be purchased. Otherwise there's not going to be enough tokens in the contract. And then last week we will figure out who the buyer is. So we say address buyer is message sender. And then now we can do the transfer. So what we want to do is we want to call the transfer function of the existing your token. And we want to pass in who the buyer is, and then we want to transfer the actual funds if it was successful. So we can do something like this, and we can do the same thing that Tam did, where we can say Boolean success, or let's call it sense. Just to say consistent, and then like this. So basically if the transfer is successful from your token, then create that variable. And then we can do a require statement that says sense otherwise failed, like this, should work. OK, so let's walk through it real quick. So we're going to say, all right, require that the person is calling this function has a value of at least 0 in the transaction. Otherwise they need to send some eth. Create a variable that's the amount, which is the value. Calculate how many tokens that they're going to be able to get after they've sent that. Check to make sure that the balance of the token has enough tokens. If it doesn't, then say there's not enough tokens. And then on top of that, figure out who the buyer is, and then send those tokens by doing a transfer call on that other function, and then pass that. And it's only going to work if the Boolean is successful. Otherwise it would be like failed transfer or something like that. OK, so that should work. The last thing I want to do is also talk about the events. So we want to create an event. The cool thing is the events are already written for you here. So we can just uncomment this one. And we can see here it's called buy tokens. So I think the best practice is to capitalize the events. So in this case, it's buy tokens, capital, which is the same as the function. And what an event does is it just passes some information amidst that information so that your front end can see it, other protocols can see it, block explorers can see it. It's pretty much anything important that you should log, or you want to log, you put into an event. So in this case, we want to log who the buyer was, how much eth they wanted to buy, and then how many tokens, sorry, how much eth they deposited, and how many tokens they got back. So we can keep track of that. So I think this should be good. We just need to admit the events. We can do that later because I think it's going to ask later. We could also do a, just while we're here, we can create a sell tokens event because I know we're going to need it. Address, oops, that's not useful. Seller, UNT 256, amount of, and then UNT 26, amount of AI is not helping me because the internet probably is messed up. Okay. So let's just try to deploy this and let's, oh, we need to actually update the deploy script too. So we've made all these changes, but we actually have, with scaffold eth, for every contract you have, you have a separate deploy script, okay? So we have the vendor and we have the token. So the token, we don't need to change because it's pretty much good to go here, but the vendor, we need to actually make it deploy the vendor. So as of right now, it's not deploying. So you can see here that it's actually already written for you. So you can just grab all of this stuff and then uncomment that out. So hard hat uses type script basically to do a deploy or a JavaScript of an hours version you're using, how you have it configured. But we want to use all of this code and it's, like I said, it's already written for you. I think what's most importantly is that we use the deployer account that comes with hard hat to deploy the contract. That's kind of a good thing to know. We also pass arguments here to get the token address and we also do a transfer to transfer some ETH to the vendor address. So we actually need to put our front end address here to also transfer ownership of the contract. So what I want to change is two things. First is I want to mint all the tokens to the message.sender instead of the front end address because we want to actually send the tokens to the deployer account first and then we want to physically transfer them to the vendor. So it's kind of like a two-part thing. So the tokens will be minted here to the hard hat account and then they'll be transferred later on to the vendor so that people can buy them. Okay, so let's save that. Oh, save, make sure everything's saved. Okay, this is saved. And now we can put our front end address here. So let's grab that. I hope this is going to work. Okay, front end address, boom. Okay, it's kind of weird. Sometimes you need quotes, sometimes you don't. In the case of TypeScript, we're putting that in quotes. If you're using Solidity, you don't use quotes. That's generally, okay. Let's try to deploy it now. Fingers crossed, YOLO. Oh, what did I do? Your tokens, buyer tokens, something with the vendor. Your token, got transferred. Oh, maybe, oh, do we want to do message.sender actually here? And then you get rid of this. Tokens, that should work, yeah? Let me try it again. There it goes. I didn't like the comma. You're right, okay. Cool, all right, the deployed. Thank gosh, okay. All right, so now let's go and check out what we have here. So now we have a total supply of 1,000, right? But now if we check the, let's look at the thing here. So we have the ability. So when you try to buy tokens from the vendor, so I already kind of fixed that because I did a transfer here in the contract. We can look at it real quick, but here we transfer the tokens to the contract and then we also transfer ownership of the contract. So I already fixed some of this stuff, but we should be able to now go to our thing. Let's reload. And we also need to open up, I believe, the front end so that we have access to buy the tokens. Let's see if it's available. I don't think it is, token vendor. Okay, so we're missing the ability to extract the tokens here. So I think what we need to do is come into Next.js, go to the app, go to the token vendor, and just, I guess, retroactively, I'm gonna go through here and like, uncomment this stuff so that it's all there because basically they have you do this kind of one by one in the thing, but I think what I just want to do is just uncomment this stuff so that we have it available. So in this case, we're gonna get rid of, so these are all comments. So in this case, we want to just kind of get rid of the commented out stuff so that we just have all this available in our front end. Ideally, you like follow the documentation and kind of understand how this works, but I think at this point, okay, cool. So now we have this buy tokens function. So it says that we should be able to buy 100 tokens. If I've written the smart contract correctly, I should be able to buy 100 tokens per ETH. So how many tokens do I want to buy? Let's choose, I don't know, two tokens. No, one more than that, 2,000 tokens. It's gonna ask me buy tokens. It's gonna tell me that I don't have enough ETH, right? Oh, it's not enough tokens in the reserve because I only have 1,000. So let's just buy two, buy tokens. And now it's gonna tell me I don't have enough funds. So I need to get some funds from the faucet so I can just click that. Now let's click buy tokens and there we go. So now I was able to buy two GLD and then I could also, now that I have the access to the tokens, I can also transfer them. So I can come over here and I could basically transfer them to this address so I can grab this address here and I can say transfer two, send one over here, send tokens. Now I only have one token. Now if I come over to this incognito window and go to token vendor, this one has one. So I've created this token vendor. I've been able to go in, send some ETH, buy some tokens and then send them to my friend, right? So we got the buy tokens working. Cool, we're about halfway through. Now we need to do the sell tokens side, okay? So we have the ability to buy tokens. We've deployed the contract. We've minted the tokens, sent them to the vendor. We're pretty much good there. So now I think we wanna focus more on the vendor again and we wanna do, to do, we have two different things. The most important thing I think at this point is to create a function that allows us to withdraw, okay? So the main purpose here is we want to be able to get that ETH out after the fact. So like I was saying, at some point, you wanna take some profits on your application while you need a function to withdraw. So we're gonna call it withdraw. Oh, if I can spell correctly. So function withdraw, we're gonna make it public but we're gonna make it only owner. So cool thing about AI is it wrote it all for me but what this is gonna do is gonna say, okay, I wanna withdraw all of the ETH that's available inside of the contract. So it's kind of like a rug pull. So I'm gonna create this withdraw function. It's only the owner can call it. So if you remember earlier, we inherited ownable and we inherited it here. What's cool about ownable is if we click it and look in here, there's a special modifier called only owner. So a modifier is kind of like a function but you can have it run as a requirement, similar to like a require statement before a transaction is executed correctly. So we do this thing called check owner which makes sure that the owner is the sender of the actual contract. So it's a way for you to do access control for like obviously we're dealing with real funds so we need to be very safe in that sense. So we have this function that says, okay, anyone can call it but you can only actually successfully call it if you're the owner. We get the balance by checking the balance of the contract. If the balance is greater than zero or less than zero then we can't withdraw. Otherwise we will transfer the balance to the person or to the actual owner. We can also change this to like message.sender or something like that. But I think for the sake of this, I think this should be good. Actually, let's see if it works. Sure, let's do it. The yarn deploy reset. Can I save it? Yep. Okay, so now I've kind of reset the contract. Let's buy some tokens. Let's buy 20 tokens. It was successful. Now I have 20 tokens. So there's 20 tokens in the contract and I'm the current owner. So if I go to debug contracts and I go to, let's see here. Oh, maybe I can't see. Oh yeah, here. Oh, your token. Actually, the owner is not set. Oh, there it is. Sorry, okay. So I can see that the owner is 0xA4 right here. So I'm the current owner of the contract. So if I was to come over to this guy, this kind of incognito guy, and I see that there's some balance in the contract, right? I'm like a malicious actor and I want to withdraw that ETH from there. We want to make sure that I can't do that. So we created the only owner access control pattern. So now if I go to debug contracts, I can see there's some ETH there. So if I wanted to try to withdraw it from this account, it's going to tell me that I'm not the owner. See how it says ownable? Caller is not the owner. But if I go to this particular contract and I go to withdraw, then it's successful. So I know that the access control works correctly. So that's really important. Anytime you're dealing with withdrawing funds, you want to have some kind of access control. Okay, so the next thing we want to do is focus on the sell tokens, okay? So let's try to knock that out. So the last thing is to sell tokens. Okay, so we want a function called sell tokens. Same thing, we want it public. I don't think it needs to be payable, so we can skip that. We want to define a new instance 256, and we want to get the balance of the contract. So we could do token balance equals your token. Balance of, and then we can pass in the address of this smart contract like that. I think that should work. And then we can require. So we can require that the token balance is greater than or equal to the amount. Oh, that's the other thing is we want to actually pass in the amount. So let's do that at first. So we want to say, okay, well, if someone wants to sell tokens, they're probably going to say how many tokens they want to sell. So we're going to say UNS 256, and we're going to pass in an amount. So in this case, this function is going to take in an unsigned integer, and then we want to make sure that there's enough tokens to actually sell, right? Otherwise we're going to pass this error. And then we want to calculate how much eth that we need to basically send, right? So we can say UN 256, in this case, amount is equal to underscore amount divided by tokens per eth. So in this case, we're doing the opposite. We're not multiplying. We're dividing the amount of tokens per eth. And we're going to also require that there's enough eth to pay, right? So we can say require amount, sorry, require the address of this smart contracts dot balance is greater than or equal to the amount. Otherwise we'll say, I don't know, not enough funds. There we go, okay. So at this point, we're creating a sell function that allows us to make sure there's enough tokens to be sold. Yeah, make sure that the balance is there. Make sure that they can get the funds. I think that should be right. And then the next thing is we want to transfer the tokens to the contract. So in this case, we'll do your token dot transfer from, or actually it's just transfer from the message dot sender. Oh, no, it's transfer from actually transfer from message dot sender, the address of the smart contract and then the amount that's being passed, right? So in this case, we're going to do that if it doesn't work. So if the Boolean doesn't exist, we can say failed transfer. And then I think the last thing is we need to like, omit, oh, we need to transfer the eth. So in this case, we're doing the transfer from on the tokens, right? So this is doing the sender, the amount of tokens. And then we also need to pass in here. So let's do Boolean, I would call it sent to, I don't know, we are sure, equal payable message dot sender. And then we'll do a dot send, I guess. And then we can do a require statement as well that requires sent to otherwise failed to send eth. Okay, and then the last thing is we created an event already, it's here, it's called sell token. So we can omit that event. So we can do omit, sell tokens, pass in the message dot sender, pass in the amount and pass in the amount of eth that's being passed back as well. Okay, I think that should be good. Are we omitting the event here as well? Oh, we're not, we should do that too. So buy tokens, so we should omit the buy tokens event. So in this case, it's buy tokens, this is amounts tokens, let's make sure that's right. Okay, that should be good. All right, let's save that and let's try to deploy. One, what could I do here? How does it just stop? Oh, that doesn't need to be there. Oh, did I do the sent to? Name it right, sell tokens. Oh, here. Okay, some multi posts, but I think I got them worked out. All right, all right, it worked. Okay, so now I should be able to go back into the app. So I've created the ability to buy tokens, we've showed that. Now let's go to the token vendor and let's refresh and let's get some funds from the whole process just to make sure we have enough. So in this case, let's buy, let's buy 50 tokens, right? Now I can buy those 50 tokens. Let's say that I wanna transfer those to my buddy over here. So I can come over here, copy the address and we're just kinda testing as we're going. Let's send him 25 of those tokens. So now he has 25. So now he should be able to come in here to the vendor and then he should be able to sell those tokens. Now, when you're working with ERC-20, you need to basically approve a transfer before you can actually do the transfer. So you can see here that we have this approve button, which allows us to call the approve function. So in this case, let's say that I wanna just sell like 10 of my tokens, I can approve that I only wanna sell 10, approve. Oh, I need some gas. Okay, let's try that. That's weird, it's a UI bug. All right, 10, approve. There we go, so I approved the sale of 10. Now I can sell 10. Sell tokens not found on ABI. Oh, maybe I didn't name something correctly. Let's see. Oh, I didn't do the function name correctly. So let's save that. Let's redeploy. So this is kinda how you do it. You start tinkering and toying around. Okay, so now I should all do that again. I'll just do it, this time I'll just do it from this account. So let's buy 50 tokens. It worked, let's approve the sale of 10, approve. And then now let's sell those. There we go, now it was successful. So now I have 40 tokens. So I bought 50 tokens, I approved the transfer of 10 and then I sold 10. I still have 40, right? And now the contract has half of an ETH. So now I could pull that stuff out by coming to debug contracts and do a withdrawal. And then I get all that back into my wallet. So now everything's working. The way we can check is to do the tests. So let's do that yarn tests. So this is gonna run hard hat tests. And it's gonna make sure that it passed and it did. Okay, we're success. So it passed all the buy, sell, withdraw, the approve function, the transfer function, and the vendor and the ear token are all working correctly. The block limit set, it's enabled, optimizer. We're good, we're good. Okay, so the next thing we wanna do is deploy it. We just went through this again, but let's do it again. We're gonna do, so we need a deployer account. Like we wanna put this on a testnet, right? Let's just make sure I did everything first. Let's go here. We came in here, we did ownable, we did the vendor buyback, everything's working. Now we wanna deploy the contract. In this case, what we're gonna do is we're gonna deploy it to Sepolia, we'll use Sepolia again. So what we can do is yarn account. Sorry, that's not correct. Yarn run generate. So yarn run generate is gonna generate us a private key and a public key, and it's gonna store the private key inside of our directory in the environment variable file here, but we have a public address. So we could do yarn account, and I could pull out my punk wallet, and I could fund it. So let's send some Sepolia, Eve, see if I can do that. Actually, you know what, I'm just gonna do it the easy way. I'm just gonna grab the address here, and I'm gonna send some from this wallet here. So I have, oh, I already have some here. So I have one ETH, so I'll send that, I'll send it to that address, and I will send zero points to ETH next. So I'm taking some funds that I have in my MetaMask, sending them to that Deployer key. So now that should work. So now if I do yarn account, it's gonna go through and check my balances, right? There we go, all right. Sepolia is working, okay. So I was able to send some funds to that Deployer. So now I can do yarn deploy dash dash network, Sepolia, all right? So what that's gonna do is take my contract, compile it, see if it needs to compile, which it didn't. Then it's gonna ship it to Sepolia by doing a create, basically. And it's very slow, but that's okay. We'll give it a second, and then it's gonna deploy that. The next thing we need to do is get our front end ready. So while that's doing that, let me open up, he'll do get chain ID. Okay, while that's doing that, I'm gonna go into the C2 directory here and I'm gonna do a yarn, was it Vercel, YOLO? That's just proud, is that what it is? Oh, wait till the contract's done. Oh, yeah, yeah, yeah. Thank you. Okay, so, oh, it's deploying both the contracts. I hope it has enough gas. So if it doesn't, it's gonna tell me, but I think it's good. Point two, ETH, we're good. Okay, cool, so that was successful. So now our contract has been shipped to Sepolia so we can update our front end. So we go back down in here, we can go into what's called the scaffold config. You probably saw this earlier. Let's change the chains to Sepolia, like that. We can also update some stuff here, lower this. What is this, the script false, that's a good one. Okay, so now we can load it up the front end and make sure that it's showing the proper contract. Okay, so there it goes. It's deployed to Sepolia. We can click it and see. Here, well, that's doing that. I'm gonna do a yarn, Vercel, YOLO, dash, dash, prod. Or dash, dash, prod. No, let me just get in here. Oh, great. Oh, here it is. Yarn, Vercel, dash, dash, prod. Yes. Boom. Yes. Okay, uploading. Okay, so let's see if the contract worked. Okay, so it was deployed successfully a minute ago. One thing you'll notice is that on the contract tab, we have the byte code here, right? We talked about byte code today. It's unreadable. So you should also verify your contract. I don't know if Tam did that, but I'm gonna do that real quick. So how we do that is we just do yarn, verify, dash, dash, network, Sepolia. Because we need the contract verified. Yeah, so Tam would have had to have done it in order to get the results back from Bill Gittle or from Speedrun Ethereum. So now it's verifying my contract. So when you verify the contract, it's basically comparing what you deployed to what your source code is to make sure that they match so that people have an open view of what your contract does. Because you wanna operate in an open way. This is an open source conference. So that's why we verify our contracts. And there we go. So it's working verified. So now if we come here and refresh, we'll get the verified contract. You can see all the code that I wrote here. Here's the ownable contract. And here is the C20 and the token and the ABI. So everything's good. The last thing we need to do is just make sure that that ships appropriately, which it should be good. But in the meantime, let's grab this. And let's try to, let's see if it passes our test. So we can go submit challenge. So we can do here. And then this might take a second. While that's doing that, it looks to me like we have like 10 minutes. Oh, here we go. Okay, so production. I don't know if it's gonna work yet, but we'll try it. Let's see. Submit. It's gonna ask me to sign my transaction. Sign. Cool. Deployed, submitted. And at some point it should verify it. But we did it. We deployed the app. So I have like five or 10 minutes for questions. So I guess at this point, I'll open it up to you guys and see if you guys have any questions about that. Got to be at least one question. At least one question, come on. Otherwise we'll take a little bit of a break and then we'll do the data indexing. Did you? Yeah. Did I miss something? No, no, no, not at all. I did a great job. You were talking about how smart contracts have different role-based systems. But I would also add to that that the best smart contract doesn't have an owner, right? The best kind of smart contract is like algorithmic and doesn't have any way for anyone to be able to pull any money out. And it works in a different way where they pull the money out based on the rules of the system and not if they're that owner or not. Yeah, that's a good way. That's a good point. Yeah, I think we try to build things in the ecosystem that are like game theory, interesting, cool apps. And so yeah, that's the power of smart contracts is you can just kind of let go and let them do their thing. And you can build some really cool stuff with that. As your... Yes. There's a Telegram channel. That's a great, great point. So for every challenge that you go through, there's a specific Telegram channel that you can get support for. And I think it's just down here at the bottom. Yeah, here it is right here. No, it's somewhere here. Problems, questions. Here we go. So we have the scaffold main developer chat. So if we click that, that will take you there. There's also, I think there's a link on the top. Yeah, Austin. Oh, here it is. There's a special Telegram chat for every single challenge. So you can go into this, you just click it. It's gonna load up your Telegram and then it's gonna invite you to the group. I won't open it. But yeah, so do that if you get stuck. If you just have general questions about ScaffoldEath, you can just go on to the main Telegram chat. I'm not sure if anyone talked about it, but the ScaffoldEath I.O., there's a docs that's really, really good. We didn't really get into that too much. But I think in here, like anything you wanna know about ScaffoldEath, all of the components that are available. So there's an address component, balance component, inputs, any of the ways you interact. So the hooks are all here as well. So if you wanna read from your contract, it gives you an example. If you wanna write to your contract, if you wanna subscribe to events, this is how you would do it. If you want to see all the history of events, if you wanna just get contract info, whatever, it's all documented really well. So yeah, the docs are great. If you have any questions, we'll be around for a little bit. And yeah, any other questions? Cool. Okay. Thank you so much, Kevin. That was amazing. Yeah, great, great workshop. We have a little surprise because we are very lucky to have Lloyd with us. Lloyd from Kiber, he's an OG in the space. So we had a break plan, but I think we would like him to have a few words. That would be Vietnamese, by the way. So please welcome Lloyd. Yeah. I'm gonna use Vietnamese. I'm gonna use Vietnamese, so you guys can hear me a little bit. I'm gonna use a few more. Sorry guys, time for you to check the AI translation. Yeah, hopefully. Yeah. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay.dale. Wow. Okay. Cool. Don't hear me. Economics. Computer science. Okay. Okay. Okay. Okay. Okay. I also studied at the University of Technology at the International University of Technology. After that, I was born into a PhD in Computer Science. I started researching blockchain, Ethereum, and web bar from 2013 to 2014. There was a rather early start to everything. At that time, I hoped that there would be workshops like this, so that everyone would think of me as an example, and that there would be documentation and stuff like that. But at that time, I had to go to the forum and the mailing list to find out. Today, I am very happy to see Ethereum Foundation, Abitrum, and all the best web-three brands that have been able to bring a workshop like this to all of you. You may not know that it is extremely difficult to invite all the speakers like this to go to workshops like this. I am very happy that it has been presented to Hanoi, and especially in a school that is quite famous for the arts, such as the University of Technology. Here, there are people who have heard about web-three, and heard about Ethereum, and so on. Before that. Okay. 1, 2, 3, 4, 5, 6. Actually, not much. So, maybe I should ask you a little bit. Let me encourage you a little bit. How much do you expect when you go to school? Under 1,000 dollars. Under 1,000 dollars. Okay. From 1,000 to 2,000. Okay. More than that. From 2,000 to 4,000 dollars a month. You don't want to go to work, do you? You don't want to go to work, do you? Okay. So, under 1,000 dollars, how many people? Okay, okay, okay. Quite a lot. Actually, I see that web-three is an open, actually a global movement. So if we can try to catch development very soon, there are a lot of places where we don't just need to catch up on computer science or computer technology to participate. And if we can... Actually, there are a lot of other places such as economics or finance, community, development like this, right? We can all participate. And actually, this is a... It's a very early day. And it's losing a lot of talent. It's the same as the year 2009, 2010 when we started studying computer science. At this time, when we were studying web-three, blockchain and other things, I think it would be the beginning of the future. At that time, when we went to school, we were looking for jobs and working for large groups, large international organizations. From 1,000 to 2,000, it was a completely normal thing. And even if you know a lot of friends from 2,000 to 3,000 years, if you go up to 10,000 to 15,000 dollars a month, it's the same as the amount that we can't imagine. But this is actually a global movement such as The New Internet. It's a completely new Internet, so if we can try to learn from the best from all the students here, it will be a very great opportunity for all of you. Um, I think it's a bit too much. Ah, okay. Um, okay. Any questions? Okay, there's a question over there. I have a good one. Okay. He's from, what's that, like embedded system kind of, right? Um, and he's asking like whether there's any like interesting position for him in Word 3? Anyone want to address? Okay, maybe you can answer the question. What is the question? He's from, he's not from computer science, he's from more like embedded system, electrical engineering and things like that. Is there any like position for him in the space? In Word 3? Yes, actually some knowledge of embedded system can be useful in, in zero knowledge proofs and such that I'm going to talk after and learning also about circuits and, and there is all the things about, um, optimizing op codes in, um, the byte code of a smart contract that is very related to what you do sometimes in embedded systems. Um, so yeah, I think definitely, um, this is deep tech and I think like knowledge and tech branches are, are going to be very useful. Okay, um, he said that when there are a lot of programming in low level or in the design that, um, currently in the blockchain we have to use a lot. So when I learn all the basic theories I will apply them all. So, um, I will do a lot of things that I need to do. Um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, um, So he's interested in developing a web-free career as a researcher, more like a protocol researcher kind of role. And he's asking like, you know, where could be the good start for him? Because like he has been like doing a lot of depth development himself. But he feels like, you know, it's not there yet. So maybe there's something for you to answer. So the Therian Foundation, for people that want to be protocol researcher, has a very good program that is the Therian Protocol Fellowship that actually I did before getting my job at the Therian Foundation. I did that grant. So I think it's a four-month grant that allows you to work full-time on Ethereum protocol on different clients. There is an Ethereum Foundation Fellowship program for researchers. Ethereum Protocol Foundation Fellowship. The application opens in April. So please pay attention to the application. If you get into this fellowship program, as soon as your career is set, you don't have to worry about it. You just have to try to pick up all the things that you have learned. Actually, Nam is a pretty good researcher, and he's also a Vietnamese. Nam used to work for my company, and he joined the core research of Ethereum PSC, Privacy and Security. Oh, okay, sorry. Hello, everyone. My name is Nam. I'm currently doing research for Ethereum Foundation. I also want to share a few things. The first thing I want to ask you about the network, it's a very good question. When you look at a blockchain, you will think that it has to run on a computer, but that's not true. Because of any harm that can be dealt with, the tasks related to logic can run on a blockchain. For example, on my phone, or on a smaller management board, or on a video game board, the research on blockchain or blockchain applications are also more open, they can run on a server, they can run on a computer like this. They also care a lot about using the phone or the tasks that they can handle, and the smaller ones. So, there is a future. I think it's a way to expand my future. The second thing is that when I work on things that are related to hard work, I can study about the specialization of a hard work in a task that is very rare in a blockchain. For example, there are currently some research on Zerariproof. Leone is actually talking about the problem that I will do a hard work to increase the accuracy, I will only work on those tasks. Not a general purpose machine, but a computer, and I can do a special design for that, that is also a very good direction. The second question is about the web-free career. In addition to the Ethereum Protocol Fellowship program, other blockchain platforms also have the same education programs. In addition, in the blockchains of blockchain, such as ink or something, I can also easily find groups with research and online discussion, such as ZKHC, you can visit the information on the Internet. You just need to enter the word such as Sturry Group Blockchains, I will find a lot of such discussions. So you don't have to worry about the problem, I lack education, I don't have enough time, or I don't have enough energy, or it doesn't match my direction. Thank you. Okay, any more questions? Any other questions? Can you pass me the mic? I think, on the present, I am studying about data science, and my future plans will be about innovation and innovation. I also see that web-based and blockchain is one of the new technologies and actually it will have such changes in the future. I don't know the impact of web-based and blockchain in the future, when we push into the market and more traditional solutions, what should we do to solve the problem? Wow. So he's like data science and stuff, and he's been like trying to work in like stock market and things like that, and he's trying to understand the impact of blockchain and directory in the other market. I guess it's more like, how we can apply all the knowledge, all the know-how. Yeah. Yeah. Yeah. Let me do one take first, right? Yeah. There's actually a great thing about Web3, especially the public blockchain like Ethereum and the layer 2 of Ethereum, all the data is available. It's almost like the data is on the blockchain. You can query and fetch all the data and it won't be in the private servers or in the silo environment like in the traditional market. So there's a great thing about it that you can get a lot of data and can handle a lot of things with that data. I think all the know-how or algorithms that we have in the traditional market can be completely applied to open markets like this. And there's also a great thing about that data. You can fully participate or do whatever you want with the algorithms and your strategy because it's permissionless. So you don't need to do anything like in the traditional market. Especially in DeFi, you just need an Ethereum address and you can participate in all DeFi protocols. You can do borrowing, landing, whatever. So that's a great thing about the public blockchain like Ethereum and the layer 2. I don't know if I can answer your question or not. I think I want to ask whether we can use any blockchain technology for all the traditional like financial data system. I think the traditional financial system... I think personally the traditional financial system is... Okay, how do I put this? Email versus physical mail. How many people here send physical mail? Go write a letter and then send a physical mail? No one does this. People use email. I think the traditional financial infrastructure will be just like physical mail in comparison to DeFi and the stuff we're working on now. This is the future of finance, what we're working on here. Yeah, I think the traditional financial system is going to be old. Like legacy finance or old finance. I think probably what we'll end up seeing is some mixture of traditional finance and crypto and blockchain. I think it's much more interesting to be on the side of innovation and know about this because it will become relevant in the future. Many big banks, big corporations will use this technology. Do you agree? Yeah, I think a lot of things like the market or the current financial systems will learn a lot from innovation and blockchain. I wonder how all the protocols and all the systems will work together in a comfortable and free way. We don't need permission, we need API keys and stuff like that. So how do we let everything run in a way that is connected to different systems and systems? Things that I haven't seen that exist in traditional finance. For example, how banks or traditional companies can open APIs for everyone to make all the different innovations on top of the existing systems. I think those things are trying to innovate in the future. But it will take a lot of time compared to an open environment and it has built up a philosophy that everything will be open and we will see where it will come from. I don't have a question, but I would like to give you an example about whether blockchain can replace traditional finance? Well, I found out that a friend studied marketing and had no interest in computer science. And when I got to know about blockchain and marketing, the thing I liked the most was the time to transfer money. I had a chance to work abroad and every time I had to transfer money from one country to another, it would take me from four to five days to work. When you use blockchain to transfer money, it only takes a few seconds and you don't need too many papers. I think that's one thing that will take a lot of time like logistics. I think that's it. As you can see, you don't have to be a technical person, you don't have to be an IT person or an embedded system, but you can still use an economic website that is quite active and flexible. Okay, that's it. Okay, last question. Where is the hand? Okay. Do you want to take this? So the question is what are the things or the concerns that a new developer should be aware of when they start with Ethereum development? To Web 2. So Web 2, they need to know about the server scaling, all the security flaws, and things like that. Yeah. Okay, so I would say things to learn in Web 2 development still apply in Web 3 development. They are still very relevant. So if you're learning about high availability, security, all of these things are still also relevant in Web 3. Web 3 is built on top of Web 2. Web 3 uses a lot of Web 2 technologies. In addition to things that you would normally think about or learn for Web 2, there are some extra things you will want to learn. Things like decentralization or how censorship-resistant is your project or how accessible is your project worldwide, how neutral is the blockchain on which you are building. There are some things that are different in Web 3 that you need to think about, but everything, most things you learn in Web 2 still do apply in Web 3. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yes. Wow. Yeah. Whoa! Yeah. Yeah. Yeah. Yeah. All of these concerns are still the same. If we talk about a different environment, we need to use different techniques to deal with them. But I don't think it's much different. OK? I thank you so much. Big round of applause. That was amazing. It was great to have him. Improvisation, but amazing. Amazing to have you speaking here directly to, yeah. Oh, yeah. We have one more talk in Vietnamese, exactly. Thanks for the mention, yeah, right after this talk. And but first, yeah, welcome back to Kevin, that we'll talk a little bit about data indexing. Yeah, up to you. Hello again. It's great to see you guys. You guys look amazing. OK, as I have probably already told you, my name is Kevin Jones. I am a developer relations engineer. So what does that mean exactly? Well, I work with developers that are building on Web3. And I help them learn how to build, learn how to create solutions that make sense. And more importantly, at the graph, I deal a lot with data, helping people organize their blockchain data and make it easily consumable in their applications. So that's what I'm going to talk about today. So I think we've talked a lot about the DAP architecture. So we have this concept of a decentralized application. You have a front-end application that is HTML, CSS, JavaScript, all the static assets. And this is the initial design, as you deploy that static application. And then you have your business logic or your smart contract that lives on the blockchain. And this is great. But when it comes to reading data from the blockchain, reading data from Ethereum is free. You can do a JSON RPC to get the current value of a variable. You pay for security the state of the variable to update that variable or to update anything in the smart contract. But for reading, it's free. So the nodes are not really incentivized to serve, I guess, quick and reliable amounts of data. And so there is this issue where it is a little bit slow and it's cumbersome, like the JSON RPC is not really optimized for reading data. Actually, the JSON RPC endpoint was originally created to manage an Ethereum node and not really to query. So what we see is something like this in the wild. This is actually real code at a hackathon where someone wanted to get all of the NFTs in a particular wallet. So all they needed to know is how many NFTs did this user have when they connected their wallet. So you have to do this thing where you create an object. You get the balance of the actual wallet. Then you have to loop through that balance and get all of the token IDs and then push those into an object and then display those as a result using the return. And this is OK if you only have two or three NFTs. But if you have hundreds of NFTs or thousands of NFTs, which believe me, there are people like that, this could easily take minutes to load a web page because it's having to go through and build this object. And every time it does that, it's doing a call, an ETH call, a JSON call, a JSON RPC call. And so this is just unreliable. So what we actually want to do is index the data. We need to find a way that we can index the data and make it highly available. And so the general method to do that is called the ETLQ. So you take the data, and this applies to all data, I guess, data science and data analytics, is you want to extract the data. You probably want to transform the data in a way that makes sense for you to actually consume it later, load it into some kind of database or some kind of object, and then make it queryable so it's easily accessible. So if we think about an Ethereum block, like every single 10 seconds, there's a block. Inside of that, there's hundreds of transactions that people are sending ETH across from each other. People are calling functions. They're updating state, whatever. There's a lot going on. And there's a lot of different protocols that are emitting these events. We talked about events earlier. We created a few and emitted those, and you know what those look like. So it's a kind of a mess. It's kind of a sea of craziness. So what we want to do is take those events, so a smart contract emits an events, and then we want to store those somewhere in some kind of database or some kind of consumable way. So what is the graph? Well, the graph is a solution or one of the solutions to this problem. It is essentially the data layer of Web 3. So we are a decentralized network of nodes. So similar to how Ethereum has a decentralized ethos to it. So does the graph. All of these nodes are running indexers. They're called indexers. And this is what you actually see live in the infotage of what it looks like. So I don't know how this works, but if anyone can tell me, that would be great. I feel like this is somehow rigged. But anyways, this is what the graph does. Is it organizes all those crazy mess of transactions into buckets that we call subgraphs. OK? So we take that initial architecture where we have the app that sits on the front end. We have the blockchain, the smart contract. It's still incentivized for the security of the network. But we implement this middle layer, this middleware layer. And that is called the graph, right? So what we can do, oh, I don't know what's up with the load time on this, but there we go. The graph is built, and I'm going to dive into this a little deeper, but it uses what's called GraphQL, show of hands. Who here has used GraphQL? A few of yous, OK? So it makes sense to talk about it then. The cool thing about GraphQL is it is called a query language, graph query language. So it allows you to do a query, pass in variables or data that you want, and then get exactly the structure that you want. So if you wanted to eliminate the token ID or the metadata or whatever it is, you can customize the query, and that will optimize the data response that you get back, right? So this is very, very useful for front end developers, particularly, because you can do a GraphQL query against your data, and with that same kind of code I showed earlier, we can just do one single HTTP query against the GraphQL endpoint to get all of the data we care about, so no looping, no building objects, just a single query. So again, we have the network participants. This number changes, but you can say there's at least 200 indexers running on the network that are indexing data, and there's also people that are just involved in the protocol, maybe even some of you guys that have staked some GRT, you can do staking, like similar you can with Ethereum. You can also curate subgraphs, so if there's DeFi protocols that you think are very popular, you can go on there and find those things and then add some stake there. You can also deploy your own subgraph if you're a developer, and you can get paid for the query's fees that go through that, so there's a lot of ways you can interact with the graph. And so in the end, I think the goal is to build truly decentralized apps, and in order to do the data in a truly decentralized way, you need something like the graph, which is a decentralized network. So here we have the same ETL queue that I talked about. So we, in this case, Ethereum, all of the events are available over JSON RPC, so we extract them using just a standard JSON RPC call. We transform those using a processing engine called OASM. OASM is basically a WebAssembly, and we use AssemblyScript, which is very similar to TypeScript. So if you've kind of used TypeScript before, AssemblyScript is very different. It's a little bit, it looks exactly the same, but it has a little bit less features than TypeScript, and you can process the data or transform it however you want, and then you load it into a database. So the graph is built on Postgres, so we have all of the indexers run Postgres, and that's where they store all the data for the subgraph, and then that's exposed using GraphQL, right? And the beautiful thing about this implementation is it is open source. We use Postgres, which is open source. We have GraphNode, which is all open source, and we use IPFS, which is the interplanetary file system, which we didn't really talk about that today, but it also is a very important part of decentralization. But we use all of those three things, so it's a completely open source and anyone can be involved. You can even run your own indexer. You don't even have to be a part of the network. You can just run it yourself. So this is kind of what it looks like at a high level. So imagine you have your DAP, right? HTML, CSS, JavaScript. You still deploy your smart contract on the Ethereum chain of your choice. You still propose transactions and make transactions to your smart contract, but this case your smart contract emits those events. Those events are picked up by what's called GraphNode, which is the open source engine that essentially does the processing of the data. You can think of it as kind of like similar to the EVM, but it runs a Rust program that is isolated and protected. So it runs that data. It does what's called mappings inside the WebAssembly and it stores those in Postgres and then it provides a GraphQL API for your data. So that same C of mess that you see gets kind of consolidated into something like this, where there's have these unique buckets that you can actually go to and then get the data you care about. So if you care about your into DeFi, you wanna look at Uniswap, which is our like most used subgraph. You can go on there and see all of the swaps that happen. You can see the TVL. There's all sorts of calculations that are in there. We have Aave, if you're into NFTs, we have Foundation, MakerDAO, Zora, whatever it is. You can search on the graph website. So if you go to thegraph.com slash explorer, any kind of Web3 protocols available on there. And if there's not one, you can build one and then you can get incentivized to store that data or to do that. This is very useful if you guys are at all interested in what we did today and you guys were very interested in the speed run challenge. I also did a full stack workshop. We have a special branch of Scaffoldeath that comes with the graph integration. It's called the subgraph package. And this URL will take you, if you just go to bit.ly slash full stack DAP or if you scan this, it will take you to the GitHub and then inside the GitHub, there's a video. So you can watch the video. It's about an hour and a half long. I go through the workshop and teach you about Scaffoldeath and I teach you about the graph and all that stuff that I just talked about in much more detail. I think I just want to show really quickly the graph website. So if you go to thegraph.com and you kind of take a look, when you first go there, there's a few different things you can do. If you're a developer and you want to create customized subgraphs, you can go to the subgraph studio. If you are a developer and you just want to get access to existing data that's already available, right? Then you go to the Explorer. So as an example would be like, let's say you wanted to know about, who here, raise your hand if you've heard of CryptoPunks. CryptoPunks, CryptoPunks, no. Pull the guys with Mohawks and glasses, no. Overpriced JPEGs. So let's just give you an example. Let's say you did a CryptoPunks, do a search. You can find all the subgraphs for CryptoPunks that are available. So if I want to grab this one, I can click it. Those are CryptoPunks, by the way. And you can come and see that this data is indexing. It's 100%. And you can see who's indexing it. These are all the indexers on the network that have indexed it. These are all decentralized indexers. And you can also see he was curating on it, but more importantly, you have this playground. And here you can say, okay, well, what do I care about? Well, let's say I want to get all of the punks, their ADs, who owns them, et cetera, you can just hit play, and it gives me all the data back in this easy to consume GraphQL API. So this is really cool because you can just plug this in to Python, you can plug it into whatever, whatever programming language you want, you can do a query. There's a lot of like GraphQL SDKs and ways that you can interact with that. There's also some Python tooling, JavaScript, you name it. There's tons of ways to get that data, and you can make a query, get that data back, and do whatever you want with it, right? So whether it's building a front end for some kind of DeFi protocol, or maybe it's you want to do some AI stuff, you maybe want to do some machine learning on it, you can get that data, and it's available. Okay, so yeah, if you guys want to get started, the best way to do that is to go to the docs. So anyone who wants to learn more about the Graph, go to the docs, and there is a section called the QuickStart, which is, there's some stuff about the Graph, how it works, but I think right here, the QuickStart, especially if you're a developer, is kind of the best starting point, so you click that, and it will kind of walk you through. But if you just want to in general learn about the Graph, there's tons of resources here in the docs, it's not loading right now. But if you go to thegraph.com, everything you need is there. Yeah, I'll give like five minutes for questions. Do you have questions at all? No questions? One, two, three, oh, I see a hand up there. All right, yes. Yes. I always pull at least one question out of the crowd. Yeah, so what is the difference between the Graph and like traditional block explorers? Great question. So the difference between the Graph and traditional block explorers, so traditional block explorers usually have centralized infrastructure. None of them actually, that I know, have used the Graph. Maybe some of them do, but for the most part, they're probably storing data in their own centralized solution. So I would say they're a little bit less trustworthy in that sense, whereas something like the Graph is we have, you know, let's just say for this example I just showed was a CryptoPunks and there's like 15 indexers. You can kind of guarantee that the data that is on those indexers is probably 100% correct because if one of those indexers operates in a malicious way, they'll get their stake slashed. So there is in the best interest of serving accurate data, whereas something like a block explorer could easily be hacked to manipulate the price, let's say of a token and show that a token maybe is worth more and if someone is using that as a source of the price, that could be a security problem. So that's the main difference is you're using a decentralized network which has a consensus and, you know, proof of whatever you wanna call it, proof of data versus something that's centralized that you don't really have a way to verify. Yeah, hope that helps. Yeah, okay, good, thanks. Yeah, good question, yeah. Any other questions? Awesome, you guys are amazing. Thank you so much. Love you guys. Thank you so much, Kevin, for all your talks today and workshop, you've been amazing. Thank you so much. Yeah, what's this after? Up now we have Leo, Oracle Research Engineer at the Ethereum Foundation. He's coming in a bit but he will talk about zero knowledge proofs and we'll do a little workshop on that as well. Thank you, First Asia and all the people here in Vietnam organizing this amazing event and expanding open source and free software around the world. Been in free software open source like for more than two years and it's an amazing community and a great purpose. So now I'm going to talk about the zero knowledge proofs, more from a perspective that is good for like a student of computer science or software engineering, but it's like zero knowledge proof are more kind of commonly talk in the sector of more like cryptography and the base is cryptography but has like a software engineering, has a lot of software engineering applications and it's starting to get to the general domain of software engineering, we're getting there. Although currently most people working in zero knowledge proof are cryptographers. I as a software engineer really that got into, huh? Is it stop working or perhaps you need to click on it? Yeah, yeah, I was not in the focus of the window. It's all, it's all, yeah. Ah, because it moved, okay. So yes, yeah, it's working, yeah, yeah, it's working. Yeah, because yeah, so I started working in the PSC that is kind of like the department in the foundation that works in zero knowledge. No, I have more like a background in software engineering and kind of like work my way into zero knowledge proof. And I think really zero knowledge proof is already ready for normal software engineering and for like computer science students in the software engineering students to learn it and start kind of building applications with it. And that's kind of like the focus of my presentation about how to understand it from this perspective of the software engineering. That's again, yeah, lose the focus. Okay, so what is zero knowledge proof? For if we want to explain enough for like kind of the cryptography that is based on but like from a point of view of what you can do with it. So it's a system that allows you to prove that you know something without giving all the information about it. And so you can also see if you are applying it to software engineering as a way of proving that I have done a computation. I can prove that I have done a computation from an input to an output without revealing all the information. I can reveal part of the input or not the input or the output or the intermediate values in this computation. So that's kind of like, what is zero knowledge proof as applied to software engineering? So there is like some examples that I put here some links as an example to kind of like trying to intimately kind of understand what is a zero knowledge proof. I will share this slide later, yeah. And this is like kind of like a very typical example. So in this case like Alice is color blind, okay? And Bob want to prove to Alice that he can distinguish two balls of various pink and well red and blue. So Alice is color blind and Bob is going to prove to Alice that he can distinguish the color. So what we do is like Alice kind of like puts the balls and puts them behind her back and she chooses whether to swap them or not and then show them back to Bob and Bob tell her whether she had swapped them or not. And if we repeat this many times and Bob is always right, at some point probabilistically, Alice is sure that both can see the different colors of the balls but Bob has not revealed to her what is the color of each ball. So there is like this privacy like hiding information like Bob doesn't have to explain to her which ball is each color. And anyway, Alice gets convinced after repeating this enough time probabilistically that the probability that Bob doesn't know which ball is which ball is really close to zero. There is another example here. I have example here like you can do the game like where is Waldo? Do you know this game? You have like this image like with a lot of things going on and this character is somewhere here and the game is to find it. And another example of zero knowledge proof is you can prove that you have found Waldo without telling the other person that you are proving to that so without telling you what is Waldo. So in this example, you can just like get like a very big piece of paper that is bigger than the Waldo story and you do a cut out of Waldo and you put it in front of the paper and you show Waldo through the cut out. That way you are proving that you have found Waldo but because the paper is bigger than the comic, that way you don't have to like the person is not revealing where is Waldo. It's just revealing that knows where is Waldo. So this is the concept of zero knowledge proof like kind of explained with this physical example. Any questions about this? Everybody understand this? Okay, let's continue. So what is this useful? What is this useful? One of the main purposes that the main things that you can use this in software is for privacy. So you can compute things and you don't have to reveal all the information so for example in blockchain you can use for privacy in blockchain transactions or for example there is an application that a PSC is working like with the digital ID of India and on Hadar. So you can for example generate a proof that you have certain age without revealing the rest of the information of your ID. Then there is a scalability. If the computation I'm proving that I have computed like normally if I tell you okay the result of this computation is this. For you to be sure that I'm telling you the truth you have to compute it again and see if you get the same result. With zero knowledge proof I can give you a proof that I have computed this and that that is the actual result and probably very fine the zero knowledge proof takes less space like less memory and less computation that the computation I'm proving so that give us like the power of scalability. Now that's what like the CK rollups use it for for example. And then can be used also for interoperability I can prove you facts about a public blockchain for example and you can believe me and communicate it between systems and between blockchains. And then we have like this is the concept of zero knowledge proofs and now the kind of like the innovation that is kind of making these kind of being usable in software engineering and through creating applications is the dimension of the general approving systems. So we have systems that allows you for a general computation to create a zero knowledge proof. Before this you have to kind of work out for each problem how you can create a zero knowledge proofs. For example with a proofing system using a proofing system I can create a proof of bubble sort. So I can create a protocol with this proofing system that you can give me an array and I can prove you that I have sorted it with bubble sort perhaps sometimes without revealing if I don't want the sorted array or the intermediate values or for example for a Sudoku I can create using the proofing system as a protocol that you give me a Sudoku and solve and I can prove to you that I have found the solution of the Sudoku without revealing you all the numbers in the Sudoku. So that's kind of like everybody understand at this point because this is kind of the idea is to generate more like kind of questions so we can explain the things but yeah, okay, okay. So the main misconception like people if you already know or heard about zero knowledge proofs from your study software or your web two developer kind of like these ideas that you need to do to need to know a lot of advanced math to be able to do zero knowledge proofs and to build zero knowledge proof applications and I don't think that's true. Now we have more languages on top of proving systems that are kind of helping you immensely so you don't need really to know the underlying math that zero knowledge proof help based on. You need this advancement to create the proof systems but you don't need in the same way like someone can learn Python without really knowing how microprocessors work with this proven system. You need to do this known is math to create the proven system that is like the CPU but you have these kind of things closer to Python although not that far that are the proven systems and the languages that allows you to create these zero knowledge proofs as easily. You know that very popular known language is Silicon that make it easier to create zero knowledge proof and we are working in Chiquito at PC and there are many others now languages that make it more easily to build zero knowledge proofs. There is like, it's still a skewer sector like what more people work from cryptography. So everything is explaining cryptography terms yet and there is not so much kind of education material for software engineers. So we're a good source I think is zero X PARC have a very good couple of tutorials in Silicon and Hello2 that are very good. Okay, so what is like when you are building your zero knowledge proof protocol using a proven system, what are as a software engineer what are the things you have to consider, okay? So the first thing is the witness. What we call the witness is kind of all the data about all the data that you are creating the proof about. So the witness, usually if you are thinking we're creating a proof of a computation of algorithm, the witness includes the input, the output but also all the intermediate values that we're doing in the computation. And like talking about the zero part of zero knowledge like some part of the witness is private. So sometimes like we call advice to the private part and instance to the private part but the whole witness in proven system usually you arbitrarily can choose kind of like what part of the witness is public and what is private. So what only the one generating the proof will know. Then there is like kind of like the setup or the circuit or the aromatization. We don't call it by different name but it's kind of like basically from a higher level point of view, from an application building point of view is a series of like constraints of assertions on the witness. So we are saying, okay only the witness that follows this aromatization, the setup, the circuit are valid, actually we are proving that we have done this computation only if this setup matches this witness and it's true for this witness, okay. And then there is the witness generation that is kind of actually the algorithm itself that we are proving that is generating all the witness values. That's like different things you need to consider as a foreign engineer. Then there is the proving and the validation key. So for the circuit, for the setup, we get two keys that are both publics and the prover having a witness using the proving key can generate the proof, no? And this that they can generate only a valid proof is if the witness is kind of matches the constraints that we have put in the setup. Okay, this is kind of clear until now, yeah? Yeah, you all know it already? Okay, so the validator is like can get a proof and just with the public part of the witness and just with the validation key can check if the proof is valid. So the validator will be sure that the prover has a witness that matches the setup and that also these witness like the public part is this public part, okay? So I try to explain it here in a very cool diagram, okay? Okay, so let's see if everyone kind of has a side. So we are trying to generate a public, a signal knowledge proof protocol for a specific algorithm, okay? So what is the developer kind of like have to build two things, two programs, okay? You need like the normal doing normal programming have to build the witness generation, okay? And like in what is called like the renaissance, the setup, the circuit is going to specify kind of which witnesses are valid, which witnesses are always the result of the algorithm we want to compute, no? The witness contains all the information including intermediate values, input, output, no? So this arithmetization defines what is valid, no? So for example, for a sudoku, the arithmetization defines what sudokus are valid sudokus, no? Okay, and the witness will build the intermediate values to calculate the sudoku itself and on the intermediate values to calculate the sudoku, no? And then from this circuit, the setup of the proving system will generate a proving key and a verifying key, okay? And then this is like the star are kind of executed for different inputs are executed many times, no? Like each input, so in the case of the sudoku, let's follow with this case, no? Like the input to be kind of like the unsolved sudoku, the witness generation would generate like kind of like a solved sudoku, okay? And then the prover with the solved sudoku, the proving key can generate a proof with the public part being the unsolved sudoku and the verifier, there is another person with the verifier can take this proof and be certain that this prover has solved the sudoku without receiving more information that was made public in the protocol. I don't know if like everyone understand this. So we'll kind of like overview from kind of like a programmer point of view of what they have to do to kind of generate a synology proof protocol, yeah. Okay, okay, that's very good. So I have some, this is going very fast. This is the time that is going faster. I have like some example code to show you kind of like how is this in Silicon, okay? So very, very simple example, no? Like the computation we want to prove is like this equation, no? X to the third minus X plus seven equal Y, no? So with the proof system, we can, for example, prove that we know an X and a Y that matches this equation. And then we can, depending on how we define the circuit, we can even know reveal X or Y or only reveal Y or only reveal X, no? But like the verifier will be sure that we know a solution, okay? And this in, we're talking about witness generation and the kind of the set up part of the circuit part like on the witness, no? So let's identify a bit here, the different parts, no? Like here is that are called signals in Silicon. This is kind of the witness, no? So our witness in this circuit has for component X, X square, S cube and out, okay? X is input, out is an output, okay? And the rest of the signal kind of intermediate values, but all of them together are the witness, okay? And then we need to do the witness generation that is done with the single arrow in Silicon. We basically, this program is executed, well, yeah, this problem when we're calculating the witness, this problem is executed and the arrows kind of like assign values to the signals and hence to the whole, to the whole witness because X is given in the input. And these are the constraints. These three equals defines the circuit, like what are the possible values that are valid witness. In this case, they are the same. And in the most simple cases, sometimes they are the same. So that's like there is an operator in Silicon that is like the double arrow that does both things at once. But I think it's clear to kind of like show that there is like two different things. These defines which witness are valid and this is one way of generating the witnesses, no? We need to use X square and X cube because like in Silicon, we cannot have like in one constraint, in this arithmeticization, we cannot have more like the power of two, like more than a degree to polynomial, no? So that's a constraint of the arithmeticization. So that's why we need the X square, X cube. But this kind of like, what I want to explain, this kind of defines, okay, like the X square, X cube out, there are valid witnesses have to follow these rules. And this is a way of generating these values that follow this rule, okay? But there can be other ways and that's okay. So with this program, using this code on Silicon, using Silicon, you basically can do this, no? Like the witness agent and the circuit is kind of in the same in Silicon, it's in the same kind of code, no? So the witness generation is the single arrow and the circuit is the triple equal and from that note, you can execute all this. From the circuit, you can create the keys and then you can do this for all the X, you can execute like, for all the X, you can execute the witness, what I mean the single arrow, you can execute it for any X, this case VX, the input, this generate all the values, the four values on the witness and then the prove it could generate proofs that include the part we want to make valid for example, X, so we would prove that we know a Y that given an X follow the question. And yeah, yeah. And then the verifier can be sure that the prove knows the solution of the questions without having to compute the whole equation. So we can imagine like if this, instead of the example, we have like a very complicated, very, very, very hard computation to do because we can do this like much easier, this can help with the scalability, no? Because I can give you a proof that I have that the result, the final result of this very complicated computation is this one and you can be certain without having to calculate it again and seeing if I'm telling the truth. And this is one of the ways that is used mostly in blockchain for rollups and L2s and all that. And that's kind of like completed. Thank you very much. And if you have any questions, let me know. In the sitcom language, right? There are two steps after two. I have the witness generation and I have this circuit earth realization. Yeah. If these two statements don't match up, does the compiler like verify that and tell me or does this blow up in my face at runtime? No, like if the, do you mean if, wait, wait, do you mean if you present a witness that doesn't match the triple equal equations? Yeah. In a second. So up there I say out is cubed minus x plus seven and down there I say plus six. Yes. What happens? So you can, so these, so only if you present a witness that follows these equations, you will get a valid proof. So if you change the equations, you will need to present a witness that follows these new equations. Okay, so me as a programmer, if I make a mistake there, the result will be that provable only. The provable will generate a invalid proof. If you present a witness that is not, doesn't follow the equations, the provable will generate a invalid proof. Okay. So the verifier will know if it's valid or not. Yeah. If your witness, the verifier will know if your witness matches your circuit because the proof is valid or not. Okay, okay. Good, okay. Any other question? I have one actually. Do you have examples of zero-knowledge use cases or applications that are alive today? Alive? They're alive, yes. Yes, like well, all the polygon Hermes, scroll, all the CK roll-ups, CK sync. Yeah, that's the one that I'm more familiar with, no, we have tornado cache. Yeah. So tornado cache is for privacy and CK roll-ups for- Scalability, yeah. Yeah, so yeah. Interesting, thank you. All good? Well, thank you so much, Leo. That was great. Thank you. Thank you so much. Thanks again. And last but not least, we have Nam, a researcher at the Foundation as well in the PSE team, Privacy and Scaling Exploration Team at the Ethereum Foundation. And the talk will be in Vietnamese, so thanks again for staying with us until the end. That's gonna be a great talk. We just need to set up and we'll be ready in a minute. I'm sorry, I can't understand. We can take a look at this example. We have two little kids, one is Alice and the other is Bob. These two are friends, right? Well, we have a competition that's very similar to the others. After the competition, we'll have a competition like this. The question is, when we meet, who will be more likely to receive the award? Right? This is a situation where we want to know who has more money but we don't want to... Oh. We don't want to... Okay. Bob doesn't want Alice to know how much money Bob has and Alice doesn't want... Alice doesn't want to... They don't want to know how much money we have. Right? But they still want to find out what this problem is. Okay. So, what will be the answer to this question? I think we'll have a very simple answer to this question. For example, these two are together and this is a very honest person. It's clear that when they talk to this auntie, Alice will tell you how much money Alice has and Bob will tell you how much money Bob has but she can't talk to the rest of them. And now, the second rule is consider who has more money. Tell the two of them. Right? So, after we have enough information, she will say Bob has more money but she can't say how much Bob has and how much Alice has. So, this is clearly a solution that these two kids need. I can see that this scene is very similar to what is happening in our daily life. For example, I will send a message to a group of people who believe in each other. For example, there is no way to guarantee that this auntie is a very honest person. I don't have anything to guarantee that Facebook will be honest with me and Google will be honest with me. In fact, I have also seen a number of cases where they are actually acting on their personal data that we don't know. Right? So, my solution is when there is no truth or when there is no truth that we believe in, what is my solution? I will use the name MPC. MPC is a tool that can be built with a machine. When I use this MPC, it is exactly the same as when I use it. From the scene that I use, there is no change at all. It can be changed in any way. I will just change this box. OK. So, what is MPC? MPC is the structure of the name Secure Multi-Party Computation. Multi-Party is Da-Ben, right? So, this is a structure that supports Da-Ben, but there is a guarantee in it. So, I can imagine that this MPC is a black box when Alice and Bob give their own personal information such as a XA a XA piece, a XB piece, then this box will press XA on XB and return it to I. When I use this box, there will be 3 important things. The first thing is personal information. When Alice and Bob share this box, this XA and XB piece will not be left to the other side. The second important thing is Independence of Input, which means the independent information that I put in. So, I can imagine that it will be great. When I use this box, both sides will have to put the information in at the same time. There is no other way that can change or put the information in the box with the value put in. This is a very good idea of this MPC. The last important thing is the XB piece. It is not a natural mechanism or a different mechanism. To explain Leo, he explained about the ZKP tool, right? The ZKP and the MPC have a very close relationship with each other. The ZKP tool allows to prove that there is something in the scene of the MPC it means when I explain this tool I will have every step from the beginning to the beginning. The ZKP allows me to prove that I know how every step is performed and every step is a true performance. The ZKP when I use such a tool to prove that there is a existence of an explanation I mean that my approach is true. Right? But when I look at the ZKP, it is more general I think I will have two sides one side is called Prover and the other side is called Verifier. The Prover side is like a student and the Verifier side is like a teacher and the teacher wants to verify that for the ZKP student will have a word W and for the teacher it is not really important what that word is right? But you just need to know that the word is correct I mean this W is an explanation for X it's just that simple so here I will see that the ZKP clearly is an application of this MPC Let's look at this box I also have two sides one side is called Prover and the other side is called Verifier and the other side is called Verifier and the other side is called Verifier and the other side is called Verifier and this X is exactly the X side that is important so here I will see that there is only one side that can have a secret that is the side of this Prover is the explanation of this secret and the Verifier side will be a completely application but when we look at the ZKP it's just an application of the MPC but because of that the ZKP can have a higher effect that is the MPC so when we have a special application we will have a better explanation of the MPC and when we use the MPC and the ZKP we will have some observation here but when we have an application of the Prover we will have a Prover because actually the ZKP will prove that we have a correct process for a Prover or a Prover when we want to have an explanation that is not known by the Prover we can have some information and we will have an application that protects the privacy of the Prover for example we will have ZKID like the Semaphore which means that we can prove that we have a quick understanding of some conditions because we are 18 years old so we can buy a tree but we don't know the age of our body or we prove that we have a visa but we don't have any information but we don't know how old we are and where we are and we only know how old we are so this is a scene that I see that we only need the privacy of the Prover but we will have an application that we want to have privacy for both sides when we need to use MPC for example we look at another machine learning machine learning is learning machine after learning it we will want to use it to do that after learning it we will have a model and through that model we can value a new model that belongs to a class like that so we will see that we can only protect the privacy for one side so we have to choose if we want to protect the model or the color we have to choose and adults can't choose so we can use MPC so MPC we can upgrade the GKML PPML Privacy Preserving Machine Learning when both the model can be protected in addition it also has a number of applications but we don't have time so we will leave this part when we upgrade from GKP App to MPC App we will be able to protect more one side and if we really just need to protect the privacy of one side and this is another I don't have time to talk about so I will leave it and then about the technology of making MPC we have a technology called Gable Circuit it's like a surface that can be painted or it can be mixed when we look at the way we use this technology everything will be around this box now we have this box we said the material from Alice and Bob is a network and a 3-part vector and we want to set the direction of it this is a model of the direction we will set XA0 and XB0 and then we will set XA1 and XB1 to set the direction of it and finally we have XA2 and XB2 and we will get this E so at this time we will see that we can control it or make it not too special we just need to control too many things we just need to control the particles if we have a box that we can control the particles inside it we can create any face we need this is a picture that I made this is a face with 3 particles after we finish we will combine this is a face that we can combine we can create a face that we can combine first, this is a human we combine human after we combine we will have a result that we can combine and we can put these 2 into a common common after we combine we can put it into a common common we can make it into a common common like this and another point for this face with 6 particles we can understand that this face with 6 particles is a MPC that can support 2 sides but it can support 4 sides 1 side is GAP and the other side is the one that can support 6 particles GAP is the side that can support 6 particles and this side for the elevator this elevator because this side has 6 particles the elevator needs to take some particles that can help to make the input is on the elevator after we have enough information XG and XE then the elevator can solve this and it can be solved and if we are interested in this result then the elevator can send this result to the elevator and it has a very good quality that means this elevator doesn't have too much too much balance between 2 sides but it only has 1 step 1 step and the result is after 2 rounds we can have a good balance or a similar process for example if we want to talk to the US the internet will not be good at this time if we talk we tend to talk too much then instead of using this double circuit we can have 2 rounds after the elevator there are other techniques that will have more rounds so I have prepared a slide about this but I will go through because it requires a lot of knowledge so I will go straight to the how to use it so after when we are at the level of development do you want to learn about machine learning or do you want to use this MPC in your work you just need to know what is the concept and how to use it and the most important thing is this model how to model what you want to do so when you use or use MPC technology it will revolve around how to model what you want to do how easy it is so there are many ways like using this MPC you can use how you like how you like to run through a train how you feel you can choose when you model what you want to do you can focus on the model or MPC circuit or MPC circuit macro you can model this MPC circuit it will allow you to model this macro it is like supporting a number of supports just let you calculate the model can help you to calculate on the 32 bit or 64 bit it will be more convenient for example here is calculate on every bit and also in this MPC circuit besides the circuit you can calculate on the normal circuit you can also use API for example there are 3 types of A, B, C and what I want to check is I have A, B, C and A I want to calculate A and B is it bigger than C right? I will calculate A, B then I will calculate D by multiplication then after you get this D and if D is bigger than C then I can calculate D by C and after I get this D by C I will check if this E is bigger than 0 or not here I will use multiplication multiplication multiplication it will be more convenient if I model actually the way I model is just fun of course I want how I can model in a more easy way because even when I use the easy way it also has a lot of complicated logic like Leo also introduced this circumference that is used to model a face but this model it is quite unexpected it is almost not too much with with the commercial companies for example here I see that I want to see if A but B is bigger than C there are a lot of steps like that then in circumference this is a example of circumference that I plan more plan the direction of two vectors A and B each vector has 3 parts and the way I use the way I go from the program to the circumference so now I can do that with the circumference circumference then it will become a face and this face will be put into the model MPG or MPG Bm16 then this is simply a line to plan on this face then I will plan the result for example circumference with circumference simply you write the program circumference with circumference then it will pass this line then one side is model one side is model then you will have the result of the circumference it is still the how to have the circumference with circumference with circumference then if you don't like MPG circumference or MPG with a different circumference for example now there is MPSpeed or Motion then it also supports the double circumference like MPG then the last I want to share is the methods that present the circumference with the circumference it will not be very convenient also not have a high performance then usually I will need to do some some special circumference for example circumference or a circumference that can be calculated in a simpler way or some optimization some optimization I can put it in for example I will see that when I study the machine study the machine for example here then you will see as I because I use a technique called Gabo circuit there is Gabler and then for Gabler this is not a secret right? instead of a circumference on the two circumference I can fully realize a circumference and the circumference with a number that belongs to the input that Gabler already knows then some some optimization to be more accurate or the way to change between the number of numbers and the number of circumference is easier then these will make increase the performance of the machine by itself then there are some other how to know that the input information on one side is correct or wrong like asking for the right number or asking for the right number or asking for the right number then I can check before running this mpc to avoid the end of the discovery of the wrong result then it will be very good or a few other related to the circumference then you can scan in this link I put a lot of information technical information if any of you want to find out more you can find out there any question for now I would like to ask what is the use of in the web 13 it's a good question now I will see I now I don't see too much of the web 3 but now web 3 through the blockchain do you want to see the amount you receive you don't want to see then mpc will use it or now you have some money on the blockchain you want to go to the market at this time you will have to perform some example but I don't want you to know the model how to divide your money or your transaction history there is a way to divide your money you have to use mpc now tomorrow I will talk about the alliance and bop when buying the alliance how to go bop alliance I can speak more clearly this model it's just a a very normal model this is for example this is a computer program but this is a different program just sending information nothing special ok thank you so much I hope great I hope you liked it I think that's a wrap for the day do you want to say final words we have a meet up tomorrow we will put up a QR code we are organizing a meet up tomorrow at the periodot hotel I will put the QR code you are all invited to join we will have a panel and drinks and food that will be amazing what else I I just want to say thank you all for listening thanks to all the speakers those who are still here to Fashaya's team and Jack for inviting us and tomorrow night we will have a meet up with free food free drinks and a panel about Ethereum in Old Town Hanoi this year when you sign up writes in the form writes Fahs Asia Ethereum Builder Day Fahs Asia Ethereum Builder Day and we will approve it that's your reward for staying until the end and then if you are still interested in learning about Ethereum later this year it's called DEVCON DEVCON is the Ethereum Developers Conference where you can hear talks like you heard today but in more depth and with thousands of other people who are interested in learning and building on Ethereum this event is coming to Bangkok in November to Thailand in November and so if you are interested in that I think there is more information on this QR code probably I think so so the left QR code you can scan to find more information about DEVCON there will be discounted tickets for all everyone from Vietnam so there will be very much discounted tickets for all of you and thanks to Natan for emceeing the day thank you all see you later