👩‍💻 Web2 to Web3 🚀 - Week 2, Day 3: Intro to Ethereum Clients & Hardhat

Web2 to Web3 Curriculum · 16 Aug 2025 · 1:32:52

Austin Griffith and the BuidlGuidl team continue the Web2 to Web3 course with Ethereum clients and Hardhat. They explain client diversity and node sync modes, then sync a Geth node and compare it with Infura. A short look at why indexers exist leads into Hardhat: launching a local node, deploying a first Solidity contract, interacting with it, writing tests, and verifying on Etherscan. A practical session for web2 developers.

Speakers

Topics

From Web2 to Web3 Curriculum, hosted by BuidlGuidl.

Transcript

What's up? I'm Austin Griffith. I'm here with Carlos and we are on what is it? Day four, day three of week two. Day three of week two. So, we've this is like the eighth day of of building. And we're going to look at we're going to finish up looking at running some scripts and some GU node stuff, setting up our own node in this big peer-to-peer network. And then we're going to start looking at some solidity. We might get into hard hat and run our own local uh blockchain and kind of run a deploy a contract and test it. So the very very beginnings of of actual smart contract development. We'll start today. But let's finish up with some guest stuff.

We ran we built a bunch of scripts and we had those scripts talk to Infura mostly, right? We were talking to Infura's endpoint. We were asking Infura, hey, what's the block number? And they were running their node. But in this decentralized world, you know, we're trying to be as decentralized as possible. It's better if you run your own node. Let's see if I can get out of the way. I have my own L1 node right here. This is it's not a GU node. It's a nethermind or nethermind, but it's basically L1 Ethereum what a GU node is. And it's talking to all like 20 other machines peer-to-peer. And so there's thousands of these nodes in the network and they're all keeping track of the

blockchain. They all have a local copy and you can ask any of them anything like what's what's the balance of this person? What's what's the block number? And uh you could ask them just like we're asking in Fura. So it's a lot easier to kind of hit your own node and ask a question. So hopefully I think Eda, do you think you could take over? Also, all of us are sick. We we all have cold. Apologies. Apologies to you at home for having to listen to our crusty voices, but here we go. Eda, how are you feeling? How are you ready to show some stuff off?

>> I I'm ready to show some stuff off. Let me directly start by sharing my screen and we can talk to like setting up your own. >> Awesome. Perfect. >> So, there's a couple different types of uh L1. We keep seeing L1 layer one. It's it's basically like the main the mainet uh Ethereum chain, right? You could run GU, but you can also run other clients. And that's like maybe we should talk about just for a second like client diversity. When when we talk about client diversity in Ethereum, when we're running a giant decentralized network that no one is in control of, we're worried about if everyone is running the same exact client and there's a software

bug in that client, the whole network could have a problem. So the the the phrase, you know, uh client diversity is all about let's have lots of different people running different versions of software that basically does the same thing in case there is some kind of bug in one of the pieces of software. Hopefully the network will stay up. So I have my nethermind back here which is one one type of client, but we're going to talk about GE today. GU is like the major it's go ethereum. It's a Go implementation of the Ethereum protocol that you can run locally. You fire it up. It talks to peer-to-peer to the whole network. It syncs the whole blockchain and then you can ask it for

questions like you can ask it questions like, you know, uh what's this person's balance? What's the block number? You can also send transactions to it and it will put those transactions into the MIM pool, too. So, here we go. Here we go. >> Yeah. So, I did install it. >> Yeah. Um, so I actually have it installed on my PC, but maybe it would be good to like walk through a bit of the steps. It's really just to like um yeah, you have the steps over here to follow. It's pretty straightforward to follow the guide, but we'll like link the uh link the steps as well. Um, so I basically just like did a brew install and then uh that's that's basically all I did to install the Ethereum. And then let's kind of bring up my terminal over

here. gonna open a new one. Let's start from scratch. Yeah. So, I basically installed the node and now I can run it to sync it on my PC, right? That's kind of what I'm going to do. I have the command over here. So, like let's directly >> and the sync modes are different too. Notice the sync mode light. This the sync mode is depending on how much information you want your node to store and verify. There's there's the idea of like an archive node that basically stores and verifies everything and could go back to like block number 100 and tell you everything about the network at that current state. But that

is super heavy. You have to have like terabytes of storage to be able to store it. Then there's like full mode which a full node is basically like all the information and concurrently verify. And there's probably some details here that my smooth brain is not completely covering, but it just kind of like from a high level, you've got the archive node. Very very few people run that and it takes terabytes to hold. You've got a full node which has the whole state of the network and verifies it locally, but it doesn't keep uh it doesn't store like uh like all the old different states that you don't need. It basically proves them and throws them away. I'm definitely not saying it right, but just this is like my my high level of it. And then there's like a sync node that's like light where it's going to quickly

sync and it's probably there's probably some kind of like checkpoint that it checks in on and then starts to sync afterwards, but it's much faster to sync with light node, but it's not doing like a full like storage of everything compared to a full node. So there's really just like the full node and the light node. There's you can get it quicker and you can have a full node running that's talking to the network peer-to-peer. You can send transactions to it. can read from it or you can have a full node that's going to take a lot longer to sync and have a lot more storage. So, it looks like you've select a light node which is way quicker for us. You've also opened up the HTTP on Zero, so you could even talk to it from like an external machine. Uh, but yeah, it looks like we're ready to go. Let's

fire it up. Boom. Look at it go. Oh, it's so pretty. I love it. >> So, we're basically getting the content on the blockchain on my local PC here from >> Yes, exactly. and you're setting up peers. See, it's looking for peers. And the current peer count is zero. So, it's going to try to find a bunch of peers in a peer-to-peer network and communicate with those peers. And anytime any of those peers finds a new block, they broadcast it to everyone else. And everyone keeps the chain of blocks. And the longest chain of blocks is what we follow as the valid one. Could you stretch it out too so we could see a little bit? Yeah.

>> Oh, yeah. There it is. Look at this. Good. >> Lot better. >> And we can see the GU version. So, it'll take a while probably to to sync up and find some nodes. Uh sometimes with a light node, it could take like overnight to sync up, right? Did have you have you run this before? And how long did it take? How did it go? >> Um, so I did leave it open like I I think it was it wasn't like overnight. It was more I think like a couple of hours. Uh, but we could still like connect to it and like get the like user provider like connect to it to see like that we're connecting to um this address on my machine. Uh, so we could like try that while this is waiting. But yeah,

maybe we could come back at the end of the episode and see if we have like more information here. >> Yeah. Yeah. Let's let's look at that script just real quick. So we have this script that talks to an RPC and before we were just kind of hitting Infura. We were just asking mainet infuro with an infura key and we could get maybe, you know, it took maybe like a second and a half to get an answer back, right? There's definitely some rate limiting going on there where we can't just like hammer their node. It's like an API service. It's like a web two service that takes time, right? So, what we'd like to do is switch this to instead of talking to Infura, we'd like to switch it and tell it to talk to our local node. And that will allow us to

query the chain a lot faster. We can even have more access to things like the MIMP pool. We could see what transactions are trying to get mined right now because we have our own local node and we can look at that kind of stuff. There we go. And 8545 is the port that that GU node runs on. >> Um, and yeah, like it's on my local host. So just local host and the port number. So what we could do is like try to get the block number, right? Like >> let's try to get the block number from Infura. And then let's also try to get the block number from our node and see uh just just so we're getting two different block numbers and wait for those two to basically be equal.

>> Cool. And so one thing to really dive in here is that there's there's a lot of indexers in in web 3. You end up creating what's called an indexer because it's so hard to read directly from the chain from from your clients. Imagine a client pulling up their web browser and they have a wallet and they'd like to see all their transactions. This is actually a really hard thing to do. You can't just query GU or Infura for all the transactions for a user because the way they're stored. They're stored in blocks and the blocks are just like these sequential blocks full of transactions. So if we wanted to get a transaction history for any given account, we basically have to

