Web3 Course Walkthrough on freeCodeCamp.org (Rust, Blockchain Development, and Smart Contracts)
Key Takeaways
The video provides a walkthrough of the new Web3 curriculum on freeCodeCamp.org, covering blockchain development, smart contracts, and Rust programming. The curriculum includes five integrated projects that require practice and preparation to complete.
Full Transcript
most of you are probably aware that on freec camp.org we have a comprehensive and interactive curriculum to help you learn full stack web development well we're constantly adding new certifications and our new web 3 curriculum is ready free to try it's still in development but we now have five integrated projects ready for you to complete in this video you will watch free Camp team members Sean and Tom complete the projects so get ready to learn more about web 3 and see if you can follow along with Sean and Tom as they work through the projects welcome free code camp this is the web 3 curriculum Tom and I are running through the integrated projects that we have ready and in front of us we have the article that shows you how to run the free code Camp uh web 3 curriculum in your local vs code setup it walks you through what projects are available as well as how you can run the course um once more projects are ready you will be able to sign up for updates and just listen to your emails because once we start releasing you'll get updates on those so to get started we can head to our terminal and we just need to git clone the repo which is in GitHub at free code Camp web three curriculum yeah it mentions in the instructions there um kind of specifically what to do I think um so there's a few prerequisites obviously uh vs code and then uh Docker is the main one I guess because this all runs in Docker so um you have to install those two things for sure and then once you get those few prerequisites installed in the article then you can I guess just clone the rapo and run it or something like that we'll share we'll share a link to the instructions um to to get it set up in the description there so and once we make sure that we have Docker running we can inside vs code open up command pallet and say remote containers rebuild and reopen in container now this usually does take a while but um what I like to do is either go make myself something to drink or just watch the terminal as it builds okay is that it ready yeah I think um this is what I typically see when it's ready is that that the last thing installs that last extension there okay awesome so now we can use the free code Camp extension to run the course first we'll prep the course um and you can see what it's doing if you head into the terminal labeled free code cam Run course but you really don't need to worry about what's in there so let us again you are introduced with the landing page which describes the course um there will be a link to frequently asked questions just in case you get stuck or are confused with how to start as you can see there are quite a few projects that we have coming soon here currently the projects that are ready are what we are calling the integrated projects the integrated projects are like certification projects on the free code camar platform in that you don't learn anything through the course you are prepared through practice projects um you get taught the content that you need in order to complete the integrated project so the integrated project just has a bunch of user stories that you expected to complete in order to go through this all right I got this loaded up and what I'm going to try and do is go through this first available project it's called bu build a video game Marketplace blockchain um so you click on it and you come to the instructions here and then it gives you the files there um okay so I guess we're going to create a blockchain for video game Marketplace uh where we can buy and sell items and we're going to work within this folder so I'm going to just go in there to start um okay it says Json files will store information about your blockchain um there are functions in blockchain helpers for reading and writing to them you'll need to look at those to see what arguments they need and what they do they're already included in the files where you need them um the items you can buy or sell are in items. Json so we've got this item that Jon I can buy some stuff there um many of the files are finished for you you only need to add code in this handful of files and run terminal commands and finish all the user stories and pass the tests um okay so your blackchain will be stored in blackchain you can initialize by running node in it blockchain um okay there's there's just a bunch of US stories here that'll explain to you what to do um no generate wallet so we can create some wallets um yeah mining blocks hashes oh jeez there's a lot of stuff here um so these these the blockchain dojason is going to hold our blockchain and then we already looked at items um transactions is going to hold transactions and wallets is going to hold wallets and then there's kind of examples here of what they're going to end up looking like blockchain has some things there and Etc okay um let's just see if we can't pass one of these tests or something oh look at that that looks good um actually whatever I'll just leave it um first one let's see you can initialize running noted NP blockchain should replace everything in blockchain J Json with an array that has one object the Genesis block it should have hash property of zero okay I think this one's not too difficult so we've got two helper functions here right blockchain right transactions um should replace everything blockchain right blockchain genis block equals so obviously the Genesis block is the first block in the blockchain which you often have to hardcode because you'll find it doesn't have a previous hash so you can't really generate a a hash for it yeah so I have a hash of zero and a previous hash of null and then the blockchain we're going to save that but uh blockchain should look like this this and I think running that should do that okay we could run it and see what it looks like let me see what does my blockchain look like node nit blockchain there it is let's see there must be a test that goes along with it um running all right we got the first one to pass should replace everything so same thing replace transactions. Json with an empty array um currently it's empty but uh if I go here write transactions so write transactions just like that yeah these helper functions they just kind of write to the file I guess and get things from the files the Json files if we wanted to see what those helper functions looked like just in case maybe the name doesn't describe them fully where do we see that this is all in this blockchain helpers file um there's a bunch of them get and write blockchain um it's pretty much just well there's quite a few here I guess getting balances and stuff um but yeah you you um should say here do not change code in this F so you don't need to change anything um and it may mention some things about some of them elsewhere maybe in the instructions um okay what do we got now next running no generate wallet with the username should add a user as a key in wallets. Json with a public key and a private Key Properties the value should be a public and private key pair in HEX format uses def so let's see what this one looks like we have no wallets and generate wallet okay so we're going to get a command argument from the command line um new wallet name so public and private I know there's instructions on how to do this um generate a key pair okay so let go con key pair equals ec. gen key pair um EC is already here for us and then get some information from the keys there's a user story on this one you to watch out for those typos e did I have a typo you um should be able to create a wallet well let's see what the examples look like here we go wallet name public private there we go that helps okay so uh public [Music] equals um get hex public Key from Key pair I think that's right on uh private equals A.G private hex and then get wallets so we don't want to completely replace um the wallets we want to add to it so I think con wallets equals get wallets um so I guess we can probably just just skip some validation and do wallets do new wallet name so what validation would you do I would make sure there's not a a name already in the wallet right is the only thing here and typically wallets aren't stored like this this is just for this project um so you can see it and have access to all the public and private Keys um okay so wallets and in a wallet name so we've got um public key and private key public key equals public w. new wallet name. private key private um are those keywords public and private is that why I'm getting underlines private is a reserve word typescript is messing with you okay and then we should just do write wallets and then if I save that open my wallets names node so this is all in the instructions but I have it somewhat memorized um but yeah you can create a wallet with this it says so I'm going to try that generate wallet me there not set I was wondering if you needed to make that um Dynamic yeah okay so do equals what set new W name key I just do this this work key equals Pub I'm not used to this keyboard I think just remember new wallet name is not the name of the key you want oh was that my problem yeah obviously thank you um that should work I think no more errors dat argum must be string or above or now what invalid argument well when you're writing wallets you don't seem to be doing anything with the wallet you just created oh gosh okay wallets equal get wallets wallets new wallets name wallets wallet uh okay wallets thank you you got to look maybe I should have put more information there okay I think it worked it worked ha awesome I think the fun thing about these projects is you get to you know try out what you're making as many times as you want yeah you're you're cutting out a little but yeah I got you okay so we got one more thing done hopefully running the wallets uh creating wallet works and it has key pairs when you generate a wallet it should add a transaction at the end of the transactions array should have a buyer address property of null and um buyer address property of null and seller address that is the public key of the new wallet okay so let's look at this add transaction I assume go back to generate wallet get transactions write transactions okay so we'll just we wrote that con transactions get transactions um and then I guess con new transaction equals something then transactions. push transaction transactions. right transactions right um transactions right transactions and then this transaction it should add a transaction at the end of the transactions dur the transaction buyer address of null okay and seller public key of the new wallet a price of 40 so public key I'll just go like that price 40 I suppose the I don't know um but let's see what happens there okay that didn't work either now now the old one's broken um new transaction equals that transaction you to watch out for what you actually named some of your variables why you just tell me what the answer is you see up the not seller address Pub there is that what you were looking at yeah aha okay so now when I look at my wallets um wallets we got two wallets and transactions got nothing in there so I'm G to just like that one wallets wallets I don't have a trackpad where's my trackpad um wallet okay let's look third wallet test okay we got a test wallet added that and now we have a transaction all right um running node mine Mind Block should add an object to the end of the blockchain dojon array correct hash previous hash Nots and Transaction properties oh boy so this one sounds a little trickier um after you run should be an empty array so I guess we're goingon to need a const new block type thing not hash previous hash transactions May something like that let's see equals so we've got helper functions let's use those yeah block blockchain uh last block blockchain so you want to get the last block so we can get the previous hash the blockchain is going to have this and we're going to want to get um this hash so we can put it on the next block and it'll be the previous hash value of the next block so last block equal blockchain blockchain do length oh one blockchain blockchain link that sounds right um just comment this out let's. log last block let's make sure that's working there it is okay so it's working nice yeah I wonder if you don't need to worry about mutating blockchain you could just pop it off the end I mean in this now you probably don't want to do that right you would need to put it back when you go back to right the blockchain uh yes you can't you can't remove a block okay previous hash equal last block. has so we got one thing down I think um Nots I think we're going to have to look at the rest of the things for that n okay so hash and kns those are going to be tricky transactions let's after you run it should be an empty R okay we can add that one quick const actually we should just be able to go to write transactions like that think so assuming everything gets mined correctly we can make that an empty array um I want to go up to these user Source I think there's some information generate a wallet okay so looks like we kind of got a large portion of the top done um okay it's add the has to be creating using 556 okay concatenating the nons the previous the hash of the previous block okay so yes we need to do some sort of loop here I guess let hash equals this while and then I know there's something in here about it having to start with some zeros there we go the hash and yeah let Nots equals just start with zero so while hash not do starts with 0 um create new hash has equals shot 256 and then I think aut to work with keys sh right there there it is can I copy that there we go okay content to Hash it says up here um the hash okay concatenating the kns kns plus previous block CL block. plus a stringified version of whatever is in transactions. Jon oh jeez look at this they copied I could have just copied this whole thing need to read um transactions there's some dots there I don't have transactions oh I think I do no I don't get transactions okay so and then we want to probably do not Plus+ start okay yeah so it's going to keep going until it starts with two zeros nonel be one two three four five um uh okay should be the hash of the last okay that looks right um yeah do you have everything for your new block now no it's hash transactions is that just adjacent I think so yeah yeah that looks right see if it works so the transactions are supposed to go empty and we're supposed to get a new block I guess node Mine Block um we did not get a new block because I did not write it but I did delete the transactions um new block equals this uh blockchain equal get blockchain blockchain dot push new block and write blockchain blockchain here we go now we don't have any transactions but um you know what I'm just going to generate another wallet quick test two now we have a transaction and yet another wallet okay let's see if that worked no mind block all right no more transactions and we have a block 351 tries um and then I guess I can come run these tests and see what is passing for me yeah uh running note Mind Block hash previous hash Nots did I do something wrong what have we got here previous hash zero that looks correct hash that looks correct Nots looks correct oh boy something is missing hash previous NS transactions I'm wondering now if you go back to your your little algorithm for calculating the hash because I remember coming across this a lot while doing um learning about the cryptography of blockchains looking at nons that you're calculating the hash with and then the final nons that you're ending up with oh jeez let's just we'll just do it [Music] first it's probably what's the what's the right way to do it tell me the right way to do [Music] it okay let's see what happened I'm just going to get my C still then okay um something isn't working well not we know the internet has an obsession with cats so this is Archie did you pause that t no I wonder what the test is doing should add an object well I mean the one thing I can think is you're not if the hash the nons needs to be zero you're never actually testing that what's that say if the nons is ever zero you're never calculating the hash based on that because you're always starting with one kind of a probability thing that that's probably not going to happen but well the nons it'll go it just goes until it finds one if zero yeah but you never checking zero well that's fine because if zero Works it'll just go to one and check one and then it'll go to two or three whatever until it finds one that works and then you can use that one uh I don't know I know what I'm can try though hash wait did it pass running node Mind Block down object and transaction proper transactions transactions do you need to add a transaction in anyway I don't know I feel like that one should have passed well if you go to the console is it saying anything there you go now you're thinking um I don't think we've even seen the console yet um yeah okay running no M Block let's see what it says here the hash of the new block should be able to be recreated with these things expected 06 maybe you're right with the to equal z d so what one so my hash has two zeros I can't get back very easily I need my touch trackpad um so it's expecting only one zero h no it's just saying it's supposed to be able to be recreated so it should have not previous has is nons previous hash last block. has that should have been correct Jason do stringify [Music] transactions I'm going to check where you are doing the two string okay so what's transactions dojon online oh there it is yeah oh stupid transactions not transactions not Jason did it say that and I should have copied and pasted did not say that in the instructions it did say that there's a bug I no well kind of a bug it's a bug uh okay let's try it again let's see if that works console running node Mind Block there it is we got another one thank you for that help um okay so do you mind writing that down you want to take a note of that oh what are you doing yeah will'll take a note of that um okay running node buy item so we need buy and sell items uh know but so we're going to run this command buy item with one of our wallet private keys and the item we want to buy and we need to add a transaction for it with the correct buyer just seller just price and buy signature so this is the test text there must be more information up here so but I know we're going to need con let's just call it new transaction this and we're probably going to need transactions equals get transactions you know it's always satisfying when uh you come across a problem like we just had and then you start to think that maybe you have an issue with your test and then find out that your test is working okay transaction when you buy an item yada yada yada so the buyer address should be the matching public key for the private key entered so it looks like we're going to get a private key and we need to find public key from that um Pub Pub is Hope is a keyword in Russ isn't it yeah it is um so I have some poor variable name choices maybe um so get key pair from private equal key public Cas so we got we should have key from private get key pair from private so that'll get us a key pair so that'll actually be key pair and then we need I think we need to get hex public Key from Key pair that should work right here so C PB I'm gonna I'm gonna make it a little better little better um I'm just gonna console log key that shouldn't do anything save that um so I should be able to run node by item and enter a private key so if I grab this private key and run it oh come on why can't I paste copy paste I should get a log with the public key that is the public key that matches that works okay so we have the public key um okay we need to run that so okay buyer address public key seller address null price should be the purchase price of the item bought item bought equals that so get item price what does that do get it price item items so it looks like it Returns the price I think just do get right here right in the object item price item bot um signature should use the buyer's key pair to sign oh jeez signature equals buyer key pair key pair. sign here we go what kind of content do we need buy concatenation buyer address price and item bot man these helper functions are really just making a lot better aren't they yeah uh yeah I lost it price item bot okay Price Plus item bot okay so we should have a signature and we need to add it probably down here we don't want that why would I do that thank thank God for linting that'd be terrible okay so supposed to add an object to the transactions transactions. push new transaction right transactions transactions save it and we will I'm G to open up this transactions and see if I can do this again node bu item and we'll try an icon but I wanted to see this not by item no um something's out of order buyer address equals public key buyer address um so I should be able to just do public key there think price is not defined get item price um price okay yeah yet item price Item B yeah that wasn't very smart there was it let's try it again yeah I think I spent 10 or 15 minutes yesterday on a bug that was caused by the trailing comma in Json yeah so at least your error messages are telling you you know exact what's wrong mine was telling me unexpected token yeah well didn't it give you like a red line around it it's just really small and you couldn't find it you didn't get a red line around it no I think I was editing in Nano so oh yeah no lenting no anything okay so I think this one should be working we bought an item and it was there so M Block No by item buyer sell signatures well let's see what happened with this transaction buyer seller price signature buyer seller price item we're missing an item I wonder what the console would have told you we check it out here in a second yeah I'm always interested if it's assertions are specific enough seven buying an item H this one might be a little I really need my trackpad for this oh I have to scroll down here I guess it's not bad I just got to scroll down a little further um expected two to equal three that's not all that helpful are youer asserting the length of the object's properties yeah I guess probably huh yeah um and then somewhere in there I suppose I check the rest of it yeah that's not or maybe I check I'm sure checked something anyway um I think it'll work now and since I'm just buy item still failing let me see if I buy an item again now we got item item item bot yeah to read read my own stuff still nothing item bot [Music] signature let's run it one more time address what I notice your transactions aren't um clearing oh you're not running Mind Block that's why yeah seller address I don't see any typos signature H let's see if that console changed because it's adding an item it's going to say the same thing isn't it that's not helpful um buyer address buy item price so the price is correct signature I wonder if that's off public key buyer address that's the same same thing that shouldn't matter signature let's see what that signature is supposed to be you buy an item Signature Sign in catenation of the buyer address price and item bot in that order in HEX format got a keep pair key pair. sign I mean the signature is here so seller address that's supposed to be null right yeah seller address should be no price should be the purchase price 10 I wonder if that's supposed to be a string no let me see this example transactions yeah it all looks [Music] correct transactions we're pushing it get address balance is there a caveat in there that I'm supposed to make sure they have a enough [Music] funds well it sounds like it's saying you're still not pushing the correct number of objects that is what it's saying but you know what I think it might be yeah something to do with the balance the test is checking if it's got enough balance or something so I'm going to go I'm GNA start over I'm goingon to reinitialize my blockchain and because the account I'm using is this one that I create that doesn't have any funds didn't add the funds until those other the the uh it's like a I guess a reward transaction for uh creating a wallet node generate wallet um just put me in there see now I'm going to have transaction with the funds I created those other wallets before those transactions were in there so I don't know why that that why would that have anything to do with it I don't know I'm going run these tests again see if it still came back yeah there it is I'm gonna look at my solution see if there's anything well I can't think of anything transactions price buyer key pair key from private signature it looks the same for the most part very similar copy it over still nothing oh I didn't save the file wonder if I wasn't saving the file I need to turn on autosave there it passed so now we don't even know if or what I'm going to undo this and see it's working undo save and then run it no now it's not passing I wonder what I'm missing on this one buyer address seller address deair all right um we have to do the cell item thing still so we'll give it another try over there I'm just going to use my solution for now because it's passing um I feel like it didn't have anything to do with the balance but maybe I'll dig into the test later and see if I wonder when you sign it the concatenation it matters the order doesn't it mhm did you have the order correct I did I double checked it public key price item bot buyer address public key yeah okay wow do you have to do the check for the the balance in order to pass that one it doesn't say anything about it should not add a transaction if the addresser does not have a maybe it's right there I didn't look at the second one this one run the test okay these both fail yeah maybe I'll just try transaction equal that transaction that so try it once yeah get address balance um cons balance equals get address balance public key if balance greater than or equal to price will add the transa uh push transaction and write the transactions we'll try that once and see May that was it there it is wow you want me to take a note of that um I mean there might be a reason that's happening perhaps yeah sure take a note um yeah I don't like that but maybe I'll put that user story first that's probably what I would do um okay running the cell item so what else have we got we've got a cell item I should have at least three wallets in my wallets that Jason so that's what I going to do here me you I three wallets I should be able to pass that one um three walls okay and then at the end here we got to oh they are valid nice at the end we got to add a bunch of blocks and transactions okay cell item let's try the cell item one let's keep keep moving keep me on keep me on task Sean yeah well you're almost there I'm almost there um so we need to sell item address private key and item so the the command will have the private key and an item and we got to add another transaction with the buyer address so let me go to my buy item on I just do a little this is going to be a bad idea but I'm G to copy this over here a new transaction transactions get trans I'm just I'm just all over the map with my code too just hacking away okay let's move some of these up to the top well I don't think we need a price on this one but okay so the buyer address is going to be null this time seller address should be public key I believe check buyer address seller address price and item sold price item sold and then I believe we actually don't add a signature to this one because we're selling an item back to the game or maybe we do I don't know oh it does say signature yes so we do need a signature I don't know what I was talking about um there's something you don't need a signature for though I thought I don't remember oh it's the it was the reward transactions um okay so I'm GNA scroll up to the cell item thing here so we're supposed to add that buyer address should be null seller address should be the matching public key for the private key ented so we've got a seller private key that comes in and we had a key pair there and then their public key okay so we got the public key um price should be five less than the purchase price of the item so we have item sold price equals get item price that should just be able to go minus5 there yeah um signature should use seller key pair toate seller address price and item sold um so public should still work price item so there we go um you should need uh shouldn't need anything here I'm wondering if there's supposed to be something that makes sure they have the item before they can sell it but I don't see anything written well you might need to check your actual use the stories no maybe I kind of skimmed over them seller address yeah I don't see I'm selling not okay so we do if um what is it get address items um I should be able to address C items equals get address items key think so just going to console log items here and nothing should be happening because I'm not writing any files so what I want to do is get an item to somebody somehow transactions we don't have any items yet so node buy item and I want to see if when you buy an item you should be able to buy an item by running by private key item okay private key let's do a different item this time a spray I think it worked actions there it is okay so now we have a spray we can sell let's just add another one we have two um and it says that the transaction pool is included uh the items are so they should be included so if I go node sell item um that private key get an error get item price item bot minus five yeah maybe I can't do that um oh it's it's because I didn't put in an item no oh is it is can I not do that either what is it you you see something you need to tell me it's not item bought item sold all right all right although I'm not inputting an item here okay so there we go we've got my items here they are that worked everything worked so I need to say if uh not items items item sold greater than zero or actually you know what let's just do if items items sold greater than one so if you have at least one and then do something transactions do push come on new transaction transactions. right you keep wanting to do that oh it's just feels natural okay yeah there I think that'll work let's see what happens if I sell one of these sprays console like my but that was before it actually changed transactions yeah um there it is and I can I think there's a helper function here I thought items gift items oh yeah there's a little you can run that to gift items let's run that on gift items I think should work now it sends an item to every wallet yep free item to every wallet that's kind okay that's that's a fun air drop um I wanted to check the balance or get address info there we go node get uh address info and I think if I just do the name here we go so we can we have some info there has a balance of 20 and a few items there we go that's kind of nice um and let's see if this selling test passed cross our fingers here no no big fail sell item what do let me node cell item actually I'm just going to node M Block should clear out the transactions and then sell item okay so now we just have none I thought it was working before I must not have that item what address is that um okay [Music] node you can use you're also saying if it's greater than one hey no items that items sold if it's greater than or equal to one we go thank you there it is um and yet it did not pass but I guess that was probably the problem so let's try it again there it is it passed all right yeah that was off by one errors um and now we just need to add a bunch of transactions and stuff like that so node node Mine Block we just pop these open I'm gonna pop these open here so we can see what's going on blockchain you got a blockchain here what looks like about three blocks node item then we need wallets so I think if I grab a key hot keys don't work excuse me spray transaction work there it is so this person is buying a spray two sprays that one didn't work because we don't have enough money um sure we'll just mine it um this person node by item paste we'll do icon should just made three transactions buy some icons we'll just mine another block we'll node gift items node gift items block yeah you can see it it keeps adding to this array blockchain and transactions so it's kind of neat um and I wonder how many more we need let's see if I have any passing I don't think that's enough though I just add a bunch of addresses two addresses mine a block we're gonna we're going to do this mode cell item that uh ion oh M Block generate wallet this is what you want this is what you want um Sean there now we have our own wallets 40 coins each um node Mind Block let's see how far we got 10 blocks no gift items M Block does not tell you in the console how close you are no okay that's got to be enough there we go nice oh one project down okay let's move on to the next project um yeah we finished this one and the next one is uh build a fundraising smart contract so it's going to be kind of similar and it's got a bunch of Jason files and stuff where you put your blockchain in there um okay let's see what it says here it says I need to create a deploy smart contract that raises funds for my startup the goal is to raise 150 tokens before the seventh block is mine you have some boiler plate code and files um I should not need to change any of the boiler plate code the fundraising contract folder is the only place I need to wrate code so I have this folder which is going to be my contract and the rest of this stuff is not stuff I need to change anyway okay the initial State it's the an object my contract will store JS files in that folder um will be run by the contract on transaction will run when a transaction is sent to the address of my contract and the on new block will run when a new block is mine and then it says that the files or the functions on contract can only run if the status of the contract is open so yeah this is my contract State object and I presume there's going to be some sort of status open or maybe that automatically gets added um okay um the only two helper functions your contract files can use are add transaction and update contract state they're already added in your contract files Okay so we've got an on new block file that'll run when new block is added and this on transaction will run when uh transaction is sent to the contract address and then these other files is just showing all the things you can use in any other file you're going to need to add here I know we're going to need to add a couple I think it says there's number of variables that will be pass your contract files uh ones available are already defined there and those two files uh yeah so it says there that we can use those variables um and then here's the command to deploy a contract says it will create a contract address and put the contract itself in the smart contracts Jason thing um and then it will get added to the blockchain the next time I mine a block after it's deployed you can run the contract files with this command um yeah and there's some notes Here says mining a block creates a reward transaction with the random address from wallet AAC okay US stories bonus hints there's a lot of hints so there's gonna be a lot of like okay hints do this first I'm GNA do this first because it says do this first there's a there's an example contract for you to okay do this first it will help you understand how contract there's an example contract for you to play with to see what it can do keep your eye on your jent files and run these commands um so we've got like transactions smart contracts maybe blockchain we want to I'm in the wrong folder from before so I better make sure I switch build a run this initialize blockchain okay we got a block node deoy contract example contract because that's the name of the folder here and then a private key from the wallets private key let's go with this one um okay so we should have a message I guess your contract has been deployed at the address it will be added to the blockchain on the next BLM cool nice so there it is and it has my like functions from the example contract folder and the state of the contract I guess so node block I'll do that now it moved over there it's blockchain a transaction private key from Wallet transaction okay so so do you want to explain what's in that functions object it's the code from these files these JavaScript files so you're just taking the code as a string and sticking it all on one line yeah yeah it works it's uh I mean it's it's pretty similar to how I mean I not maybe not that part of it is but it's kind of similar to real smart contracts in that code goes on to blockchain that's I guess more the purpose of of kind of some of this is to get the concepts across I don't know I think it's nice I think it definitely helps for debugging yeah all right um let's try and do a little more here node add private key from wallets um so the contract is now like a different address and this person this wallet created it so you could still use that wallet to send things to the contract now um private from example contract address and I'm pretty sure nobody has any coins or maybe they do I don't know so I have to use zero for the amount send some hopefully to the there you go so I sent zero to the contract address and it says someone said a transaction it is running it's on transaction file here's what the transaction looks like and if you look at the example contract this one it has all that information you get the transaction that came in and just a couple locks okay so it ran that file and then you can also run contract example contract address get favorite number okay node run contract sample contract address should be that over it I spell that right no you're missing the U in favorite ah look at this we got running this file favorite number is 10 and then we can set it is your your favorite number actually 10 no I don't have a favorite number example no it's actually 11 that's why we're going to change to 11 set favorite number 11 I'm kind of missing uh like you need usually you need a private key you know to update state right to the blockchain I guess we don't in this one um which is fine but I ran that and now it should be there it is and if you were to look through some of these blockchain files You' see all that kind of happening like I guess there's a transaction okay this the smart contract transactions basically transactions go in their own file um let's see what happens when I mine a block yeah and then everything from both these files gets moved over to the blockchain yeah let's tr get a random reward when a new block is mine and yeah so smart contracts kind of have their own area here um but I guess typically on real blockchains they're just regular transactions but yeah or you nothing okay let's okay let's try and get this going fundraising contract so the initial State should have a status set to open and a description to Smart contract your contract should have a get description file so we're GNA we these are the new files we need to make new file get description. JS and update description so make those two update and console log I don't know if I can copy that maybe that's a thing I'm just mumbling to myself here what's going on over there Sean I'm just watching you seeing how the master does it creat smart contracts yep um keep your eyes open for those typos I'm good at that yeah I think that's why I mostly hear um so get description console.log here's the description Des of the fund contract and then destion here probably contract state. description so the contract state will be the object here yeah but we need to actually deploy the contract for any of this this to work I don't think I need any of that I think we just need this one okay updates the description um updates the description so update cont track state um I wonder if I should look in here I think wonder if it's explained in here what that function needs remember you can just go to the you can hover over the function definition and then control click or command click not convinced you can in these ones but maybe what do you do command clicked there what do I press um I'm not sure what it is on Mac if it but on mine it's control and then I click on it and it takes me to the definition although now you have Dynamic Imports it might not do that yeah so update contract State and Y update contract State address State there we goate contract address contract address and then [Music] comma we need need a new thing something from there args just go with zero for now I don't think I need I think you could just console log it couldn't you yeah we'll throw that in there anyway should need any of that or that a contract address no it needs the whole state object so it would be contract State contract contract state. alss um TS zero maybe I'm going to go with that but I don't know let's see what it says make sure we save the file um and then let's attempt to deploy it I think maybe sure so I'm going to follow the commands from in the example contract we going to reinitialize deploying contract and then a private key paste there we have it so let's just L that to the blockchain and then we should be able to run these functions [Music] node run contract get description. JS it's the description that worked and then date description you do new description Network yeah look at that Arc zero working nice well let's see if the test passed I guess huh look at all these we got passed already wow how many left to do not too many nine 10 oh this one's pass too this one's pass too your fundraising contract should be deployed and mind the blockchain all right nice okay so running the commands to deploy your contract sending it the 150 tokens create a transactions so our contract needs to raise 150 tokens before the seventh block is mined and if it does we need to create a transaction that sends all the funds donated from the contract to the address of the Creator and then also set the status to closed and if we do not raise the 150 before seven blocks we need to send the transactions back to the people that sent them to us okay so you have to keep that all in state yeah who's sent what so initial state I guess um maybe donated so let's go transactions and then maybe an array and a um raised maybe like a number status description I think that might be enough so we need to definitely need to keep track of all the transactions that come in so we can send them back and I think that'll work I don't know if we need to keep track of the raid or not you could just Loop through the transactions I suppose so that sounds like an optimization thing that you may or may not want to do yeah okay so this on new transaction comes when our contract gets a donation so we're going going to need to if we get a transaction what do we need to do put it in the state also add to raised or something add the funds to raised we'll just keep track of it for the heck of it I don't know need it um and then we need to check if we have the 150 send all funds to contract Creator something like that maybe um yeah I'd go with that okay so contract state so a transaction comes in let me console log transaction thr that in there what does a transaction look like when it comes in yeah probably an amount and the address would be the contract address and the from address would be um whoever sends it yeah trans so this is tricky update contract State contract address New State um the state has a transactions object so you know what I'm just going to go we have a contract State here so I'm just going to contract State transaction s that push work no transaction push that transaction that came in state and then we could also do contract state do is plus equal transaction. amount maybe I'm not sure you can plus equals on a property you can't makes um contract state. raise um equals wait yeah you can can't you contract sit. rais plus equals try yeah don't see why not maybe I don't know um where am I at here okay so we've got a few things happening update contract State add to raised and then should I attempt to do this right now or should I there are helper functions for running contract running contract playing contract wallet um thought there's one for getting just the whole state I'm going to do I'm just going to do this once thr another one in there why not State console.log cont we're going do that let's just see what happens I should be able to deploy this and we'll see a transaction we'll do that update the state and then we'll be able to check it with that other file okay so um we'll go back to reinitialize and then redeploy and find the block then what we want to do is send a transaction to it so if I look at transactions there's one there suppose I could send zero to it let's mine another block so now somebody has 50 this person public key that's their public key though wallets 0412 so here's their private key to be able to go add a transaction from this person this is probably all in the instructions it's just I kind of have it memorized um helpers maybe down here add transaction I guess okay we already went through that um so we take the private key and then the two address which should be the contract address very large address I made sure to make them as big as I could yeah that always seemed like turn I looked at these no I did the opposite actually but okay so we have problems um well 50 this is my transaction though the transaction came in yeah undefined 15 new state well that is the problem contract address contract State all right let's try it again initialize playy M Block let's do that twice so we have a transaction node add transaction um private key private key private key here we got this person 0416 contract address and 50 I think it worked okay so what files have changed this one right here transaction showed up from okay that person to the contract address this is we just sent this to the contract and it did some things there with signatures um and then the contract ran this file here yeah so we got this log of the transaction that came in and then so if we say get State now it should all be updated node run contract East get state. JS it is smart contract status open transactions nice okay awesome so now we need do like if if contract contract state. Rays greater than or equal to 150 um send all ons to Creator just like I put right there um so we need to add transaction key Creator address so I suppose that would be their public key of the Creator and private Key Well wouldn't you first send to wouldn't you first put all the transactions into the blockchain that the contract has state for and then send a transaction from the contract to the owner say that again so your contract state has a bunch of transactions in it you need to mine those so that the contract address has those funds and then you need to from the contract address send a transaction to the owner well I'm just storing the transaction information in the contract State the actual transactions are also going into the transaction they're already going through right pool right so they're they're already going onto the blockchain okay I just need the information so that if my contract does not succeed I can send all the stuff back and I proba probably probably only need like the from address and the amount from each transaction that would be enough to send it back so I'm going to I'm going to do that I think on transaction um you know what I'm not going to do that all right um so what was I looking at here this private key I presume is that the private key of the contract itself maybe it's kind of hacky but you can yeah you need to you need to sign it from the contract yeah yeah um and so I wanted to find this function and see what it looks like add transaction somewhere you know what there's this thing you can find right in here somewhere private key to address amount add transaction private key to address Creator address amount contract state. raised that sounds right so you're definitely sending everything through even if it's over the goal yeah yeah isn't that how real fundraisers work you can raise you know you set a goal of something 10,000 but you can also raise much more pretty sure that's any to watch Shark Tank no maybe not I have and that's what they say on Shark Tank we raised 20,000 on a goal of 10,000 that's what they say um well I mean if you have let's say you raise 140 from previous transactions and then somebody wants to donate another 100 to get to 240 where would that other money go who would get it well I don't know I'm used to things like Kickstarter where you have a goal of 10,000 but then some of these you know some kickstarters they have a goal of 10,000 and they get a million pretty sure that they don't get to use the million all right it doesn't matter that's how this one works okay yeah um so I think this file might be done and I don't even know I'm just going to click this run test let's see what happens maybe that one will pass running and send it there it is so if the 150 tokens get sent yeah it worked nice oh but I also need to so add a transaction I guess I need to update contract state. status equals close maybe I think is what I'm supposed to do then update contract State copy um I would just move that line to the bottom of the file all right yeah that's good call yep is it supposed to be a Capital C here no the're [Music] closed what did these already say no it does not look like it okay I guess we'll run the test then we don't have to go through that process of deploying there it is now we need yeah now we n
Original Description
We just released the beta version of our new Web3 curriculum on freeCodeCamp.org. In this video, freeCodeCamp software engineers Tom and Shaun will walk you through some of the new Web3 curriculum projects.
🔗 Learn more: https://www.freecodecamp.org/news/web3-curriculum-open-beta/
🔗 Access the Web3 curriculum: https://web3.freecodecamp.org/web3
❤️ Support for this channel comes from our friends at Scrimba – the coding platform that's reinvented interactive learning: https://scrimba.com/freecodecamp
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
Dates - Beau teaches JavaScript
freeCodeCamp.org
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
The Definition of Ready - Agile Software Development
freeCodeCamp.org
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
Working Agreement - Agile Software Development
freeCodeCamp.org
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
Definition of Done - Agile Software Development
freeCodeCamp.org
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
The INVEST approach to product backlog items
freeCodeCamp.org
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org
More on: LLM Engineering
View skill →Related Reads
📰
📰
📰
📰
Only10 Vol.26.01 | 10 AI Projects Worth Watching This Week
Medium · ChatGPT
Top 10 AI Development Companies in the USA (2026 Edition)
Medium · AI
Kimi K3 is so popular Moonshot ran out of GPUs and paused new sign-ups
The Next Web AI
What smart people are saying about IBM’s AI warning and SaaSpocalypse fears
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI