Austin Griffith – Intro to Scaffold-ETH 2 and SpeedRunEthereum! by Austin Griffith | Devcon SEA
Devcon·Tue, Oct 7, 2025, 12:00 AM
Speaker
In this session, we’re going to dive into Scaffold-ETH v2, a toolkit we built to make developing on Ethereum way easier. We’ll take a look at how it works, why it’s super useful for quickly spinning up projects, and how we can use it to tinker with smart contracts and hook up the frontend. ⚙️ Scaffold-ETH 2 is built using NextJS, RainbowKit, Foundry/Hardhat, Wagmi, Viem, and Typescript. Whether you’re new or experienced, we’ll get you to SpeedRunEthereum! Speaker(s): Austin Griffith Skill level: Beginner Track: Developer Experience Keywords: Open Source Software, Public good, Tooling Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum, https://warpcast.com/devcon Learn more about devcon: https://www.devcon.org/ Learn more about ethereum: https://ethereum.org/ Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on Swarm, IPFS and more. Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. Devcon SEA was held in Bangkok, Thailand on Nov 12 - Nov 15, 2024. Devcon is organized and presented by the Ethereum Foundation. To find out more, please visit https://ethereum.foundation/
Transcript
you [Music] [Music] [Music] some some small things with that and then we're going to go through speedrun ethereum and we're going to kind of just like look at this curriculum and kind of talk through each of the like learning moments that you'll go through when you go through speedrun ethereum so let's uh let's get started with scaffold eth first scaffold eth is a Dap developer tool it's great for tinkering with your smart contracts and it has this Auto adapting front end that is really nice when you're tinkering around with your smart contract so I'm going to run this what Devcon 2 this will be my second demo today maybe we'll do Foundry this time so uh scaffold eth is uh a Dap building tool like I said uh it uses nextjs rainbow kit wag me typescript and you kind of have the choice between hard hat or Foundry um it's uh a a great tool for prototyping you can quickly get something out uh uh out the door I I think I deployed earlier I deployed an app in like 20 minutes and uh we had lots of time left for questions so I'll do the same thing probably uh uh now it'll probably go pretty fast but let's uh let's let's let this thing install and then we'll go Tinker with scaffold eth Devon [Music] to okay bringing the code up here it's still installing so we've got some time but let's go look in here you kind of have these two main packages there's either Foundry or hard hat that's kind of like your back end that's your orchestration tool that's your deploying and testing and then nextjs is your front end scaffold e does some really nice things where when you compile in Foundry it injects those artifacts into your app and we'll see that in a little bit but it's really nice when you're working on your front end and it knows about all your smart contracts and all the variables and you can kind of it'll Auto suggest how to fill in stuff there's I see a couple of people that were in the last talk sorry this will be a refresher for like 10 minutes here and then we'll get into speedrun ethereum okay so uh let's see is our app up here we're going to go look at our contract and it's a basic contract uh has a lot of uh initial Concepts that are here like Primitives and data types and events and Constructors but it's a greeter it's a greeter contract and let's uh fire everything up so we'll do a yarn chain to bring up um let's CDN first Devcon 2 and then we'll do a yarn chain and that will spin up our local blockchain and that's what we'll deploy to and then I'm going to do a yarn start and that will bring up our front end and it's the two things kind of working in Symphony that is kind of the magic sauce of scaffold eth and then we can yarn deploy here and what that is going to do is ship your contract to the local chain compile and deploy there we go okay so so we're compiling and we're deploying and kind of the the heart of scaffold eth is that you can have uh your app up here and you can have your code up here and you can make small changes to the code and you're going to see those changes reflected in the front end so if we go over to the debug contracts tab again sorry for the repeat if for people who are at the last one but it's good to run through the concept here uh let's uh let's look at the greeter contract real quick what do we have here so there's a greeting and it gets set you send in a string and it gets set so let's just do that real quick it's G to it's going to yell at me for not having gas when I hit this it's going to say something like oh wait wait wait wait wait wait we're still connected let's get out of here we want burner wallets okay so I just disconnected my metamask uh and the first concept here is burner wallets uh you'll use these in Dev rather than in production you don't usually use burner wallets in production very often but they're really nice in Dev because you can just like hit a button here and it sends a transaction without having to uh have the dialogues come up and have your chain ID write and all of that in metamask uh it's telling me I don't have any gas but if we click this little faucet button here now we have some eth and let's see if we can set hello world yep there we go so now we see Hello World there right and that was from this thing here and uh like I did in the last demo I always like to look at this little premium flag and Dink around with this so there's this piece of code here that says if they send in some value then we set a premium to true there's some flag called premium and so let's just send in some eth and uh also there's no decimals you need to convert it to we by multiplying times 10 18 and there's a little button to do that of course you don't want your users to have to do that this is something that you'll do and this is like a developer kind of thing but in the front end you would just do this behind the scenes okay there we go so it's true now we were able to send in some money and now there's money in the contract and we're able to uh set the greeting and have that little premium flag set okay so um debug tab like this is really nice because now I can go and I can add some code right what if we wanted to uh make an address public uh uh I already have owner what will this be beneficiary beneficiary and we'll set that equal to some other address let's just set it to this address oops oh man I don't know what I did there copy this okay paste it in there we go okay and when I hit save and deploy this now Watch What Happens we're going to get a new uh beneficiary over here oops deploy so I'm watching for that to show up here and sure enough there it is there's the beneficiary so notice how that just Auto adapted like all I all I did was add a line to my contract for beneficiary and deploy it and then my front end recognize that new variable and displays it here so you can really kind of Tinker with stuff and play around with however you want your smart contract to work and kind of test your assumptions um uh let's see let's do this let's uh let's test some assumptions here so there is this withdraw function down here that lets us pull the eth out of the contract and it's checking is owner I'm going to take that is owner off of there and I'm going to write a different require statement I'm going to require that the message. sender the person calling the function has to be equal to the beneficiary or it'll say not the beneficiary so instead of the owner we're going to have this beneficiary that can do this withdraw so what I want to do here is I want to try to test this I want to see how this works and test my assumptions and make sure this works the way I I think it does so the way I would do that is uh I need to sort of withdraw as the beneficiary and then I'll I'll kind of try to withdraw as a bad guy and it should not work as the bad guy and it should work as the beneficiary so let's do that let's try that out real quick okay so now uh let's let's set the greeting real quick and send in some money just so there's money in the contract okay so now there's a couple bucks sitting in the contract right and then uh let's call withdraw but let's call withdraw as a bad guy so to create a new account you can do this really quickly by just opening up an incognito window and going to Local Host notice I got an address here kind of C2 C4 now if I close this and do it again new incognito window I'm going to get a another new address there okay so let's grab some faucet funds and let's go over here and let's try to withdraw this $33.39 hopefully yells at me and says something like not the beneficiary very nice and real quick let's see if this dude can withdraw it should let's find out uh did I click it there we go and the money's out of the contract okay so like I said testing your assumptions right like I made this line of code that said only the beneficiary can call this withd draw function and then to test it basically tried as the beneficiary and then tried as another account and proved that it only works for the beneficiary not for the other one now that's not exhaustive testing of course you would want to write a more extensive test Suite eventually but for just thinking around trying things trying to figure out how you want your smart contract to work this this is a really uh kind of quick way to uh iterate and try things okay so scaffold eth uh is great for uh this this kind of prototyping that we're doing here then eventually you'll move over to your front end and you'll write some react I'm not going to do that uh I already did that earlier we'll do that tomorrow and yeah let me show that real quick so tomorrow like all day long we're going to have a build Guild community-led session I'm not even sure where it is which where like that way do you know where the CLS is oh it's upstairs Okay cool so we'll have uh a big room and we'll do intro to building on ethereum in the morning and then in the afternoon we're going to have a capture the flag so it's going to be a um challenging uh uh challenge it's going to be a challenging challenge but the the the guys at build Guild have build like 12 different challenges starting from easy and they get harder and harder so come come by uh the community-led session tomorrow just look for build Guild we're we'll probably be upstairs uh okay so scaffold eth is kind of the underlying tool here but what I'm really going to show off mostly is speedrun ethereum today and we'll go through each one of these challenges uh but let's see have we have we basically covered most of the scaffold eth stuff let me see if there's anything else I want to talk about here with scaffold eth probably aren't going to deploy any contracts I think the front end will be taken care of for us I I think we're good I think we're we we've tinkered enough with scaffold eth uh let's go ahead and start working on speedrun ethereum like I said uh the underlying technology here is scaffold eth but this is uh a nice curriculum that'll take you slowly through building your first uh five apps on ethereum uh starting with just like a simple nft app so what you'll do here is uh you'll deploy uh an in ft smart contract so you'll go through these settings you bring up the chain you deploy you'll have a front end uh gas and wallets we've kind of already covered this but we're using burner wallets you'll go to uh the faucet to get some funds uh yeah again we're using burner wallets not metamask so you're just kind of like learning burner wallets here first and I think maybe even you send around some eth here and you use the faucet to to fill up your account uh and there's no code in this first challenge this first challenge is just about kind of calibrating your uh the tooling and getting used to uh how scaffold eth works but you'll go to the my nfts tab and you'll hit this mint item button and that mint item will mint you an nft and you can get in and look at the Smart contract and see how that all works uh maybe we'll run through some of these in a little bit but let me just kind of cover H maybe maybe we should just run through it why not we got lots of time uh we'll we'll go through this slower tomorrow if you want to follow along but um I'm going to just go ahead and clone it down might as well go through the first challenge here oh I already have it there huh simple nft 2 all right oh boy that might be too slow okay well uh let's just follow along here maybe that'll come down eventually oh yeah it did okay what do we do a yarn install uh here let me just follow the instructions even better okay so we CED in oh I need to get check out the simple nft branch then I yarn install okay I'm going to close the rest of this stuff from the old terminal we don't need any of those anymore okay and we'll do the same thing that we do with scaffold eth where we bring up yarn chain and that that's going to run our local chain and then we'll do a yarn deploy and that will deploy our smart contract to the chain oh whoa sorry okay and then we'll do yarn chain weit we did yarn chain now we'll do yarn deploy and that should deploy our smart contract to our blockchain and then we'll do a yarn start and that'll bring up our front end and it will look familiar it should be very very familiar to scaffold eth because it is okay so here it comes let's see we're going to have our app up at Local Host 3000 there we go here is our app here is the burner wallet stuff we can hit this button to fund our wallet let's see what does it have us do it has us go through and get some gas is it sending yeah I think oh I see this is just the faucet we can skip this if you I I would recommend uh on your own time going through speedrun ethereum and going through each one of these challenges I'm going to kind of like briefly go through them but I probably not going to go slow enough that you'll get everything from it so I would I would recommend like going home and going through speedrun ethereum at home sometime okay but let's see what we have so it's going to tell us to what mint some things let's do it let's go to my nfts and let's hit mint what's going to happen here yay there's our first nft let's mint another one okay and I think the directions say to send them around yeah yeah okay so we're going to create an incognito window right so we have a second account and we'll go to Local Host and you'll notice there's kind of like this like kind of red and teal guy and then there's kind of like this green dude here so we're going to try to send the Buffalo to the green dude I think I can do my nfts here okay let's let's try to send an nft to this dude so I'm going to copy his address then I'm going to go here to let's send him the buffalo uh I need to put in an address so paste that in now hopefully this fires off a transaction and sends the Buffalo yeah all right he got it okay so that's that's most of the first challenge I think is basically just like I said kind of calibrating your your tooling and getting ready uh you don't really have to actually write any solidity but let's go uh look at the Smart contract real quick just to see it see what the nft contract looks like okay and if we go to packages again and you either have hard hat or Foundry and then you have nextjs if we wanted to look at that contract your collectible is what it's called notice we import a bunch of things from open Zeppelin to make that 721 work uh ownable and counters and then we inherit all of those things and you can see there's sort of like a base URL so what happens is it it stores a base URL for the nft and then it puts the nft in ipfs and then puts the hash of it in the smart contract and here's the mint item pretty straightforward we're minting something incrementing the counter uh some before transfer hooks but that's it there's the there's the token Ur URI right there let's go let's go actually debug that and look at that token URI real quick so if I go to here and I go to debug and let's see what what can we do we can get our balance whoops didn't mean to disconnect I'll take the burner back please there we go so we could check our balance let's see what it is it's one right we own one of them and then if we maybe look at who the owner of token ID one is it's that other dude token id2 is us okay and then let's get the token URI so if I say I would like the URI for token 2 it's going to give me this ipfs link and if I follow that it should be a description about the the NF and uh an external link to the zebra there it is very nice okay so that lives in ipfs and then this stuff is also an ipfs but it's kind of like a manifest and then the hash of that goes onchain and lives kind of right here it's kind of hard to see but it's this qmv thing it's that right there that's the unique identifier of the content okay so let's see is that basically challenge one let's see what else we need to do we minted it we sent it around oh okay so what it's going to have us do now would be uh deploy the the thing to sepolia so instead of deploying locally we would deploy to a public network and then probably do the same thing where we send it around I'm going to skip this I think um just because it's it's going to be the same thing it's just nice to have it on a public network and that's how the auto grading works when you're doing this at home you'll hit this submit challenge at the end and you'll put in your deployed URL wherever the versel site is that you create and you'll put in the um link to your contract on ether scan and we have an autog grading system that will then go through and grade your challenges and let you know if you got it right or not and so each one of these challenges you turn in and then the auto grader grades it uh but I'm not going to turn this in and I'm probably not going to ship this even to sepolia but uh it's it's uh right here in the directions pretty easy to do oh even contract verification very cool what you can do is verify the contract so then when people see it on the test Network or when they see it on the Block Explorer they can actually see your code which is really nice okay let's just let's call it let's say uh this is this is good let's let's move on to the next challenge and uh really start look looking at some code or looking at um an actual challenge I think this this first challenge was just like basically spinning things up and sending them around but the decentralized staking app you will have to write some code so uh this challenge is about building a smart contract that allows people who don't trust each other or adversarial parties to coordinate uh in this case they're coordinating to uh a group funding effort basically you maybe you need to buy let's just say you need to buy something for $500 and you need to get five of us all together to put in a 100 bucks but the thing is we don't trust each other and we can't and and it's important that you can't get griefed basically or locked up right if someone can figure out how to lock your money or steal your money that's really bad so you want to build the the smart contract in a way that everyone stakes in or everyone puts in their money and if you get enough together then it will go into a different state basically like a successful state but if you don't get enough money together by the deadline you need to figure out how to put it into like a withdraw state so then people can withdraw and get their money back and so you have to just like think of all these different possibilities for how this could play out if people uh uh uh don't coordinate but the cool thing is all they have to trust is the code in the smart contract they don't have to trust any other players all the players have to play by the rules of the smart contract and this is kind of like hopefully starting to show the kinds of things that you might build on ethereum the nft is kind of like a simple collectible and honestly like nfts are more like passports right like your passport or your digital credentials I feel like the the digitally scarce art thing uh wasn't as cool as we thought it was when we did it I think nfts were a little overhyped okay uh so what we're going to do or what you would do if you were going through this at home is you would uh build a Staker dos Soul okay so what you're going to do is build this smart con contract that allows everyone to stake and we're going to keep track of everyone's balances and then after some deadline we need to have at least some threshold of eth stored in the contract and if it's uh and then after the threshold passes you call complete and then that checks to see how much is staked and if there's enough staked over the threshold then you put it into like a success State and it what it does is it just calls some external contract and like buys something with the eth but if there's something wrong maybe you didn't get enough money together uh then you want all the your users to be able to call withdraw and get their money back right okay and it will have a nice little front end for you and yeah let's uh let's let's go for it let's uh let's clone it so um there's there's kind of this interesting thing that you learn when you're going through this and it's that contracts aren't automatic you always have to like make a transaction to make something happen so when we're thinking of the state machine as we're in the staking phase and then we're either in the success phase or the failure phase uh you to move from one of those phases to the other you someone's got to click the button someone's got to pay to make the transaction work right and this kind of brings up the idea of a web 3 Kon job uh in in the web 2 world when you want to run a Cron job oh man what's this thing called here we go in the web 2 world you might want to run a Cron job to say roll your logs or something like that like every night we want to you know roll a log or uh I I don't know in in the web three world we might want to do something like compound in interest every night right so you you're not going to you're not going to just run um a service that checks in to compound your interest or something like that because because if that machine Falls over then the whole system doesn't work you have to you're you're only as as strong as your weakest link sort of and so if you have uh if you have a really hard and strong blockchain and then you have this like service that's calling it and that falls over and everything breaks then it's it's no good right so what you need to do is you need to create a a system where you write the rules correctly you say anyone 's allowed to check in at once once every 24 hours anyone can check in once and you write the rules so that happens and then you the the key here is that you incentivize someone to hit the button and that's that's a good like aha moment when you're building these smart contracts basically you write the rules to say that someone can only check in once and then you make sure they get paid for checking in and that's the key that that causes this syst system where then you can share this code and anyone can run it and at least one person is going to run it because they're financially uh incentivized to do so and so if you want an automatic task to run on ethereum you don't just run a computer that does it you have to write the rules correctly and build incentives around those rules to get folks to behave the way you want them to okay let's see let's see what we got here yarn install yarn oh I think I need to check out o yep and then I did that uh let's see let's just remove this then try it again yes then yarn install oh man oh man I can't type here we go here we go okay now we're installing all right so challenge one is about building this staking app and it's gonna operate like a state machine as I've explained we let people stake money and then at some deadline we'll check and see if we've reached the threshold or not okay and and let's go ahead and deploy our contract and we'll run a yarn start right here I don't know I think maybe the chain is not running oh wow okay we've got a couple chains running here this is uh this is kind of a mess let me clean this up a little bit okay there we go so then we'll do a yarn chain to bring up our chain and a yarn start to bring up our front end and let's go look at it okay and this is the old one I'm going to close that out okay so here is the front end for the Staker app there's some staking UI that lets people stake 05 ether and then either withdraw or execute and then we see all the events here and just like scaffold eth you have the this nice debug contracts page let's go ahead and deploy our contract let me just follow the instructions here is that what's next yep that's what's next there we go okay yarn deploy here it goes there we go so now our contract is here uh let's see what we have but there's no code written yet I think we need to write some code to get this uh to work whoa okay so let's see let's edit the Staker dos Soul yep okay yes okay so this is where it's like you're going to need to know at at by this time you're going to need to know some solidity syntax you're going to need to be able to write your own solidity it's it's not going to let you just uh copy paste the values in you actually have to uh like learn like you have to know what you're doing you have to like think for yourself and actually build the thing so let's see what we need to do here uh it's telling us we need to edit the Staker doou and that's the old one let's bring up all let's use cursor this time okay and then let's go look at our smart contract here it is okay so this external contract is just an example contract and it's to know that you've completed this it just like sets this Bool to true so don't worry about that contract we'll we'll call it from the Staker contract okay and then all right so it looks like there's some scaffolding here there's some comments about what you're supposed to do but basically the code is not WR yet it does instantiate uh that smart contract and one of the things you're learning here there's like a handful of different kind of Mo learning moments here but contract to contract interaction is kind of a key thing here and that's what's going on we'll we'll have this Staker contract instantiate this contract and then it actually calls it right here so right here it's actually calling that function nope right here it's creating the contract or it's creating the instantiation of it and then later on we'll call we'll call some function on it okay so what do we need to do it says you'll need to track individual balances I guess we can copy paste this right so we we want to keep track of balances and what else and we have some constant threshold okay so we're keeping track of of all the money that anybody puts in and then we have this threshold where we need at least one ether in the contract to be successful okay all right now it's time to write our stake function and we're going to test it with the debug contracts tab so what do we need to do here let's see does it give you any other hints not really we've got the threshold okay so what should the stake function do right we should let's just look at this first goal here we should see the balance of the Staker go up right so let's do that let's let's create a function called stake and it's payable oh we've already got look at that just going to fill it in I don't even know if that's right let's see no event H does it want me to oh yeah here are the events here yep oh huh oh here it is yeah okay there's this event right here oh it already did it okay so I just need to create the event here event stake there we go so we Define the event here and then we emit the event here so someone calls the stake function with some amount of of money it's a payable function so people can send eth in and we increment their balance based on however much money they send in and we emit an event let's go test this let's go deploy just this contract and let's go uh try to stake some money in and see if uh our balances show up okay so I'm just going to use a debug contracts tab for now ooh where is our staking CR function okay something's not right did I not save this hit save here try deploying uh it's just reusing it uh is this yeah that's the first oh here we go okay I'm looking at the example contract I need to click here to look at the Staker contract okay now I can read the balance for this guy and it should be zero right and then I can stake so let's put in 0.1 e okay and hit send oh I don't have any money I need money first we'll go to the faucet and get some money now we're ready to stake okay so now what we're testing here is does our balance go up we're supposed to have this balance that's incremented by the value let's go look and see if our balance went up by hitting read here there we go it did okay so we're correctly tracking the balance let's hit it again and see if it adds up like it should yes it does now it's 0.02 I don't know if that's too small it's pretty big you can see it so so far we're allowing people to stake money into the contract we see that we've collected $67 in this contract already and uh we keep track of their balances so oh here we go Let's do let's do an incognito and let's go to the staking app and let's grab some money from the faucet and then let's try staking as this dude too so let's go ahead and stake another 01 what I want to see here is that the money in the contract goes up but we're tracking individual balances and that's the key oh need some money from the faucet and then there we we go transaction successful okay so now there's even more money in the contract right now it's uh at2 wait oh I need to hit the thing yeah I need to hit this dude right here right there we go there we go now now we have 0.
12 there we go so now we have $400 in the contract and what's key here is that it's track in the balances of the different addresses separately so let's see what this guy's balance is yep so his balance is 01 and uh this other dude's balance should be that 0.02 right just making sure that that's tracking and and keeping track of everything right okay that looks good all right what's next in the challenge it seems like our stake function is at least tracking uh balances right and is that and do you see the events oh there's events let's go stake events oh yeah there we go we can see the two events right let's let's let's use the a let's let's let's use this let's see stake point5 what happens if I hit this button so I've staked oh yeah it's keeping track of my individual stake and there's that event okay so it's it's working so far we're we're able to uh stake and see the events okay now here's where it starts talking about this smart contract being a state machine and how the timing works right now what it wants us to do is set a deadline of so the block. timestamp would be the time at which the block was mined or validated so you can get like kind of like the current time of of the chain so we're going to say current time plus 30 seconds and let's see here let's just copy paste this okay so we're going to have a deadline of 30 seconds and what are we going to do we're probably going to need a require statement oh yeah here's where it talks about the smart contract doesn't do anything automatic someone's got to poke it okay okay so what do we need to do here we need to have an execute function that checks if the deadline has expired let's just do that first let's just just just that simple function right there so we need uh a function called execute okay and it will be public and what do we want to do we want to oh it's trying to do something let's just let the AI figure it out let's see here if the block dot okay I don't want to do that what I do want to do I want to write a require statement and I want to require that the block like the current time we want to know that the current time is after the deadline and let's just save that just straight up that's all I I'm not going to do anything else I just want to test this little piece of code and this is nice with scaffold e because you've got it all locally you're on your own block explor you're on your own blockchain you can dink around all you want so even though I I know I need to write some more code here I know there's more to go here I just want to test this one thing does this require statement only let me execute after the deadline has passed that's what I want to test okay so if I go to debug contracts and I hit execute uh time should have passed oh there's one other thing you have to do here it's kind of tricky when you're looking at block. timestamp there's no blocks so when you're deploying to like a live Network like ethereum there's blocks every 13 seconds or whatever so this is constantly going but on your local chain there's no blocks happening so we can't get the time so just a little trick that I do is just hit this uh faucet button and that basically forces a block to get mined and then gets your time stamp updated so now if we go here here and hit execute it should just work yep okay now let's redeploy it let's try this again and I'm going to do a D- reset so I I'm on a fresh contract and let's see that so so there is the contract there let's do it again let's do it again watch for this to change there we go Okay so we've got a fresh contract now it should fail to execute because it's not within the 30 seconds even even if I increment this and hit this it it shouldn't yeah deadline not mat okay cool that was what I wanted to test I basically wanted to test like does this thing keep track of time correctly and does it only run the function once the time has passed and it does so we have that working okay now okay yep we're going to flip a a bit in that okay so if the address this okay so address this is going to be the address of the contract do balance so this tells you the balance of the smart contract and what we want to know is is it over the threshold by the deadline okay so we know uh and and if it is then we're going to call this code right here and I'm just going to copy paste that okay so we know we need to do some stuff in the middle of this but there is our contract call and this is really cool it's going out to this other contract and it's calling the complete function on the contract and it's sending all of its money okay so we have the Staker contract and then we have the example external contract and the Staker contract will call a function on the exter or the example contract and send all the money to it but we need to do some stuff in the middle here we need to do this whole uh this thing here is the contract over the threshold by the deadline so we need to check the address. this.
balance okay let's do that so we want to say um so we'll do if I think address balance is greater than or equal to the threshold this would be like the positive State like they oops oh yeah actually oh I do want that line there there we go so if the balance is greater than the threshold and you can't get past this require statement if the deadline hasn't passed right so we know the deadline has passed and we know that the balance is greater than the threshold then we're going to call this example contract complete and if not right so if we're not able to get the threshold worth of eth we need to put it in a different mode thinking of our state machine it's not a success it's going to be kind of a open for with draw mode okay so let's go ahead and bless you let's go ahead and set this so else right if if we didn't get the threshold we're going to need to set open for withdraw to True which means we probably need a Bool up here called open for withdrawal yep and it'll start out as false okay uh so let's see what happens here we call execute it makes sure that the block Tim stamp is after the deadline and it checks to see if we have collected enough eth in the smart contract and if we have we send it to our external contract and Trigger the complete and if not we open uh for withdraws and we let users withdraw their money back okay and we want to you let users withdraw okay so now we need to withdraw function probably okay yeah and whoa and we know open for withdraw needs to be true and what is it going to do it's going to send the balance to the user and then it's going to zero out the balance uh now this is uh this should give you a little bit of Goosebumps in terms of re-entrancy there's this thing that you can problem you can run into where you have re-entrancy where the trick what you want to do is create uh a temporary variable here called a map and then you want to zero out the amount and then transfer the money like that and what that does is just make sure that the balance is zero by the time you call transfer because people could it's called re-entrancy it's kind of like a rabbit hole to go down but basically you could set up an attacker contract that when it receives the eth it actually goes back in and calls again and what you could do is withdraw multiple times end up draining the whole contract's let's say there's five eth in the contract and your balance is only a half an eth you can use that half an eth and you can withdraw multiple times re-entering so kind of a weird little attack there but that that will fix it so they that doesn't happen all right let's see let's see if this works so we need to let's see time left create a time left function you want to Reser zero okay let's let's yeah let's do a time left too that that looks like a nice function to have it's really nice that the AI just reads the comments and fills it in maybe we shouldn't have those comments thin there so inline it's pretty easy to just kind of let them let it do its thing huh so what's happening here is is if the time stamp is greater than the deadline we return a zero if not we return deadline minus Tim stamp and that should give us uh a report on how much time is left in the round and so now we should be able to go here and we see time left right and this won't change unless we do that thing where we cause a block to get mined and then time left goes down see that let's do it again okay so it's getting there once once that gets to zero and by the way I can't call execute yet right it's going to say something like deadline not met yet because we're waiting for this to happen Okay and by now I bet we're set let's see time left now goes to zero Okay cool so that is doing what it needs to do it's correctly reading how much time is left uh let's let's have a failure case and then let's withdraw let's do that let's test out if we're not able to coordinate and we put some money in there and the time expires can we get our money out that's what we want to test right now okay so let's just go ahead and deploy a fresh contract all right and then let's go ahead and stake 0 one or something and send and then we're just watching for this time left to be ready again if I hit execute it's going to say it's not not enough time we're waiting for this gota wait 13 seconds three seconds okay here we go it's got to be ready now all right so we've staked money in we can see that there is $300 sitting in this contract and uh when I call execute it should work and it should set open for withdraw to True right we weren't able to get the threshold of eth so it needs to put it into withdraw mode and so open for withdraw gets set to true and then uh when we call withdraw let's try it hopefully we get our money back so let's keep an eye on this and this right oh that's hard to see what is it 8.3 it should go to 8.4 yeah money's gone there money's back here okay so we've kind of tested the the sad case we staked our money and we weren't able to get enough money together from all the players and so then we put it into that withdraw mode and we test it out and made sure that uh they can withdraw their money and it's not going to get stuck but let's talk about the happy path what we want is for a bunch of people to uh uh stake by the time the deadline happens and then we'll hit execute and hopefully it will uh it will work let's let's try a fresh contract okay let's get a couple let's get another player in the game here in an little incognito window we'll go Local Host 3000 grab some money from the faucet and go to the Staker UI and we're going to go ahead and stake 0.5 ether and I'm going to do the same thing over here stake point5 ether now there should be you've staked 05 and you've staked 0.5 so we should have our total staked eth so now when we hit this execute it should not put it into withdraw mode withdraw should stay false basically it should send this money on to this other contract let's see what happens uh oh deadline not met I need to do that thing there we go it's kind of kind of annoying oh hey there we go look at that you staked and let's go look at Contract balances so the Staker contract is empty now and the external uh example contract has the one eth and the completed is true okay so it was able we were able to get the threshold together and then by the deadline we hit execute and it sent the money onto this contract and called this complete function so it seems to be working pretty well let's see what it wants us to do now it seems like we've tested both the Happy State and the and the sad State and it seems like I don't I don't think anybody can grief us it seems like it's pretty solid uh yeah can you see time left yes if enough eth is staked does it work yes and if the threshold isn't met are you able to withdraw yes we've we've checked all of those boxes okay so to improve the user experience set the contract up so it accepts eth o this is cool okay so we're g to have it it's called The receive function it's kind of like the fallback function where if you just send money to the contract so what we're doing is we're calling normally we're calling this function here we're calling stake and we're sending in money but what they're saying is we could set it up so you just send money directly to this uh address and it will still keep track of it for you and the way to do that is to I'm just going to let the AI do it I don't even have to type it yep I do yeah I'm GNA call stake so if someone sends money into the contract we're going to trigger this uh staking here and it's a payable function okay let's see if this works so let's go ahead and deploy again and what we want to do is just like YOLO some money to the contract and see what happens so here is the contract right there and I'm just going to go to the faucet down here and I'm just going to send in like 0.
5 eth and hit send so I'm not calling the function I'm just straight up yoloing eth to the address and it was successful the money is in there but what's interesting is it's keeping track of the balance for this user if we go look at this user which is the zero user on the chain and we check its balance it's 0.5 so nice little piece of ux there instead of having to call that uh function you can just give people like an ens name right it could be stake. build.com and anyone can just YOLO eth to stake. build.
com and then someone still has to hit the execute button but like I said earlier if you figure out a way to incentivize it you can make that work uh in a decentralized way all right use the receive function to catch that's working okay if you send eth directly to the contract does it update your balance it does can execute get called more than once this is an interesting one so what if and you really have to think about all the different edge cases but if someone calls execute ooh okay this could be really tricky let's say the deadline has passed but no one has called execute yet and there's not enough money in the contract if someone calls execute it would open the withdrawals uh but what if someone called execute again after the balance uh was over the threshold you could end up getting in a weird state where both of these things become true so maybe we could make a variable called like has executed or something like that and then only let them execute once yeah complete I like that and then we'll say completed is true here and then we'll also require not completed right so we require that it's not completed and then we set completed to true so that means that we only ever going to go into this function once basically and it can't get called multiple times there's probably like a more elegant way to do that but it's straightforward simple let's just do it that way all right all right it's a trap make sure your funds can't get trapped in the contract yeah o here's one try sending after you've executed o that's tricky okay let's let's run let's run the whole thing and go down the happy pth path let's redeploy Okay and then we will just use the Staker UI and I'm just going to stake twice and that will get us to the Limit there we've got our one eth and now we're just waiting for this time to run down while we're doing that let's look and see what else we need to do okay yeah it looks like we're moving on to deploy the contract so if if this works I think we're happy 3 seconds left two one zero okay now what what was it saying it was saying if we send some to it yeah yeah yeah yeah okay so what happens if we execute and then we send more money into the contract so basically the the staking is done we've moved into a complete state but that still doesn't mean that someone can't come along and send money to this contract we basically don't want that to happen right we don't want money to get locked up in here goodness what's happening over there uh so what we want to do is probably have some other variable here let's see what do we want to do o completed we could use completed right we can uh in the staking function we can require not completed there we go and that fixes that problem so now once the game is over it make sure no one's allowed to put any more money in and let's let's go triple check this let's have the whole thing work and then let's try to send some money to it and we should get a good failure so let's see grab some money from the faucet withdraw that's not going to work stake two times okay okayy here we go so now we've got our eth and we're just waiting for the time to tick down yeah good time to retweet dmu's tweet good tweet Damu retweet okay let's see are we out zero okay time left so now we execute okay and it puts it puts the money into the other contract everything is good now what we want to do is make sure we can't send money to this address now and I'll do that same thing with the faucet I'll put in the destination 0.1 now this should fail this should realize that we're completed and we don't want people to stake any money or get any money locked yes already completed Okay cool so I think our contract is pretty solid we've kind of like worked through the edge cases and protected ourselves from from uh those things o create a modifier okay hold on let's go create a modifier called not completed and it will check that the example contract is not complete oh in the execute and withdraw okay so we actually did that a little different if you go through this at home uh maybe you'll do it a little differently but we kind of just wrote our own thing so it doesn't do that it doesn't check the external contract completed it just keeps a local state okay let's deploy this thing huh let's go uh let's see so uh the first thing we need to do is uh yeah not going to edit the default Network I like doing just dash dash Network okay yarn generate should give us an A deployer account okay and then yarn account should tell us about our account and I need to send in some sapoia so I'll use a burner wallet and I'll put it on sepolia nope it's loading [Music] internet all right sorry here we go sapoia and we're gonna send um uh yeah I don't know how much do I want to send like a 100 bucks or something it's aoia it doesn't matter okay let me scan this dude's address all right okay so we sent $100 worth of zolia to our deployer account and now we can do yarn deploy D- Network sepolia good old test network but uh yeah this won't be as fast as like an L2 we're going to have to wait for the block to get mined so this will be pretty slow and I think Sao is pretty expensive too isn't it oh no what did I do not enough not enough funds okay $100 was not enough let's send some more sapoia gas is pretty crazy let's let's send $1,000 let's send $10,000 okay that's definitely going to be enough and then let's trigger the deploy again and see what happens so we're waiting for a block to get mined on sapoia oh no no way I mean how how much that can't be right how much let's check our account yarn account how much money do we have it seems like like it shouldn't cause that oh no it's zero okay what's going on here let me scan this dude's address again maybe I have this wrong send in a thousand again 7 e okay let's try that again hopefully we have a balance on spolia nope uh maybe the RPC is messed up let's uh let's do a different network okay quick quick fix Quick Fix I'm going to put this out on a live Network I'm going to pay pay real money uh so what I want to do is adjust the threshold to point 0000001 something like that I I only want to spend like three cents here right because I'm this money is going to be gone forever so I don't want to spend too much money uh yeah this looks good okay uh let's try deploying this to uh base or some maybe optimism let's see so we'll do yarn account again and get that account let's go with optimism I did Bas earlier okay so yeah sending real money here this is uh not not the best I'm going to send $1 that should be plenty because that money is gone for well this money won't be gone forever but once we lock it up in the contract it will be gone forever maybe I should just make a withdraw in here right let's just make one real quick function I'm just going to set it up so anybody can call it someone's gonna steal my money that's cool let's do it all right yarn deploy D- Network optimism all right we're going to use the optimism L2 we're going to pay a couple cents we're going to deploy contract there instead of using a test Network because that was not working we're we're g to straight up pay for it and by the way if you're doing this at home uh go use optimism sapoia I think that's what we recommend folks use it's a it's a test Network so you're not burning funds like I'm doing right now okay we deployed our Staker all right this thing is live now I want to edit that uh config file right the uh scaffold config where we set what network we're on right now we're on hard hat if we change that over to optimism and hit save the whole app should now move over to optimism all right here we go yes bless you and it's going to have a switch to optimism and let's go ahead and stake I don't want to stake .5 I got to be careful here because I could spend some real money and I don't want to do that uh let's go to the stake function and let's do 0.001 one right I think that was the threshold and let's send it in what's it going to cost us 34 cents not bad Okay so there goes the money it's now locked in there right if we hit reload it should be sitting right there right there's the 34 cents okay and then we're waiting for that time period to happen right time left is zero uh now there should be the execute function let's see what happens all right all right the 34 cents should disappear here from here completed is true uhit reload here this should be empty yep and this dude should have the 0.01 right there and anyone in the world can call this button right now and make 34 cents uh I'm gonna go ahead and do it though before anybody else gets to it I could even get no I can't get front run because it's a sequencer centralized sequencer if it goes to the MIM poool and someone's watching the MIM poool and they see me put a transaction in and they can just copy my transaction and turn the gas up a little bit and front run me and steal the money okay it it worked basically uh we were able to I bet I can't turn this in on optimism though can I let's see Can I submit the challenge nah so so what you will do is you'll you'll deploy your app whoops I kind of want that back you'll deploy your app uh and then you'll turn it into oh yeah it looks like yeah you want to do this longer yep and then we'll deploy yep and then it has you ship the front end so you'll do a yarn verell and you you'll upload the app so once your contract is up you need to upload your app then you submit that here and that is the staking challenge kind of a a a neat little simple but powerful uh uh tool or concept powerful coordination mechanism okay let's see here now let's let's let's go through the rest of the challenges a little bit faster I think writing that one was nice it was good to get in and like write some code but let's just kind of like speedrun the speedrun for for the rest of the time so let's go look at these challenges let's go I'm just going to go to the GitHub okay oh scaffold eth challenges is it that there we go okay so uh let's look at challenge two so we've already done decentralized Staker we're going to do challenge two now and this is a token vendor so this is really cool you're going to have um one smart contract that acts as your token and then another smart contract that you'll send the token into and it will sell the token a little token vendor right yes so smart contracts are kind of like always on vending machines that anyone can access let's make a decentralized digital currency then let's build an Unstoppable vending machine that will buy and sell the currency we'll learn about the approved pattern in ERC 20s and how contract to contract interactions work okay so we need we would basically create a token uh let's see is that here yet oh no no no no we're we're just going through it let's let's let's not write any more code let's just go through it then you would edit the front end to display it and verify it okay cool so uh yeah same thing right you would clone it down you check it out you install it you run yarn chain you run yarn deploy you run yarn start and then you have a front end that comes up and uh you'll work through you know can you check the balance of can you do a transfer just making sure like balance and transfer works in the token you can send the token around now it's time to build the vend right this will be the second contract you're going to build a vendor doou so a second contract and you'll have some exchange rate so this is tokens per eth right if you put in one eth you should get a 100 tokens back and looks like you'll have them you'll write a buy tokens function that will look at the message.
value so you'll call buy tokens and you'll send in some eth and it will look at the message. value and then do the calculations of tokens per eth and then figure out how much of the token to transfer to you so you'll send eth in and you'll get tokens back looks like there's even an event that's admitted yep lots of good stuff here um pretty pretty simple and straightforward you're basically building a token and then selling it out of another contract let's see vendor buyback okay the hardest part of this challenge is to build your vendor to buy the tokens back the reason why this is hard is because of the approved pattern so the way erc20 is work is if this contract needs to accept the token you don't just send the token to it that that would make a lot more sense but that's not how it works you basically approve this contract to take your tokens and then you call a function on the contract and it goes and gets them really weird pattern you just get used to it after a little bit but this this is going to help you kind of get over that first bump or hump so yeah you you would have to do two transactions right so buying tokens is easy you just YOLO some eth in and you get some tokens back but selling the tokens you have to call approve on the token in one transaction and then you have to call a second trans action that calls the vendor and tells the vendor hey I've approved this token you can take it and do some stuff and it it will there we go so if you ever want to deploy a token and sell it for eth this is a a way to do that but uh only on test networks don't don't be don't be deploying to tokens on live networks unless unless you really want to okay so that is challenge one that is the or that's challenge two that's the token vendor we're learning about ERC 20s we're learning about contract to contract we're learning about that stinking approved pattern all right Challenge three uh is a dice game so Randomness is particularly tricky on a public deterministic blockchain basically the chain shows everything so if you wanted a random number it's hard to do in a deterministic blockchain you can't like Randomness is very hard so a weak form of Randomness is to use the previous block hash and the problem with doing that is you can set up an attack our contract and that's what you'll do here so basically there's this dice game you pay some money and you roll if you win you win some money if you lose the money stays locked up and so how you attack this is you build a second contract that looks at the same thing that this contract is looking at in terms of Randomness to figure out will I win or not and basically you set it up so your dice contract your attacker contract only pays to roll on winning uh numbers basically so you you just sit there and you uh call roll a bunch of times on the attacker contract and it waits until the block hash is just right and then it calls it and you win so you basically only roll on winning roles and so that's not good right if you wanted real Randomness this is kind of falling apart and you can attack it but this kind of teaches you how that works you're going to make a rigged contract and you'll call this rigged roll function and yeah it's a really fun really fun little challenge I think Mr D did the dice pretty cool dice like a 16-sided dice die but yeah that's the dice Challenge and that teaches you about Randomness and about how to make an attacker contract uh that can predict the randomness basically or only pay if it's going to win okay we're getting there so now is the decks the decks is probably one of the most important builds you will make uh through speedrun ethereum um thinking of our token and our token vendor we were able to Mint the token and put it into the contract and let people buy it but uh what if you wanted people to be able to swap put in some tokens get back some eth and you wanted the price to be variable well a a DEX is a really really cool smart contract where it um keeps reserves of both tokens so it'll hold a whole bunch of of your token and a whole bunch of eth and it we'll hold them at a ratio that tells you what the price is right so if this token was exactly one for one eth you would have 50% of each of the tokens in right but maybe the token is worth 10x the eth then you'd have 10 eth and one token in basically but you have these reserves and these reserves allow you to do these swaps and for the first time ever you can do that in a decentralized way you used to either have like an order book system or some kind of like centralized choke point that could fall over but in this case it's fully decentralized and it's all on chain the there's some bad things like impermanent loss but that takes uh you'll have to really dig in and kind of like learn all of that stuff um maybe a good too long didn't read is that those reserves are important for making the swap work and the more Reserves you have the the uh cheaper the swap is or the less slippage there is basically so you want to incentivize folks to be liquidity providers so the way it works is someone puts in some uh eth and some tokens and every time there's a swap a tiny little bit of that is left behind and so slowly the contract actually like gains value as people are swapping back and forth because they're leaving a little bit behind and that is to incentivize the LPS the liquidity providers to provide that liquidity and this is uh this is expansive by the way so it a really really cool uh concept is the idea of a hyper structure boy I didn't get it structure uh from Jacob from Zora but he talks about how hyper structures work and they're Unstoppable they're free they're valuable they're expansive this is this is what I was talking about expansive basically the protocol itself incentivizes people to LP so the more money you put in the more money you make and that's how it's supposed to work and therefore if you build it correctly and you put it out there lots of people will provide liquidity because they're financially incentivized to do so it's permissionless it's positive sum it's credibly neutral check out hyper structures it's a it's a really cool concept okay so uh in this one in this Dex we'll put in some liquidity I think you end up let's see whoa what do we do so the structure there's going to be like a swap function yeah so you're going to be able to do eth to token or token to eth and balloons are are token yeah and here are the reserves right you have to uh so there's a function to swap but there's also a function to put money in or a function to pull money out in terms of liquidity yeah and you also need to initialize it with some initial liquidity and that kind of sets the starting price and yeah here's this this this is a the very popular uh what happens here is if so this is the old position and this is the new position you put in token a and you get out token B and you can see by this curve the farther you go this way the more slippage there is so the more reserves you have the smaller that little chunk is uh but yeah go go take on the Dex challenge there's a lot of intricacies here that I'm not really getting into this like constant product thing there's a lot of great stuff to learn here go go do this on your own sometime go through the decks and uh you'll you'll learn a lot and it's really like one of the neatest contracts let's see liquidity we already kind of know about let's see if there's anything else here before Oh here does this show the swap yeah so it's going to kind of give you a little drawing for the when tokens go in and what comes out yep and then you deploy it live and you verify it and you turn it in and uh our autog grader will go swap some tokens on your decks and make sure everything works right looks like there's even like a YouTube video here I wonder what that one is okay so those are the most important challenges everything else from here is like uh like dessert basically challenge for taking on the decks is like the challenge you you you if you can build a DEX you can build a lot of different things like this is a good like am I ready yet kind of test like can you sit down and build a deck okay uh there's three more challenges here um there's a state channels application this is really cool because it uses signatures you don't always have to put everything on chain sometimes you can do things between parties with just signatures and and sometimes you can even have like a smart contract that those signatures settle to and uh in this one you kind of uh learn learn about State channels and about kind of like how scaling could work or uh does work and then I think is multisig next let's see what's next yep multisig so multisig is a really cool let's go look at this uh let's go look at this code so a multisig is a smart contract and you can send money into the smart contract and multiple people need to sign to make make that money send out basically right you have to get like three out of five signatures let's go see what the code looks like yeah there we go and then if we look at some function here yeah so you're going to keep track of signers you can add and remove signers there execute transaction this is really interesting let's look at this function here so you pass in some two address and some value and some data and the signatures and then it actually goes through and validates the signatures and then if everything is valid and you have enough valid signatures right you'll need to have uh valid signatures needs to be greater than or equal to signatures required and if so you can call the function it actually executes whatever you want it to just some arbitrary call data gets executed there and that's a multisig really really cool uh little multisig really handy uh especially uh for storing large amounts of money like a dow has a treasury so uh like a multisig is like a nosis safe if if you don't have a nosis safe yet you should go get one uh nosis safe it's it's a great way to uh hold your money in an account where it takes multiple signers basically Bally to move that money around so it's just a lot safer let's say you have three accounts and one of them leaks you can just remove that leaked account and then put a new account in whereas if that leaked account had money on it the money's gone forever right so the multisig is a a nice way to kind of safely hold your funds uh here yeah it's an ecdsa uh let me find it there there's a function called recover right here so what this function does do you see that is that big enough so it's um so you can sign any arbitrary message so uh Austin likes beer I sign that message and then I send it in here and I take uh the thing I signed which would be in this case is just a hash but it could be like a string I I think this is a hash of a string and then the signatures so with the message that they signed and their signature you can do a recover and it will give you back the person who signed it and this is like really powerful uh tool for a lot of things but doing ecdsa recovery in solidity is really nice like it leads to things like meta transactions and all sorts of other cool things you can do does that make sense did that answer it cool okay all the way to the bottom SVG nft this is kind of like the the ending challenge uh oh what did I do here this is kind of the last challenge uh you're supposed to make an nft just like those nfts that we did at the beginning where we were minting the little Buffalo and the zebra those were going to ipfs though when you minted those the image is actually stored on ipf s and it's like the hash of the image is stored in the smart contract so it's kind of like not as cool with in SVG nft you actually put the contents like how to draw it like if you go look at an SVG it just looks like some code but you put all of that code right into the contract and then the contract itself can render the SVG pretty cool little challenge yeah you make some lugies I think optimistic lugies is that what they are classic but that is the last Challenge and uh I would recommend y'all going through this on your own time at home you can go to the scaffold eth repo and find scaffold eth 2 challenges or just go to speedrun aum.com uh and I think that's that's mostly what I have to present but uh maybe open it up for questions if anybody has questions about anything or concerns or anything um on all ears yeah uh what about uh can I do some like PR to add some more challenges because for example I work with snarks a snark compiler so maybe an example for verifying snark or like extending the something is so you're saying could you PR into scaffold eth some new challenges uh possibly we I mean that state channels was actually made by someone else and they PR it in so it's Poss possible but it's more likely that you just like fork speedrun ethereum and make speedrun starware or something I think actually someone did that exact thing let me see did you say starkware it's not oh oh snarks I see yeah yeah there there is scaffold yeah so maybe you want to do some ZK stuff or something like that yep uh speaking of that let's go to um if you go to build guild.com bid GID and you go down to the bottom there's this mirror board there's this Tech Tree link right here it's kind of buried but uh it has all sorts of other challenges Beyond just the the speedrun challenges all sorts of things that you can build uh on chain and yeah there's like a whole section here on zero knowledge oh man how do I move no no no no dang it oh there we go that'll work okay so yeah you can do like this this just like covers like all these different concepts within the space and how to just like test your knowledge and build things there's like a little circon starter kit and um the the guys who made Dark Forest are actually here they're the Frog guys the guys with the Frog hats actually made this game Dark Forest it's like one of the coolest games ever made on chain uh using ZK snarks and or DK Tech in some way okay uh I think I'm about done but definitely open for more questions if anybody has any questions go speedrun ethereum that's the important thing yes yes uh this is a beginner session I think I'm going to ask very very dumb question if you don't mind I'm very beginner um I was trying to understand more on the storing chain and how to use that instead of utilizing any databases using uh chain as a database like how does it work and which parts actually is advised to store and chain which parts not or how that that's this this is this is a kind of a moving Target because you know a few years ago I would say you're making a mistake if you're storing lots of stuff if you're using it like a database you're making a mistake it's not meant to be a database it's a very expensive slow asynchronous database right um but the the needle has moved and l2s now exist and l2s are super cheap maybe it starts to make sense to actually start using them like a database again I think you have to be careful because this is all public right like everything that goes in there is going to be visible to everyone so if it's like medical records or something like that it's all like no way can you do that right or like anything that could dox someone like connecting an account to an address and someone shows up at your house with a wrench like there's a lot of things that you don't want to put on chain just for like privacy concerns but you can store strings you can store numbers it works kind of like a database and on an L2 it's a lot cheaper with blobs blobs are going to get a little bit more expensive so it will get a little more expensive I think but I think they're trying to push it cheaper and cheaper too but does that sort of make sense it does make sense but again like so I should not really treat blockchain as a database or can I I think you can yes like if if you wanted to make Uber on chain you would have a very hard time right that's like a con a constant thing we see at hackathons it's just not very practical oh no what did I do uh but maybe there is other places where you could use it like a database and it makes sense I think it comes down to the application and how sensitive the data is and how much you're willing to store like pay to store it but thanks to l2s I think yes you can use it like a database again thanks more questions yes okay thank you uh on challenge zero you said that the image Z image uh was still on ipfs it was on ipfs uh here let me let's see is it still up the the image okay so what happens is you have a manifest which is like your name and your image link and it's like a Json object and then inside of that was an image link and that's what we're using to render that goes into uh ipfs and you get a hashack and so it's not stored on chain like the image itself is not stored on chain it's the hash of the image that's stored on chain so you go to the blockchain and you get the hash and then you take that hashed ipfs and get the information back but it's not stored on chain it's stored in ipfs does that make sense it's just like the hash that goes on chain yeah okay yes I would like to know uh to understand the interaction because when you hit on the the mint button yes it means and nft yeah now I would like to know uh where does the interaction between your the contract and the and uh ipfs is located so at which level is this interaction so do I need if I want to implement it in in my code do I need to to get a such um an API key to drop my image on the ipfs no okay so ipfs is like a distributed storage system and what happens is you're you're you go look up content it's content addressable so like an image goes into ipfs it's not like going to the cloud somewhere it's going to some machine somewhere right so you you actually have to run an ipfs node and you have to pin your images on that note to keep them to stay there so if you you can add you can upload things to ipfs but you have no guarantees that that thing will stay in ipfs so you end up having to run your own Pinner usually which is uh just like a an ipfs node that you add files to I I still don't know if I'm fully answering your question like so yeah maybe maybe you could ask yeah how am I answering your question yeah yes yes I think uh you go uh I have another question on the second uh the first the challenge number one yes you implemented uh a protection against a Rey attack yeah yes uh I read somewhere that uh the same function uh is subject to a a limitation a gas limit of 2300 uh I'm sorry I don't understand I didn't understand you something about reentrancy yes when uh this is something I don't know if when you use send to send ITA or to send it to another address yeah yes it is subject to a limitation of 2,300 gas yes yes when you do a DOT send here the best place to look this up is go to solidity by example and there's a really good example here about sending e where is that right here sending ether and this explains it really well uh this 200 30 this 2300 gas you're talking about if you use transfer or you use send it basically locks it at this much gas and so if you want some other execution to happen on the other end of that transfer say you're transferring to a Smart contract and it executes some other stuff you will run out of gas so what you need to do is do a DOT call instead so the way you send eth looks like uh where is the dot call I didn't even see it there oh here it is yeah here it is here it is so you do two address. call and then you send the value in so really weird kind of thing it looks like you're like calling a function on this contract but you're just sending money in uh but that's the way you do it if you want to forward along all your gas like if it needs to do a bunch of execution on when it receives that and uh needs to spend some gas you'll want to use call instead of do sender.
transfer okay okay so at this moment when I use do call I should not Implement Reen protection uh it depends on the the application like you you need the the re-entrancy stuff is kind of different than this stuff this is this is just like how to send stuff you need to implement re iny protection if someone can re-enter your app and uh like attack it like the what we did to mitigate it was create a variable and store the balance into the variable and then zero out the balance and then send the money so by the time the money gets to them their balance is already zero and they can't re-enter so it's not it doesn't have anything to do with how we're calling send or transfer it's everything to do with how the code is structured and if it's structured in a way that is vulnerable to re-entrancy okay thank you yep any last [Music] questions thank you for the build Guild coming out to support me you guys it's probably pretty boring listening to this talk we got a got a four more hours of it tomorrow too all right thank you all thank thanks for having me go speedrun [Applause] ethereum what do you use was very good to find a solution yeah it's C which one CS
Automatic transcript — names and jargon may be misspelled.