crawl through every transaction in every block and look at the to and from and save it for that user. So if if you wanted to provide your user with a quick transaction history, there's actually a middleware layer there of of a an in an an indexer, right? And it's a middleware service that basically looks through all the the blocks ahead of time and gives you a much easier cleaner way to like query for that information. But a lot of time these indexers are centralized and so if an attack happens or something is goes wrong you could probably like lose that service for a little bit. You don't have 100% uptime like you do when you're talking directly to Ethereum. Just to kind of clear that up. Okay, let's see

what we got here. So, we're going to check the block number on a infura and then we're going to check the block number on your local node. Let's see how it goes. Hey, hey, look at that. Both of them are caught up. Oh, my cat over here. Sorry. >> Great. All right. Oh, yeah. And it's getting new blocks, too. There we go. So, it it it's only has a single pier. So your machine is talking to one other person who has >> who has connection, but it's working.

We're getting blocks from them. And we're and this is how you know that your node is synced up and good to go when it starts pulling one block at a time. You'll you'll watch it sync up and it'll pull like 20 blocks at a time for a while and the CPU will really spin up, but then it'll kind of get stable and get to the point where it has the full chain stored and it's just waiting for that next block to happen. And as soon as someone on on the whole network, remember there's thousands of nodes. As soon as one node finds the the nons to mine the block, then all of the nodes will will broadcast that information to each other and it will spread quickly and uh we'll we'll get the current block. So let's see. Are we maybe even faster than Infura? I bet if we run this

script kind of over and over again for a little bit, uh there will be times when we will be ahead of of Infura. Oh, it's doing some other stuff here. Oh, it's getting Sanford's balance. Let's start getting all that stuff locally just because we're waiting on Infura here and and let's switch it to our provider, which should be super easy. We just switch provider to local provider, right? So, cool. >> I think that's all. >> I think that's it. Yeah. Now, let's see if it goes faster. So, now you should just be able to run this thing over and over again. Let's see if it ever happens where our node finds the the block first. So, we're 34 34. So, we're waiting for block 35 to come in. And you could even we could even at the there we

go. Look at look at that. So, our node since it's talking peertopeer got it before Infura got it, right? Or perhaps Infura has some error checking where they have maybe five or six nodes that are running different versions and different things and they're seeing, you know, like, okay, this node has it, but does anybody else have it? And make sure that like maybe two or three nodes get it before they broadcast it or something along those lines. But sure enough, we're able to see by talking just to a peer-to-peer network, we're able to get the state of the blockchain synced up faster than than Infura, the the service. Very cool. Okay, so if you at home are looking for a challenge, try to set up an indexer. Build something that

looks at the current block and then you can get the block and then you can get all the transactions in the block and you can loop loop through them. And maybe we'll do that on the next episode or we'll talk through an in an indexer. But just wanted to expose that you can talk to Infura, but it's very slow. If you want to get a lots of blockchain data, if you want to run your own indexer, uh if you want to know transaction history, that kind of stuff is going to take an indexer and you'll have to build that out. And so this is just a good way to do this. You'll need to run your own node. And also a much bigger picture thing like Carlos alluded to I think maybe before we hit record is that this is a network of peer-to-peer machines and you're participating in the

network by because it's decentralized there's no central control right so what makes it more and more decentralized is more people running these at home. So you running a node at home means that you're just another peer for other people to connect to. Notice we still are only connected to a single peer. some some brave soul out there is letting us connect to them and get get uh our our no our blocks. But if that one computer falls over, then we're going to lose our connection. So hopefully you have a web of lots of different peers that you're talking to and you're talking directly to them peerto-peer and you're syncing up the state, but that that's participating in the network, right?

We're not mining blocks, but we're at least participating in the network in terms of verifying blocks. Anything to add to that? like just like kind of the idea of this like running a node is such a an integral part of creating a decentralized network. You need more peers. >> Yeah, I was really surprised on how easy it is to like run your node um to just install the software and get it up and running and you could really see the difference on like using a service especially when you're like doing it locally. Um, so yeah, like it was a was a nice wakeup call for me as well.

>> All right, so uh I just wanted to get us exposed to running our own node, but I didn't want to do too much of a deep dive on it. I feel like it's probably time to move on to uh hard hat and running basically we'll run an entire implementation of Ethereum totally locally and we'll have our own block that starts at block zero and like a genesis block right so we'll create our own local blockchain that mimics Ethereum but we're going to kind of put away our connection to Ethereum and we're going to work locally hopefully what what Carlos shows us next we could basically set up on an airplane if we wanted right you don't nec necessarily need to have a connection to a bunch of peers. You can run your own kind of like fake blockchain locally and you deploy

contracts to it and interact with them. But if you're ready and if we I think we've got things covered here in terms of just like exposing y'all to you should go run your own GE node. You should go run maybe a different uh client maybe like meind or another uh client. And then there's going to be there's going to be the execution layer and the consensus layer, right? And so there's going to be what what used to be called ETH2, but you'll run like a Prism validator and you'll run a beacon chain. So there's a couple different types of nodes that need to be run. Uh but we'll get into all of that later. Just wanted to expose folks to here's the node and here's how it works. Anything I'm missing here.

>> I think we're all good. >> All thumbs up. All thumbs up. All right. Great demo. Hopefully your peer eventually connects to some more peers. Like I feel like your note is uh your note is lonely. >> Well, we'll see by the end of the the >> There we go. >> the the video. >> Yep. Yep. All right, Carlos, you want to take us away with some hard hat? Then let's make a transition to we talked to Infura, then we spun up our own node and we talked to our own node. Now we're going to spin up our whole own blockchain, right? We'll create our own blockchain locally and we'll talk to that next. And that way it'll be free and easy and cheap and we'll be able to start orchestrating some smart contracts.

>> Yep. So, first like sorry for my my voice. It's a little Yeah. So, I'm sorry. So, can I steal the screen from from you? Hello. >> Go for it. Yeah. >> Oops. I can't. I think you have to >> Oh, no. You might have to stop and Yeah, I might. There we go. There we go. Okay, let's see. >> There we go. We got hard hat. >> Okay. Um, yes. Okay. So, I think um you already did like a good introduction of what hard hat is, right? Hosting. Um, not sure if you want to add like

anything anything else. Um, >> I would say like along with it's going to run a whole blockchain for us. It's also orchestration uh software, right? This this software is set up to compile contracts and deploy contracts and even test those deployments. So, Hard Hat isn't just our local node. uh it is a local blockchain, but it's also all the software involved with taking Solidity and compiling it to byte code and then deploying that bite code to the chain and then testing whether or not that smart contract does what it needs to do and and all of that stuff in between.

So, it's not just a chain. It's actually orchestration and testing software and it's also included in Scaffold ETH and we're we're getting you exposure to it at a low level, but pretty soon you'll be using this stuff and it'll all be kind of under the abstractions and you'll just be firing a command and everything will work. But we want to show you the guts first before we we really show you scaffold ETH and the speedrun and everything. >> Yeah, that's a good point. Like hard hat is not only a development environment like a local environment. It's also allows you to deploy contracts to mainet right so you will use hard hat for local testing for compiling contract but also for deploying to mainet. So I think maybe the first thing that we can do is

installing hard hat right on our local machine and >> sounds great. >> There are like two ways of going uh I mean of installing hard hat. Um the first will be just to like instant install hard hat standalone and then going from there. But I really like this uh MPX hard hatut. >> Yeah. So um because it's allow you to select like a sample project which I really like because it gives you like the you get like the full picture with all the folders and the files that it created it creates you get like the full picture of what hard hat can can do. So uh we use like nodes and npm and mpx if you don't know that's actually like um

command that allows you to install or to run binaries that you don't have in your machine. So um the first time that we run MPX Harahhat it will actually look to the to the npm repo and we'll run that binary for you. But then if you install hard locally this MPX will run your local instance in in node modules. So let's so here I think this is from yesterday. Yes. So let let's create a new folder here.

Let's call it day three to be original. Um, and okay. So now let's CD into day three. This is an empty folder. So let's install her hat here. Can you see the the screen? Can you see like the the text is all good? Yep. Yeah. >> Yep. >> You see the hard hat ask? Yep. >> Nice. Okay. So there are like a few options here. Um I usually go with the basic sample project. So we are going to do that. Um this is the project route.

Yeah, let's do that. And yes um Harat comes with some dependencies that let's also install them. Like waffle is just like for testing stuff. Chai. If you're familiar with with NodeJS testing, you probably are familiar with Mocha and Chai. And also you have this plug-in called hard hat ethers and what it does is just is take ethers like we know ethers right we have been using ethers in the last few days. So hardhat ethers what it does is just provide like a like another utility functions inside ethers. So you have you can do a few things uh quicker and more let's let's see here

ethers I think. Yes. So this plug-in and you have like a few utility methods here like the signers get contract factory and also it gives you like the uh a provider shortcut I think. >> Yes. >> And all the utils like parse ether and format ether are still in ethers but they just extend that and add some more things that you're going to need. >> Extend that's the word. Yeah it's extending ethers. Thank you. Yeah. Okay. So this is still stalling dependencies >> and maybe we should talk about there's also other options other than hard hat

there. Uh truffle is another orchestration that is kind of the OG you used to truffle compile. Uh I I built my own orchestration software just using soul C. You can go to npm and find soul C and it's basically a compiler. You can give it solidity code and it will spit out bte code and then you can deploy that bite code to the network by just making a transaction. So you can build your own orchestration. It won't be fun. And there's lots of great things to do this now. And there's a new one called Foundry that's bu written in Rust uh that also does the same thing. It it'll it'll compile and test your contracts and deploy them to to another network.

And so there's there's options here, but hard hat is kind of the current defac de facto. This is the way to go. It has really nice things like you can put console logs in your smart contracts and it will spit them out to you here. And it's also built into scaffold ETH which is like kind of like week three we will be doing a lot of like full-on DAP building and a lot of it will be backed by by hard hat. So we're we're showing hard hat now but know that there are other options of course. >> Yeah. Okay. So um the install the installation just finished. Um so let's take a quick look of what it did um when we run this this sample example project.

So it created I mean we are going to deep dive like dive deeper sorry dive deeper after but let's take a quick look first. So it created like this greater contract. Also created this sample script that we can run from. We can do like run hard run scripts sample script and we can also do node scripts and then the name of of the script and we will see that there is like a a difference. I also created this uh sample test. This is actually like a unit test for the for the contract. And

also this file which is very important is the hard hat config file that right now is uh I kind of empty but we will be filling filling it later. So I think um yeah the thing that I most like about the hard hat is being able to run the hardhat network and the hard nodes. Right. We we just talked about the Ethereum blockchain, the Ethereum network and Infura which is like a node or our own node that connects to that network. So we can do the same thing with hard hat but locally. So if you do MPX hardhat I think it's node, right?

>> I think so. Yeah, it's actually going to build a blockchain for us and fire it up. >> Yep. So you see here like this is setting up a local blockchain and it's also setting up this um JSON RPC node for us. So we can connect to this the same thing that we connected to infura or the same way that we connected to to EDAS node. This is the same thing but locally. >> And if we had that script and we said what is the current block number it's going to say zero or one, right? It's we're going to be on the very first block right now. Yep. the genesis block >> the genesis.

>> So also um something really important is uh this accounts that had created for for us. So this past day we have been creating a lot of random wallets right and random pneumonics and random private keys. So be careful here because I mean I think it's yeah it's here but hard like these addresses are 100% deterministic. So everyone who is running hard in their local machines are going to get the same exact private keys and accounts. So don't use like these addresses as that like the same thing that we did like last like yesterday for example that we will create like a new pneumonic or new private key and we use that for you know sending funds or

whatever on mainet. So this like everyone is getting the same the same account >> and I bet there is mainet transactions right? I bet if you copy and paste that address into Ether Scan, we'll find that some people inadvertently unfortunately have made some transactions with that account. And this is something so we were talking about Truffle earlier. Truffle did it a little differently. They give you a random account every time. Yeah, look at all those. So anytime anyone accidentally yolos some money into that account on mainnet, there's probably bots that are just set up to drain that as fast as possible, right? Because that private key is exposed.

It's kind of strange that hard hat uses the same account every time for everyone instead of giving everyone a fresh pneumonic each time they run it. But I think that's so you have like a good deterministic test suite and you know all these different accounts every time. >> But yes, to reiterate, be very very careful with these accounts and know that you you do not want to be deploying to mainet with the hard hat accounts that are generated for you with these private keys that are exposed to everyone. But they work great for local stuff because it's it has what 10,000 Ether in it. So we have more money than we need. We're good to go and we can like deploy and send money around all we want using these local accounts on our local chain.

>> Like we can actually add this private key to to MetaMask, right? So we can just grab this private key and going to MetaMask. >> But remember, it needs to be a dev MetaMask. If this is like your main meta mask and yes, you are have real funds in it and you're also adding these random private keys that are exposed, you're setting yourself up for some real terrible outcomes. So, make sure this is like a development hard hat or a development metam mask and you're just adding this because you want to do some, you know, interesting orchestration things with that account >> and and you're connected to mainet right now. So, you want to connect that back to

>> Oh, I think I I I just created a new one. Yeah, I I have to import, right? I think I I I >> I clicked into create. >> Okay. >> So, let's paste it here. >> Yeah. Like F39, right? That's the same >> the one. >> And if you go to local host, you'll have a huge balance if you correct connect to the right network. >> Yes. So, we are in mainet. Let's go to local host. local host big money what I can do with 10,000 ether >> like can I transfer this to mainet somehow >> yeah exactly let's bridge this yeah >> okay so um yeah I think le let's try to

use some of the script that we used for day two and use some of them to you know do the same thing but in the in the local hard network. >> Yeah, >> that's a good idea. >> I think Oh, let's for example, I get the balance of of this of this address, right? So, I'm going to copy um this one. Uh well, let's first create a new script called get balance.

Okay. Oh, and one other thing remember that we use this type module in the other things to use like the ES6 uh I don't know if you remember but on the last few days we have been using ES6 and here by default hard is using the common yes so I'm not going to change anything so let's keep with with common yes and so it's like a way to see like the other way to do it right not only >> so so in this case in the package JSON you don't have that whole type equals module thing. Yes, >> there was a type module and it's not here in this case. And so we're using the require instead of the import.

>> Yeah, like all the scripts, all the tests are using like this common GS. So I don't want to change it right now. So let's use this common GS. Uh yes. Okay. So I just copy the sample script and then I'm going to delete all of this and Okay. Uh from this script that we have here. Okay. So now instead of using the infura URL let's say like the local provider right URL and you can copy it from here.

Oops. Okay. So with this the provider now points to the to the local network to the hardhat network. So we can do something like um that we did before previously like let guess let's guess the balance from not from vital because vital won't have like any money in remember that we are using like a local blockchain right so there's like no data like we are like on block zero right so only these addresses will have money on it. So let's uh do something like um

right count zero address and this can be this one. Okay. And now uh con account shield balance this will be provider get balance account address remember that we need an an await here and then if we want to pretty print this we I think we already know this right we need

the ethers utils I think format, right? Format headers. >> Yep. >> And you you said account zero because it's there's a whole array of accounts. Oh, it it even says account zero. We call it the zero account all the time and I don't know if people there's also the zero account is in all zeros and that's where people burn things. They send money to all zeros. But I call it the zero account myself all the time. It's just the first account in the hard hat list of accounts that it gives you that it pre-populates. So let's open open a new tab because we want to like the if we close I mean this tab is going to close the node. So we we want the node to keep running. So let's

run this u script will be like this >> and that node will report back to us whenever we ask for things like block number. It'll let us know each RPC call that comes in. So you can see kind of like the action that's happening on it. Yep. >> Come on. Big num big big number. There we go. >> So 10,000 E. So much. >> And yeah. >> And there we go. We see that it did a chain ID and a get balance. Yep. Yep. Exactly. >> Okay. What if we try to send ETH from one account to another account?

>> Okay. Yeah. Yeah. Maybe try to send Vitalic some of our uh our test net just like we can do it >> only like a 10%. Yeah. Do you do Yeah. E script and you almost need these like just tinkering around, you almost need to build a few scripts. You you'll find as you as you get better at being a web three developer, you have just like a these little Swiss Army knife scripts of yours that you you have and you run against nodes all the time, checking balances, sending value, things like that.

>> Yep. So, let's check the send if script that we wrote yesterday. Um, and >> looks like it's a rinkabe provider. Yes, but we can save we can save a lot of this stuff because of hard hat because here we have to instantiate the provider and the signer like all the time but hard hat can do that for you and you can save like most of this stuff but let let's let's copy this and let's make this work and then we can use some hard hat utils for for it.

>> Got it. So we're taking scripts from day two that are in a different folder and we're bringing them into day three where we have hard hat installed and we have that other implementation of ethers that hard hat is wrapped. So >> we are still writing ether scripts but we're going to leverage some of the extra stuff that comes along with hard hat. >> Yeah for example remember that we implemented like this get providers and get signers. This was some util function that we created and I mean we can go there and it just instantiate a new wallet and with the private key the provider and all of that but with hard hat what you can do there is um well let you can do two things here you can have ethers from from hethers and and hardhat

from from and this hr e from hardhat or you can also import ethers if you want from from harat But let's do this. And now for example we can do um hard hot signer and this will be so what what we are doing here is we're accessing the the extended version of ethers that hard hat has. So we can do I think it's get signers right?

>> I'm not sure. We we'll find out it. Yeah. Yeah. Yeah. Let's do that. Yeah. Let's return here. So, so let's console get. Oh, yeah. Importing some stuff here that we need.

Classic. Yeah, >> it's a promise. >> Okay. So, this looks like an array of signers, right? Yes. Like as you can see here when we created like when we started the the hard hat node it gave us like a list of of accounts right usually you know that from the same pneummonic like you can derive as we saw just the other days you can derive like multiple accounts so what we can do is maybe getting all the signers and then getting the first one right like the F39 I think that's the one so

>> and then maybe we just output the address of that or something. It should just be the F9 or something. >> Yeah. >> F9 address, please. >> There you go. >> Yes. >> So, you see that with hard hat we save when on the other script we need to we have to do like this util to get in the provider, get in the signer, you know, and and then inside here you have to instantiate the wallet with the private key. So we save all of that with uh with hard hat because already does that for for us. So here we have the signer already. So we can we can do this. My balance will be like harasser with balance. This will be the same.

Well we let's let's send uh to address. Maybe we can use like some of the like the account number one for example to send like some No here count this like 70 right? Yeah. So sending it to to address and then we have assigner to address and then we are sending 10% same thing that we did the other day.

>> Cool. >> Okay. >> So so we have multiple accounts set up on our hard hat and we're going to use account zero to send 10% of the value to account one. And we can just kind of double check everyone's balance after that. Neat. >> Yep. And we will also see because right now we haven't made like any transaction yet. You only have like this breeding stuff. But we are going to see how the transaction is happening here. And um yeah, let's clear this scripts. Then this is send it.

Okay. So it seems >> in mind. >> Yeah. This is the H is 6F. And if we go to the net, you see that nothing happens. Any ideas? >> I don't know what's going on. >> I think >> what did we do? You remember that I said that you can like um run the nodes this way like like the scripts doing hard hat run and then the script. >> Uhhuh.

>> Oh, so you're running it outside and it's not Wait, what? So, what note is it talking to? So confused. >> Yeah, that's true. I mean, it's Well, let let's first see if this works. Okay. And then >> so where did it send that transaction? I don't understand. >> Yeah, me neither actually. >> Okay, >> but this was >> There we go. There we go. Yeah, I mean actually like I have like an aha moment with this because um hard hat provides like two

local host nodes or networks. One is local host and the other one is hardhat which is the default and when you use hardhat it's only for testing it's like a spin up like a spin up like a >> like super ephemeral. Yeah. >> Yes. and then it close it whenever the script finish. But if you want to like send the transaction to the local network like the one that we have here, you have to specify network local host >> if you're using MPX or something like that. Is that right? It seems that seems like over complicated, but maybe that's just because they want >> Yeah,

>> you can also do this, I think. >> There we go. Yeah. And just set it as local host. And then we can just say Yep. >> Yeah. So I think this will work. >> So we're sending 10% for a second time. >> Yep. >> So it works. It works. So now I'm curious if this is going to work >> like that, you know, like only with with no directly. Yeah, it worked.

>> Okay. So, that default network was pretty important. Is that right? Like it was there's this ephemeral network that spins up for you to like hit. It's almost like a an in-memory network and then there's like your local host network and you just need to tell the hard hat config let's talk to local host network. We don't want to spin up anything ephemeral or hit the ephemeral one >> because we are using like this hard hat wrapper right from ethers. So that I guess is reading from this hard hat config file or or the command line. So it was using the like the hard hat network, not the local host network. So that's like the like ephemeral I think is the word. Yeah, it's the same thing that when you run a test >> like it spin ups this ephemeral

network just for the test and when the test finish the network is gone. >> So we want to I mean yeah like we can do this default network and then we don't have to worry anymore. >> Awesome. So, we've got our network up, we're connected to it, we've got accounts, and those accounts are able to send things around. It's probably time for some solidity here, right? It's probably time to start looking at a smart contract and looking at >> orchestrating the deployment, the compiling, all of that stuff, >> even the artifacts that maybe come out of this, right? Like when you do a yarn compile and it creates the bite code.

There's probably a lot to learn here. >> Yeah, I think it actually already did it. when I run like mpx hard run I by default I think it just like compile the so it's already here but yeah so let's >> here it is solidity >> solidity >> we're eight days in and we give you solidity now >> yeah I think like we saw like some solidity on the San for NFT or something like that >> but yeah I think this is the first time like having a solidity contract in our IDE like looking at it and we are going to deploy it and we are going to make some changes and we are going to test it. So yeah, I mean if you are familiar with any like op OP programming language like this is probably looks familiar to

you, right? This this is like a like a class with some properties is how how they call this like properties usually, right? Um and then some function a constructor function which also really typical on on the on the on the classes and then some function actually this is like a read function and this is like a a setter a getter and a setter right this is like super typical on OP and I mean this would be pretty easy to understand I think um is the constructor just runs whenever you deploy the contract and only that time. So all this code is runs once when you deploy the contract and then you have this function and usually this properties that you have in a class

when you are if you come from a web background usually this always stored in memory right and in some cases you might uh store this on a database. that you might persist this on a on a on a database but here when you deploy this on on a blockchain on a network this is going to be always stored on the blockchain. So if you make a change to this variable for example here right on this set greeting we are ch changing this variable this is not in memory like this is actually when you send the transaction is actually changing the status of this of the state of this variable >> to to dive into that just a little bit more like you're you're you're building

a smart contract and you're deploying it to Ethereum and what that means is all those people that are running those nodes they all have a copy of your smart contract and this this greeting this storage element is stored on all the nodes and everyone has the smart contract and everyone has the storage for that smart contract. So you can ask any node on the network what is the value of the greeting and it can tell you and then you if you want to change that right so that's a reading if you want to write it's just a transaction just like everything else you have to uh craft up a transaction and call the set greeting function and we saw call data and we saw kind of the anatomy of a transaction earlier but the two address

would be this smart contract we would set greeting and then we pass a greeting in and then that that storage element for that contract would get updated on everyone's machine. And then if you ask the new value, it would be the new value. So there's there's a lot going on here, but this this solidity should give you a real kind of like barebones view of like what a smart contract is and and it doesn't live on one machine. It's a program that runs on all the machines and you get the exact same answer everywhere. >> But th this is great. Good introduction into solidity and smart contracts. I'm excited to play with it more.

>> Yeah. And one thing also last. Oh no, sorry. Go for it. >> Sorry. Sorry. I was just going to add so we did interact with smart contracts yesterday, right? When we were talking to the die contract, we got the AI just as a reminder like we saw like getting these values and like functions but not like how they were written. Um but when we had like the APIs like we talked with the die contract and Stanford NFT contract I think >> and when we compile our greeter an ABI an address will get created right well an AI gets created when you compile it and an address gets created when you deploy it.

>> Yep. >> And hopefully we can do all that locally and test it locally to make sure it's all going to look good before we send it to mainet Ethereum. So actually the this sample script that cames with uh with hard hat is actually I mean let's rename it because rename it because actually it's a deploy script. Um >> yeah so this is also using hard hat like the extended version of ethers which has like this get contract factory and just by the name it gets the contract that doesn't need anything else and with that um this is sending the transaction to the main poolool right and this is waiting until the contract is deployed so I I think like we can just like run

it right let's >> let's go >> and this will be on our local node Right. It'll be deploying it to our local node just because we've got that network selected. >> Yes. Like if not because we have like this default network. If if you don't have this and you run this command with any with any flag, it will happen the same thing. It will get deployed to the hard hat network and so you won't see it here because you know that's like a femeral. But now it will be it should be okay. Yeah. So let's do hard run scripts deploy. Let's see what happens.

Nice. So, we have an address. And if we checked our local node, >> there's even a console log. There's the contract deployment. >> Yeah. The contract address from this is like the F39 like the first like the sir account from from from Harack. And then this console lock is nice. I think it wasn't included in the first version of hard like it took some some time to them for to to include that utility which is super nice. So you are able to do you know sometimes something is failing and you want to log here what you know with what this is or whatever and you can print this and see this here which is like super helpful.

It sounds crazy that like console log is like the how we're doing debugging, but it it's so nice. Before this, basically what you had to do is have like events getting triggered and you had to go read those events and listen to those. So with with the console log, they've abstracted it away and they've kind of hidden it, but it allows us to get information back and you can throw stuff in that console log and get some feedback from your chain about what the heck is this value? Why why isn't this math working out the way I thought it would? There there's a lot of debugging that can be done with console log. >> Yep.

So, any volunteers to to give give like an overview on this artifacts folder? >> Yeah, we should we should look at it. Let's let's let's uh let's let's recompile the contract. Let's add some maybe like add a little counter to it or something like that. Just add a new 256 count or something like that. Just add a new value to our contract. Just make a small change to it and make it public. So we can see it. Yep. And call it counter and just set it equal to 10 or something like that. Right. So change we changed our contract up. Now can we compile it to make sure it it works? Do we have a >> Oh, I think if we >> let's just deploy the whole thing ship.

It'll compile and go. Yep. >> It just detect the change that we made and then it compiling it again. >> Yeah. So you see here compile one solidity file successfully. Yep. >> Awesome. So, we redeployed a new contract and each time you compile your contract, these these artifacts get created. Is that what we wanted to dig into here is we can go to artifacts and then contracts >> and we can see the greeter in there and see the AI and the bite code and everything.

>> Yeah. And also one thing that I wanted to mention that once you deploy a contract like you can't make any change to it and that that was at the beginning I was like oh so this this is wrong how can I change it so you can't basically you can't you have to deploy a new contract with a new address so that seems like basic but for me it looks like a huh okay so I can't change anything so I need to deploy a new contract so >> this is a great insight in terms of smart contracts and building decentralized apps. If you build a good smart contract, it usually means that no one can stop it, not even you. And so you're kind of like building these unstoppable always on apps, but they're super expensive to run because they have

to settle on chain. And so there's only certain circumstances when you want an always on unstoppable app. And that's what we'll get into in in the third week. But just know that that's that's what we're doing here as we deploy these smart contracts. There it is. >> So I think this is the >> there's the AI. >> Yes. >> Which tells us, you know, here's the different functions and the different uh storage elements. Y >> uh if you go back to greeter.json, there's more there along with the AI.

There should be the bite code if we keep scrolling down. >> Yes. >> Yeah. There we go. So that's what it compiles into. That right there is what goes on chain. >> Yep. >> And if you think of it like embedded controllers or assembly, I mean it's kind of like assembly, right? It compiles your solidity down to machine code. And that machine code is in in encoded into this this bite code here. It's basically like jumps and stores and assembly language stuff that's like way low level.

>> Yes. So, anything else that we want to look into these folders? >> I think that's it. Just showing that the bite code is there and showing that the AI is there and showing these artifacts are created whenever you you do this compile and deploy with with uh hard hat. I think that like now that we've deployed our contract, we probably want to test it or we want to want to at least like poke it and ask it what the counter value is and and do some of that stuff. >> Yeah. So, let's interact a bit with with our contract with an script and then maybe we can do a test later. >> So, just >> sorry, I just wanted to add a reminder that because also um this is on your local host like you can't search for that contract address on either scan or

like another tool. it's on your on your own PC at the moment. Um I sometimes like accidentally go through all these places and it's not there. So just like a menu of mine. >> Yeah. >> And the extra tricky thing there is that contract addresses are deterministic based on the deployer address and the deployer address is deterministic based on the pneumonic and everyone using hard hat is using the same pneumonic. So, just like we were able to go to Ether Scan and find that some poor people are using that address there that they shouldn't be using, you'll probably also find that some people sent some money to some of these contract addresses that they shouldn't have.

But you'll get if you if you tear down all of hard hat and you bring it up again and you deploy the first contract, the first contract's always going to have the same address. So, let's see. Yeah, there we go. >> Some some ETH here. >> There's even some ETH. There's $83 in that contract. >> Yes. Yes. So, you're right. So, this is the the first time that we deployed the contract was this one, right? So, the contract address was CF. So, if I stop this uh like the node and run it again and deploy it again, I should get like the same contract address. Also, yep.

Our balances all just got reset there because we used number zero to send 10% to number one a couple times and their balances changed, but when you took down the node and you brought it back up, it resets all of that stuff. >> Yeah. Cool. So, let's create like um contracts. Uh contract. Yeah. Contracts. Yes. And let's do like some interaction with our contract. Um so yeah let's use um let's do the contracts address and then take this one.

So just a recap what we did. Um so contract read right. So this is what we did yesterday to interact uh with a contract. We have like this this Sanford NFT contract in this address. It was deployed on on Winterbe and this is what we had to do to instantiate a contract in Ethers, right? We have to create like a new contract with the address, the AI, which is like this file that we created with all the with all the information and then the provider. But now since we are using um hard hat is easier than that. The same thing that we we just saw on the send e right like we we can get

the signer this way. So the same thing goes with with contracts. So you can do um let's call it um like greater right to the name of the and then let's agate the same thing we are using the hard hat ethers and it has like this get contract at function >> cool >> so so here you can just say the name which is greater greater and then the address. So this what it's going to do is like create this greater contract instance with the signer already on it. If we don't say anything, it's going to use

like the first like the first account or the SE account is going to use. So if you want to send like a like if you want to do like a write in this contract, if you want to call this set greeting, it's going to use the first signer the SE address. So first let's do like a read. Let's see. And then let's see what is here like the initial greeting. This is going to be greater. No sorry gr it was grit.

What do you think? >> All right, let's see if it works. I don't know about 50/50 on it. Where you at? >> 5050. Oh man, >> I think higher like 75. >> Thank you. Thank you. >> A lot of confidence. >> So it's going to basically go talk to the contract that's already been created and we get a greeting initial greeting. Is that what we deployed in the uh constru? >> I think in in the deploy script that is what you >> awesome.

>> Yes. Hello Harut is like the initial. Yes. Okay. >> So now let's uh let's change the greeting. Let's do like a set greeting transaction and it will be greater reset greeting and it takes uh this greeting string as a par. So let's do um I don't know it is working and then remember that this this will just wait until the transaction is sent to the memp pool. Um but let's wait until the transaction is mined.

Now by the way I I just read that hard hat has this by default it has this uh automind setting. So that mean that the network is like a stale but whenever the text that you are sending a transaction it just create a new a new block. So it's just waiting for you to send a transaction. But if you want if you want to mimic like rinkb or mainet or something you can also configure hard hat to be mining blocks like every 15 seconds for example. But in this case, it's just waiting. So whenever we do this, it's just going to mine our transaction. Okay, >> that's a good distinction to make. We could kind of didn't talk about that before. On any public network or on mainet Ethereum, there's just like a

periodic blocks are getting mined as fast as proof of work can find them, right? But locally, we don't have proof of work happening. were kind of just like but it's probably some kind of just like heavy-handed proof of stake validating the the transactions and so they just happen whenever they come through or you can set them to be periodic which makes it really weird like when you're checking for like timestamps and stuff because if you ask the block you if you ask the chain what the time stamp is not going to update until you make a transaction and force a new block.

>> Okay. So you see what what I'm doing. I'm just like setting I'm reading the the initial state of greeting. I'm just printing that out. I'm sending the transaction with a new message. And now after the transaction is mine, I'm just reading it again and see if the the value actually changed. >> And hopefully it says, is this working? Let's find out. Let's find out. >> Any any percentage for this? >> Oh man, I'm way higher now. Now that like we've got things working and we're kind of like iterating through it. I'm like 90%.

>> 90. Okay, let's go. >> Yeah. >> Okay, >> it is working. >> Working. >> Yes. Awesome. So, so we've spun up our own local node and we've deployed our own contract to it. And now we're writing scripts that let us talk to that contract through hard hat. basically reading from that contract some values and then putting in the transactions to write to those contracts. So we're kind of interfacing with our contract. And this is like what this is the kind of like development mode you get into.

Okay, I need to build this smart contract. I create it in hard hat. I write it out and then I kind of like write scripts to talk to it and then eventually you probably write some kind of like a test bank or some kind of test suite that tests against your contracts. Is that next or what? How are we doing? What's next from here? >> Yeah, I was thinking on Yeah, on testing. I think it's like the last part that we need from from hard hat. >> Cool. >> So maybe we can like run the test and then you know make a change on the contract and break the test and then fix the test or I don't know something cool something like that.

>> And what about deploying deploying our contract to like rinkabe or something like that? Is that something we would do through through hard hat? Yeah, because I mean like I said before like we are doing everything here seems like super local like development mode but hot actually actually let you deploy to mainet if you want and yeah like we can maybe we can explore that. Yeah, maybe we can like set up like this um this there is like a networks property here. So we can say like the maybe the rinkb network with with some provider and some pneummonic or private key and and deploy a contract to rinky.

We can maybe we can do that. But maybe >> let's try testing first. Let's see how far we get with testing. Yeah, I feel like testing is a pretty critical thing and and one thing that hard hat excels at. >> Okay, so this is a for running test with hard hat. can just do uh MPX hard hat uh I think test that should work that's what it's going to do is just looking at the test folder and running all the tests that are here and we have like this sample test that was created for us when we created this sample project and we can we can read the the test right now. So you can see that what is doing is deploying the contract as we

did on the on the script. Then after the deploy happens is testing that the grid that the greeting is equal to hello world which is like the same string that we pass on the deploy and then it's it's actually doing like the same thing that we did here right on the on the contract script like we we just you know read the the initial greeting set a new greeting and then read the new greeting. But the thing here that we were testing this like manually right because we were like just checking on the on the console and say okay oh look look it is working but it is way better if we use like automated testing because you don't have to you know you don't have to just like trust your your eyes you you will see

here like okay this is working >> and this this kind of shows why they have that ephemeral network also because if you have like a a nice network that's going to stay up all the time locally and you're constantly deploying contracts to it and testing them. Like when your test includes deploying the whole set of contracts and then testing them, it makes sense to probably just have an ephemeral chain that comes up for that. You deploy everything, you test everything and then you tear it down. What we're what we were doing is we have a nice like local one that stays up and then we deployed it and then we kind of like copy pasted the address to it and then wrote some scripts that go and talk to that address. So >> I'm sorry. Sorry.

>> Go ahead. No, no, that was >> I was going to say that >> I think that we because we changed this local host. I think the test actually are using the >> local host. Yep. So, exactly. >> If if we remove this because I run the test and I was getting the calls here. So, if we don't want to mess with this uh with this local account, local network, >> we can probably just >> close that node, right? For now, we can just shut that node down and just run our tests against an ephemeral network that it'll spin up for us as we need it. >> Yes. But what I wanted to show is that if we have like the default network here and we run the test, it is actually like doing things in in our node. But if we

change this, it's going to use the hard hat network. So, as you see here, like nothing is happening here. >> Make sense? >> Yep. Makes sense to me. There's there's the hard hat node that we spun up and it's our own local blockchain and we can talk to it and we have all these accounts, but then there's this other ephemeral chain that it spins up just to run a set of tests and then it tears it down when it's done. Is that probably a good way to say it? >> Yes. Maybe I don't know, maybe let's see what happens if we do this. Maybe this will use the I don't know. Maybe this will use the this Yeah, >> it should, right? Yeah, it's going to use it.

>> Yep. >> Yeah. Okay. So I think it's just like important to make that that distinction between the local host and the hard hat networks. Okay. So what if let's let's break this this test right like this is why tests are useful right because if this is a very simple test a very simple contract but in mind that we want to expand or change this contract right so if we don't have like unit testing or this testing like we want to we will have to check like manually that everything is still working after the change but what if for example um okay let's what can we do um yeah Let's >> just set the greeting to something

static. So >> well, >> oh okay, you got it. >> I have something something better. Yeah. Yeah. Yeah. >> So let's say we have like this locked bull value here by default is true. So whenever someone is tries to to set the greeting, it's going to require like to be unlocked. >> Cool. >> So >> So then the test should fail because it's locked.

>> So what is happening? Can you like explain what this require does? But when when when you spot a require on your contract, what is that really doing? >> I feel like require is one of like the most important things in a smart contract. In Solidity, we have this thing called require that uh it kind of sounds like you're importing a package, right? When you require in JavaScript, you bring something in. But in this case, this is more like an assert. It's making sure that a specific logical condition is set. and and if it's not if it's not exactly how we want it to be, it will revert. So we're requiring that basically locked is false here, right?

We're requiring not locked. And if that condition is is false, then I mean if it's not set right, it will revert and the transaction will fail. But if locked is set to false, then it will continue on and it will work through the thing. So it's basically like an assert. >> It will be easier if I do this, right? Because maybe this was confusing. If I do like the other way around, if I say unlock, I think this this reads better, right? >> Yeah, I think so. I think it does. I think it does read a little bit better call >> because now it requires requires this to be unlocked, right?

>> Yep. >> And so if not unlocked, we are going to revert the transaction with this message. Okay. So now let's see. Okay. So we change this and so let's say before we deploy it let's test it right that's why we have uh test so we run our test and compiling and breaking yes so yeah so so you see wther return the new greeting once is changed and and it's saying reverted with rec string sorry this is locked Right? So we spotted like this um bug just because we have the test. Right? So what we need to

do now is just to fix the test. Right? So we first we'll go to the test and let's copy this this thing. And so we'll probably want to have the use case for that change that we made. So s reert if the contract is unlocked is uh locked right or maybe is not locked up. Okay. So we can do this. Uh so greater contract this is getting deployed and then let's change this and then well let's try to

to send this transaction which should re right and with this hard hat waffle you have this I think it is um um you can grab this you can say expect this I think it's >> and it's Mocha, isn't it? If you wanted to know where you're finding this expect and this to be reverted, is that waffle or mocha or where would we look that up if we wanted to go find the docs? >> Uh, I think yeah, it's a bit messy because I think it's a mix a mix of of waffle, mocha, and chai. It's like the like the like the three libraries that we are using.

>> So, chai one. I forgot to say chai. Chai. I think chai is the one that provides like the expect >> and actually I think this is >> yeah I think if you google waffle and then chai matchers or chai with waffle you're going to get all of this expect to be within expect to be close to expect to be greater than that kind of stuff. >> Yes. So I think this test should pass right like we are just checking that the lock is working because we are saying okay if we try to to set the greeting we expect it to be reverted right so that should be working I mean we we still have like to make this test work but let's let's check

>> sounds good let's see yeah I remember when I was writing my own orchestration software was particularly hard to like catch the fact that it was reverting because it wanted to really throw like we want it to revert and we want to check that it reverts and we want to keep running. So that was a trick but it worked perfectly here. >> Yeah. Like that also happened to me and sometimes it's because you do this like you have the await here like inside. >> Yeah. So the promise doesn't get to the expect and it doesn't know to try catch it and it actually throws in there.

Yeah. >> Okay. So now this is working but I guess that we need a way to to flip of toggle >> to unlock it. Yeah. Yeah, we need a new function in our contract. Yeah. >> Yeah. So, let let's do a new function called like >> we're writing solidity. Anan, welcome. Here we go. The third week, we're going to write so much solidity. It's going to be awesome. You you'll get all the solidity you can handle. But at first, here we go. >> I think something like this should work, right?

>> Yeah. It looks like it toggles it and anyone can call it like very very Yeah, there's no no defenses here. Anyone can lock it and unlock it. Here we go. >> Yeah, we will probably take a look at this ownable like ownable interface that we can use here for you know with some function with I think they are called like modifiers something like that. >> So you can do something like this you know and then >> this get called like before the function and if you are the owner you won't be able to run this function and it will revert right?

>> Yep. we will inherit uh an ownable pattern from someone else and then it will have a variable that tracks the owner and then it will make sure using a modifier that the owner is someone else but we'll get into that later. Let's just make sure this thing does what we need it to do. >> Yeah, but for now like welcome to the anarchy like everyone can >> Yeah, anyone can unlock. Okay. So now maybe we can test well also something I I want to mention is that h in this case like we are going to deploy the contract like every time right because we are going to write like over and over. Maybe is there a way to to to save these three lines and there is there is a way to do that. You can like

inside the describe you can do I think you have before and before each. I think you have like these two u functions. H before it just write like before all the tests once and before each it runs before every every test right so we are going to copy this um let's copy this deploy functionality here we probably want a variable here okay yes we need this to be a sync Okay. So, is this clear? What what is this doing? Uh, this is >> now you have that lowercase greeter

variable available. It runs before before it does line 12, it runs through your before each and then before it does line 16, it runs through your before each >> and it sets up that greeter variable for you. >> And if you do this, if you use before instead, >> it won't run before 16. It will only run before 12 >> only once. that probably in some cases you might want to do that but in this case like let's deploy a new instance for for every for every test. Okay. So so soon return the new greeting once it changed and let's add here and it is unlocked right.

Okay. So now uh okay we can leave this as it is. But up here we need to run or to send this unlock transaction. So let's say greater and it is remember locked and let's wait for this and I think this should be the same right like now the the contract is unlocked and then we can now call set greeting and this will work hopefully.

Hopefully. I'm like 60% sure on this one. There's a lot going on here. >> You like >> I'm more optimistic like I >> Thank you. Thank you. >> So much more confidence. >> Okay, let's see. Let's see. Compiling because we made some changes. >> Hey. All right. It's working. It's >> fast, too. So you could have a whole contract suite, right? You could have multiple contracts that all have to talk to each other. You orchestrate your whole system bringing some up. Often you're going to be interfacing with contracts that exist on mainnet. So you bring up some mocks

locally. Maybe you'll have a mock ERC20 that will represent some other ERC20 that's already deployed. You'll send that thing around. You'll run it through your whole system. You'll make sure all your tests work. Uh and and then uh what do you do? you deploy to uh to a test network, you'll you'll deploy to mainet. We we haven't talked about mainet forks yet. Maybe one little interesting thing while we're talking about all these different uh gu nodes and RPCs, you can actually use hard hat to take the current state of mainet and then just run it locally from then on. And so you could take something that already exists on mainet and you could do a mainet fork and then you could deploy your stuff but just locally but to a fork of mainet

that's stored locally which is really really interesting and fun and a fun way to test things. Just getting that out there knowing that it's there eventually you won't want to mess with it right away but mainet forking is also a really cool thing. >> Yep. >> So what have we covered? Have we covered everything? What would it take to if we wanted to put this greeter just if we wanted to yolo it to to rink a bee or something like that? What what are the last >> Let's go. Let's go. Let's go for it. Let's go for it. >> Should we? Okay. Maybe if we can get it done in 10 minutes, we might as well do it. If it goes longer than that, maybe we'll save it for next week. >> So, something that you might want to look at is the the configuration file of

of hard hat. So you have this a bunch of things here uh that you can read the documentation if you want to go deeper but we are going to take a look at this networks property. So whenever you run uh a script with this MPX hat run and then the script and then you we say like dash network whatever is taking all the information from here like from from from for local host I think it is here maybe yeah look at this like this is like the default network object on the hard hat and we all don't have that but by default it has this and then also get the signers by by default but imagine that we want to um use winkke for

example let's try to deploy our contract to winky so we will need to go to the to the hardhat config file and then add a network networks and then rink >> and there's even the private keys that come with it. This is going to be interesting here because we're going to almost need to create a deployer account that's separate from the other accounts. >> Okay, let's we we had some here, right? providers. from Oh, mainet. No, what is what you do?

>> I think we had like a private key in our end file as well, right? We can use that. >> Oh, yeah. Yeah. Yeah, that's true. Yeah. So, let let's copy this here. So, the URL is going to be this one. But we don't have the Let's start real quick the the M package. Remember that we use this for like getting this this to work. >> And just tripling down on what we're doing here. We have a bunch of local accounts for hard hat and if we try to use one of those local accounts to deploy those local accounts have the private keys exposed. So as we load them up with rinkabe to be able to do the deployment someone could technically get in and steal our rinkabe. So you don't want to use those local accounts. You

want to generate a new account and have it in yourv file and make sure yourv file is get ignored and you want to have that private key come in there and we'll fund it and then we'll use it to deploy. That is makes sense because this this account I mean this is the the provider remember that we had this util file on on like yesterday and we use like this urls to connect into provider. So this is the way that you tell hardhat when you use the rinkb network what provider do you want to use and for signers you can use this account property and you can set the private key directly here and I think you can also have aneimmonics right so you can have

like anneeimmonic and then have having like multiple accounts but since we since we already have this if you remember from yesterday we have like this variables already set so what I'm going to do is copy hopefully doesn't get Okay, let's see what happens. >> We're probably going to expose something here. >> Yeah, I mean it's fine. >> That's I mean if we just create a brand new one maybe and then fund it. >> No, but I mean it doesn't I mean this this already I mean doesn't have any value I think. I mean we >> Okay. >> Yeah. Let's let's >> you at home be very very very very very very careful about copy pasting around private keys and having them in their your local like I would say that like one out of four developers I've worked

with at some point has accidentally pushed a private key to GitHub and lost like thousands of dollars. So don't don't don't do this. like be very very careful and very aware of what >> private keys you have where and if they're dev accounts or real accounts and make sure it's in the get ignore. >> Okay, so let let me test this real real quick. The balance let's say let let's get ser let me see if this works.

So where will these are hot signers? I think okay I think we can do that. Let's paste this. I'm just trying to see if uh if it works incorrectly. I'm going to this would be let's call it signer. So if I call this script with hard hat run, >> is it going to be the zero account or is it going to load our new account that we have from our environment? We'll find out.

>> I think we need if we no bal if we do this network if we do this is going to use let's check it. This will be like the like the hard hat uh config, right? So this is like the 10,000 E. Yeah, like with Samsung. But if we do rink, that's why we configure this network here. >> It's gonna select the network and then it should hopefully use our account from our environment >> like like the number. >> Neat. >> Yeah, I think we I have it here. And it's the So, let's see. It's It's I think it's this one. I think >> if you want to copy paste that to chat, I can send you some rinkabe.

>> I probably have some. >> Okay. Yeah. Oh yeah. Like we have been like using like some defet before. So >> So let's see if we do this. We hopefully we will. >> And did you bring that in through the environment variable or it was already in this folder somewhere? I feel like I never saw you bring the private key in but maybe you did it off screen. >> No, no, I did it here by very carefully like I just like copy these two files here from from the day two to the day three and then >> without clicking them to show them. >> Yes. >> Okay. Cool. Got it.

So let's see. So this should be connecting to yes working >> great. >> So we are connecting. So so we are using like hard hat for all like local development. But as you can see we can also connect to rinkb or mainet or whatever. So hardhat is not only for for local development. Okay. So now I think if we want to deploy that contract, it's just going to be MPX hard run scripts deploy and then network, right?

>> And what's the deploy script have in it? Can we look at the deploy script real quick before we fire it off? >> It just loads up the greeter and deploys it with hello hard hat. Should we say hello rinkabe? Should we change our greeter to be Yeah, >> because it's going to be on rinkabe. It's going to be on a public network. Now, >> ooh, one other thing. >> When you go to a public network, I don't think you want the console log stuff there anymore. I don't think the console log stuff works in a public network. So, you probably want to carve that out of your contracts as you start going public.

>> Yep. Oh man, you just deleted it, too. I just would comment it. It's gone. Carlos says no more. No more consults. So, should we should we go for it? >> Let's go for it. Yeah. I like that we just like wildly change our contract and then ship it to Rinkabe. >> Yeah, it's compiling because we made like this change. >> And just to dive into that, there's just like a lot of more overhead that comes with that console log. There's all these different u uh overrides. It worked. We deployed a contract. We should be able to go to a disinterested third party ether scan. We go to rinkabe ether scan and paste in that address. Is it a

contract? >> Uh it hasn't found it yet. Give it a second. >> Our our node's faster than their node. They they have a lot of indexing. >> Contract. Yep. >> And can we look at the contract code? We should be able to see the bite code of the contract and we should see that it's not verified yet. Right. This is what everybody sees. This is our contract right there. Yeah, like actually it's start with 60 80, right? And then if we go to the artifacts, it should be the same, right? Should be the same. >> I think all contracts start with that.

>> Okay, then. Yeah. >> Yep. Yep. But down the line, it's more stuff. Yeah. >> Yeah. Yeah. It ends of 33, I know. >> Yep. >> So, yeah. I mean, the next step will be to verify the contract, but maybe it's too late for that. Well, can we run a script against it? Can we go set We can run our tests, I think. Right. Our test bank will run against But our test is set up to say hello rinkabye, not hello or hello hard. >> No, but that that's that's perfect because then that will break, right? So, if we do this test, >> no, let's do MPX hard uh test then network.

>> It should fail on us, right? It's a fake. Yes, >> it And is it going to deploy? I don't even know what it's going to do here. It's going to deploy as the hard hat account. >> Yeah, that's true. >> I think it is right. Which like somehow works because they keep it loaded up on hard hat. Like I don't know like that account shouldn't really it's bad practice to be using an exposed private key to deploy a contract on a public network. >> Yeah. But most of the time people just run the command like you just did and they don't even realize what's going on under there, right?

>> Yeah. Like probably like if you want to do to run test against like winkb or mainet, >> you will probably won't do this. Like you use like the get contract at and then you will paste the address, right? And uh >> this there's sort of like this idea of I'm deploying locally and we're even like bringing up our own chain and deploying everything there and then shutting off the chain. It's very ephemeral, but as soon as you put a contract out on a public network, that artifact becomes very important and very solid and and you're more often going to write a test bank that goes against that specific contract, not you know, orchestrate the whole thing and test it.

>> And just maybe we won't do it today, but just wanted to point to this hard hat scan plug-in, which is what you can use to verify your contract. So it just you just like install this plug-in and add it to your hot hat config and then I think you just have to get an ether scan API and put it here and then I think it's like a command like a yeah like verify command the network and that will verify your your contract >> and you can do it manually too. You can just go to ether scan and you go to the contract and say verify and you just paste in the source code and tell it what the compiler version is and it should get the exact bite code compiled.

>> All right, >> I think we did it right. >> Yeah, go ahead. >> Just just to add note on the verify. So like when you verify the contract like it will show the contract code on that ether scan interface. So like you will have like a green tick and like you can see the actual like solidity code. So just like as we were seeing before in the die contract >> and security through obscurity does not work on a public blockchain. So just because we have this cool greeter and it's packed into bite code and no one can really tell what's going on there, people can decompile that bite code there. There uh there are lots of ways that people can hammer and steal from your contract. So don't think that like

you'll obiscate it by not verifying it. You almost want to verify any contract that anybody's ever going to use just so that source code is out there and everyone knows about it and everyone can even use Etherscan to interface with your contract if if everything else is down. >> Yeah. And the same thing with H with this private h properties. >> It's not really private. That's a great point. Yes. >> Yeah. Yeah. Like maybe you can think, oh, so no one can access to to this viable because it's private, but that is not the case. like there is like a I think you can even do that with ethers you have like get storage at zero something like that and it will get like the value of the first variable so yeah so this is just if you want to hide it from other contracts I think or but but

you are inheriting from it yeah if someone were to inherit the greeter the the parent wouldn't be or the child wouldn't be able to use that that variable basically >> awesome so much cool stuff we started tinkering with solidity here we showed you how to spin up a GU node and talk to the network. Then we brought up hard hat and showed how all that local orchestration works and how we have some really cool tools these days that let us build and test and orchestrate smart contracts. Uh, great work, Carlos. Thank you for being here. We're all sick. I I'm Thank you, Eda. Thank you, Carlos, for being here. I need a drink, too. Any closing thoughts here? Hard hat day was a success.

>> Yes. Yeah, just a reminder. So, I do still have the get node up and running. So, we did find another pier. So, like >> nice. >> Now, two peers. Two. >> Two peers. Goodness. >> Let's let's just look at that one moment. >> Yeah, I think um >> and you're just getting blocks one at a time. Now, that's that's what a good node looks like when you're just getting one one node at a time >> or one block at a time. Yep. I think that Huh.

>> There's a viewer connecting. Yep. >> Yeah. So, like you can see all the blogs I'm getting. Um, and yeah, just closing. >> It's running. >> Cool. It's awesome. Great. All right. Hard hat day was a success. Thank you for coming. Thank you, Eda and Carlos, for working through it even though we're all sick. Uh, hearts, hearts, hearts. See you guys. >> Thank you. Bye. Bye.

Related talks