👩‍💻 Web2 to Web3 🚀 - Week 2, Day 2: Reading and Writing to Contracts with Ethers.js

Web2 to Web3 Curriculum · 15 Aug 2025 · 1:40:37

Austin Griffith, Eda and Carlos continue the scripting week of the Web2 to Web3 curriculum with smart contract interactions in ethers.js. Carlos builds reusable utility files, shows how to keep private keys out of code, then reads from a deployed contract using an ABI found through Etherscan. The group writes to a contract with a signer, sends value through payable functions, crafts transactions from raw calldata, and finally sends mainnet DAI, with the key lesson that every contract call is a transaction.

Speakers

Topics

From Web2 to Web3 Curriculum, hosted by BuidlGuidl.

Transcript

Here we go. Oh, what's up? I'm Austin. I'm here with Eda and Carlos. We're on day two of week two. We're in in the midst of the scripts. We're we're scripting lots of stuff and we're learning about providers and signers and dealing with uh pneumonic files and loading those up into scripts and scripting your even contract interactions. Today is about scripting interactions with smart contracts. And we're we're gonna learn that like everything is a transaction. Like it's all about just like that call data, right? If you want to talk to a contract, it's not like you're going out and poking an app. You're crafting a transaction and you're sending that transaction and that transaction ends up poking the contract when it gets mined

into the block. So here we go, Carlos. So I I want to get my stack going locally so I can follow along with you. But I think yeah, you you kick us off and tell us how to get started and uh I'll follow along on my machine, too, and jump in. >> Okay. >> I'm going to follow along, too. I'm >> All right. >> Yeah, I'm learning a lot. >> We might we might switch at some point. >> Yeah. Sounds good. Sounds good. >> Okay. Let me sh >> Okay. Can you see? Can you see? We've got the the sea meeting the the land >> and we've got Sanford and Vitalics balance >> Firefox. Okay, perfect. Okay, so this is uh what we have so far from from

yesterday. Uh we created like this providers file and wallets file where where we did like some you know like some calls and some testing. The only thing that I did off camera was like putting these files into the day one folder because we are going to create like day two folder today. So that's the only thing that I did and also I did g in it. So I initialize a g project and um did like a commit with the with the stuff that we that we have you know I I just did like g commit.

>> Is that pushed up live? Could we grab that too or is it's not live. Okay cool. It's not I mean we can create >> it will be it will be for you watching at home like the person watching at home will be able to easily fork this stuff but we're going to have to do it live as we go and try to follow along with you which is cool >> if not you know we can create you know myth call we can just create a repo and push this to it and then we can switch and someone can just pull my code and and keep going. So, we'll see. We'll see how how >> Okay. So, I think um a good way to start might be to do a bit of a a recap from what we did yesterday. Um and I was thinking like we are going to use these

providers, wallets and signers like all the way like this week, you know. Yeah. >> So much. So maybe we can create like some kind of utils file where we set up all the provider and signer and wallet stuff and we will just import that from other scripts right so it's going to be easy so we don't need to instantiate the wallet like every time that we need to use it right so >> basically I have I have like 30 projects on my local machine and all 30 projects basically have a local pneumonic file that I've generated just for that project. It loads that local pneumonic into a wallet. I send some money to it and then I code up some interaction, right? And so you're saying, let's have

that as a utility file. So it just like does all that stuff for us and and we can get started writing the the guts and the important stuff, the contract interactions we want to use. >> Yep. >> Awesome. Okay. So, let's create first like the day two folder and let's create the utils. Yes file. Okay. So um I think let's import either.

>> They have to bring in ethers, I bet. >> Yeah. Every script starts with importing ethers. Got it. >> Okay. So the the first thing that we saw yesterday was um providers, right? So let's create um get provider function. Um let's see what we did yesterday. Okay. So here we have the infura on wallets. I think we also Oh yeah, remember that we did like we were instantiating two providers like mainet and rinky because we had this issue that we were trying to use the rinky provider to get the ENS and it wasn't working.

>> So yeah, let's see what if we on this utils let's let's have this uh a mainet flag here default to false. So we can request a provider and say get provider and if you leave the default it will get the rinky provider. Um usually when I set the default for a function I I usually try to do like the least like destructive uh way you know. So if you get a provider if you don't say anything it's going to get like the rinkb provider and if you want to to get the mainet you will say get provider true you know. So that will get you the mainet provider. So this should be something like um provider URL and if

mainet we're going to use this like turnary operator okay it is mainet we are going to use this sorry and if not we're going to use the winky v1 okay and Now we are going to return the a new this was ethers uh pro providers. Yes.

Okay. Does this make sense to you? What do you think? Yeah. >> Yep. Sounds good. >> So the idea here is just to do let's let's test this function. Um so we can do >> just get the block number or something, right? Just make sure we're talking to it. Yep. So this will be um uh provider and we can do um this I think it was provider get network. Yeah.

Okay. So we run it day two. Oh let's Okay. Okay. This was happening yesterday. Remember that we always forget to import the like the M config. So if you don't if you don't do that, I mean if you got to get that in.

>> Yes. Because if not, this is going to be null and it's not going to work. Okay. >> And and if you don't bring in the end, just real quick, if you're not using an environment file file, you're probably copy pasting pneumonics or private keys right into your code. And that's a really really easy way to get it accidentally published to GitHub. Even having it as an ENV file is is a little scary and you should only have like either testn net e or this is an actual mainet script so it has mainet eth and it's in like a very special place. But like that env file, if it gets committed to GitHub, your money's all gone. So you have to be very careful to have it in an env file and have that env file get ignored. And it's almost like that's the

first thing you should do before you do anything. Bring in the ENV file and ignore the ENV file and then make sure you're solid. Do not commit that thing to GitHub or you will get wrecked. >> Yes. Yeah. If you remember from yesterday, we created this get ignore file and we are ignoring the node modules and also the com file. Um, so let's see why it's not working. Uh, okay. Why is this happening? >> I think it's it's up above the get like the day two file is inside of that directory, but the env file is one one directory above.

>> Okay. But I thought that it was like getting there. It doesn't do that. >> I don't know. Let >> because you're in the day two. I bet if you copy paste that EMV file into your >> No, I think I think it's not the file, but it's that I'm in the in the day two. >> It's where you are. Yeah. >> So, I think if I run it from here, I think it's going to work. >> Yeah. >> Yeah. >> YouTube. Well, I'm not going to print the infur. >> No. >> Okay. Let's see now. >> Boom. You got it. Okay. Okay. Cool. So, so I just like >> printed the get network and if I pass this is a rinkb and chain ID is number four. So if I say true, so is mainet equals to true. I should get the

homestead. Yes. Send ID one homestead. Okay. So this is working. Cool. Um so what we did yesterday after providers was h creating a new wallet, right? So let's have u generate wallet new wallet function. Uh then let's copy I think this should be fine.

>> So do you remember this that we were like >> create random create on ether? Yep. Yep. And and honestly, you could you could generate your own private key, right? If you want to come up with your own 64 character hexadesimal private key, and as long as it's really good and random, you could do that, too. But I bet Rick Moo does some special stuff with create random where he's using a lot of weird randomness just to be safe. >> Yes. So yeah like we could like store this on on a file on txt file or whatever but for now we are just like going to print uh this on the console. So let's see now.

[Music] Okay. So maybe we can use like this private key today like a can you for our So let's >> let's do it where it like generates the private key but doesn't show doesn't expose the private key to the to the screen. So let's do it where you're actually going to create a brand new account and we'll fund it but we shouldn't expose it to the camera if we do it correctly >> just to go through those motions because it's a good exercise. >> Okay. So what do you want like doing like this? comment out the private key and pneumonic and then let's write the pneumonic to a file, right? That like that's what would be in thev file.

>> Yes. >> Is that right? Is that how we would do it? So you want to generate one, but you want to like can you write to the EMV file? That's probably not part of thev stuff. You probably just need to copy and paste it. >> So you'll generate it and then offscreen copy paste it into the EMV file. Is that how we're going to do it? >> Yeah, I'm going to do it. >> It's kind of weird. Sorry. Sorry. It's a weird uh like >> No, no. I think it's a good exercise because you know >> Yeah, a good exercise >> because it's not good to share this stuff while you are like broadcasting to to people. >> So let's So let's do that. I'm going to paste. Okay.

Going to have this private key. hiding a private key. All right. >> Wait, wait a minute. >> It didn't come up. No worries. Didn't see anything. >> Okay. Okay. You're good. Okay. So, this so this is the the my address like the new address. So, we can find this address. And if you remember on this m example file, we have my wallet private key. So I just copy paste my new generated private key here on my M file right. So

>> cool >> actually I'm going to if you remember I we imported like a new uh okay some music pleaseickity >> I always do that now it's so funny running distraction when someone passes types in their password. >> So let's import Oops. Where was that? Okay. So, let's import this one. So, it's like D3. >> There we go. Okay. >> And we haven't exposed that private key yet, right? Like that's a that's a good one. Okay. Cool.

>> So, D3. Okay. So, this is the one. Nice. Okay. So, this is working. Okay. So, the last thing that we want to do in this huts file is creating a get ser. [Music] We're going to do the same thing the mainet flat. It's get singer which is also like I don't know how good of a voice do you have. >> Sorry >> my spelling is so bad. Okay. So here since we have the if you remember we have the for the serer we had to we need like a provider right and we need we needed our private key and

also the the provider right. So let's copy this stuff and okay so this is already populated because I just like um populate this M variable but we need the provider. So what we can do is uh get the provider from the function that we just created and pass along this flag and then this will be provider. Make sense?

Yes, >> I think we can remove this. So, let's return. Yeah. So we can singer get signer and then what can we do with the with the signer like get get balance or get uh address maybe.

Yeah. Okay. So let's see. Yeah. >> Yep. Like the D3, right? It's the same the same that we had on the on our wallet. >> Okay. >> So, when we get the signer, it connects to the mainet provider. Is that what's going on right now? Oh, depending on >> Yes. So, the default is connecting to Rinky. But if you want to connect to to mainet, >> you put true in there and then you've got a mainet signer. Okay, cool. >> And the good thing is that we can do this. So we can have like we did yesterday, we can have a provider connected to mainet and a signer connected to rinky. So we can use the provider to get in like some like ENS data for example and our signer to make a transaction in ring.

>> Awesome. >> That's great. Okay. >> Yep. It's really good to show that distinction between what a serer and a provider is and how those two things are kind of mutually exclusive, but you can connect at any time you can connect your serer to different providers and have that like wallet basically signing transactions on those different networks and it's all the same. It's all the same like it's all EVM compatible. So, it's going to be the same across all these networks whether it's a test net or an L2 or or Ethereum. There's just like a little chain ID difference between one one network and the next and speed. I mean there's a lot of differences in in census and stuff, but from our point of view, it all works the same.

>> Yep. >> So, I had a question at this point. I always think of the signer like the the authentication piece. I don't know if that's the correct way to like express it, but like it's what like you like your address. You sign the transaction with your address. You can tell who it is. Um, so that's like an easy way for me to like distinguish provider and serer. >> Yep. Yeah. Signer is like your private key that you've generated, right? And it and it can take that private key and sign things with it, but it's really like very isolated, right? And the provider is like your connection to some network. And so you want to connect to a network to get information, do some signing over here, and then ship it off

to that network to to send it to get mined. I think that's a good way to think about it. >> Yep. Okay. So, if we want to use these uh functions in in other scripts, what we need to do is to export this function. So, we can import it from from other scripts. So to do that, remember that we are using ES6 module syntax. So, this is the way to import it to export it. It's just like a export and an object and we can have all of our functions here.

>> And we had to add the module thing to the package JSON. That's what unlocked this stuff. >> Yes, >> right there. >> You have to do that or you can also name the file mgs with the extension mgs if you want. But if you want to enable for the whole project, it's better just to to write this line here. Okay. So, okay. So, this should be ready. Uh what if we at the end of yesterday we send it a transaction, right? We send like some some E from our address to to some for remember.

So, let's do the same thing but using the utils that we that we just created. So I'm going to create a new u file called state send is >> did you drop the utils file to us so we could just copy paste it while we're doing this live so so we don't have to code I like I wrote like half of it but I didn't get it all like specifically like the the infura endpoint I didn't get typed up correctly but if you could just yolo it to the chat somewhere where we could grab it just so we have a live version of sent.

>> Dope. Thanks, dude. Okay. >> Okay. >> LFG. >> Let's go. Okay. So, now um on the send e script um let's paste what we did uh yesterday. Uh okay. So if you remember what we did is uh just getting in the Sanford address from their ENS and then with our signer send the transaction with the with our balance actually I didn't copy yeah our

balance here >> balance divided by 10 like 10% of the balance right yes >> okay so you see winky provider so now the good thing is We can we can do winkb provider and this is going to be get provider and >> oh what it just like magically imported that for you. How did you do that? >> I don't know. My ID I think >> your ID has something neat. Oh man, I'm jealous. >> So now we also need a signer, right? Uh so we can do a rink be well we want this to be the mainet provider right

and we want a rink uh mainet provider and a rinkb serer get signer okay so my balance I think this should be SER no we can be serv >> do we need to await the get provider and get ser is there no async await happening there >> yeah I think that there's no need >> uh because actually when you I think when you create a provider >> h it actually >> oh yeah there's no async there's no call back yeah okay looks good >> I think let me okay yes my balance some for main provider okay sending it to some

And this is going to be ring signer my balance. Okay. So I think like we will need to fund this address, right? Because we don't have any ring on it. So let's do that. Um >> and that's like to pay for the first gas fee to send and obviously the rinkabe to send as well. >> Yes. So, let's grab this address and search for ringp. >> And just like kind of a disclaimer here, be careful about creating pneumonics in your file system and then having an address or a private key that you paste into MetaMask because now you've got this account that

lives in MetaMask and this like private key that's on your system and if somehow that leaked, you didn't know it and then your MetaMask has it. Just just be careful. You almost want to have a developer metam mask where you're only putting in private keys into this meta mask that like you know clearly is not like for production stuff. Just just a disclaimer. We we kind of copy pasted private keys around a little bit there and it's a little bit scary and messy to have that in MetaMask. Although it like lets us do a lot of neat things like he's doing where he's like getting his address out of MetaMask and probably using it to send stuff if he needs to.

>> Yeah. Yeah, I mean these are all like test accounts. That's probably why why I'm so so so wild with it. >> So, can any of you like send me some in here because >> I can send it if you paste me that address into our chat? I can send you some. And yeah, so if you're at home and you're having a problem with one rinkabe faucet, go Google rinkabe faucet. There's probably a bunch more. But since we're kind of in a hurry here, I'll send just some from my rinkabe stash. But uh yeah, get getting test net stuff is just kind of uh a challenge in the first place just because you have, you know, a network that's like Ethereum but not

nearly as secure as Ethereum, right? So these test nets can get attacked and fall over and just have issues. So sometimes these faucets go down because they get attacked also. Okay, I'm sending you some Oh man, my MetaMask is so slow. I'm sending as soon as as soon as MetaMask starts responding. Here we go. So let's >> Okay, it is incoming. So, 15 seconds, it should be there.

>> Okay, so in the meantime, let's >> five. >> Thank you. So, I have 800 of them. [Music] Okay. Um, so let's um utils. No, what I'm doing wrong. >> Oh, >> what are we trying to get? >> Oh, you want to Oh, yeah. You didn't bring in ethers. So, and remember it's format ether is what we're going for, right? Utils. Format. Okay. We got to be careful. There's two different utils now, right? We've got utils as in our file and then utils as in this like selector with ether. Like those things are not related. Yeah.

>> Okay. I'm going to re return here because I only want to check first if I have the the balance. So let's let's see the two check this why. Okay. So like exit how was it in like process.exits, right? Something like that. Env yeah something like that. Yeah. Yeah. That's it. Yeah. Yeah. Okay. So, can you see like my balance is >> Yes.

>> Okay. Cool. >> So, now let's check if we got the surpet provider to do the lookup of the of the sout e. So, let's let's check my balance. Yes. And the and the s for address is resolved here. Nice. So the last thing is just to make the transaction, right?

Uh so we are going to use rinkb. So that's why I'm using the rinkb serer here and the send transaction command. And I'm going to send to the s for address. And the value is going to be my balance uh like the 10 10% of my balance, right? And remember that um when this is completed like after this await this means that the transaction has been sent to the me. And we actually I think um Austin I remember you telling me that the H is deterministic right like whenever you create like a new contract or create a new transaction like the transaction has is always deterministic right so you can because

of the nons that you can like derive always the has even if the transaction hasn't been mined yet right >> going back to the idea of like an air gra an airgapped laptop you can actually yeah craft the entire transaction and sign it and you'll know the transaction hash that will go into the mimool eventually without ever even broadcasting it. Yep. >> Okay. >> But at that point, I think it's coming back to us and it's already in the m pool. Right. Line 20 is blocking on it's not even blocked on. Line 15 is blocked on does this thing get to the mimpool and then line 22 is blocked on did that thing get mined into the chain. Yeah.

>> Yep. >> Cool. >> So, should we should we go for it? Go for it. Yes. >> Okay. Okay. Okay. Okay. Send is Let's see. >> So, it's >> our balance for address and we can we have the >> now it's getting mined. Yep. So, it's in the minimool. So, now this is the 15-second block time we're waiting on rinkabe. >> And we can just like copy and paste this h into scan, right? And then >> y it' be rinkabe. Ether scan.

>> Yes. >> Yep. >> And then I can paste here the hash. Oh, it's already succeeded. So, let's see here. >> Yeah, mine >> transaction mind. >> Um, >> and so can we look at this? So, it's from our account, our D37 account. And that's the pneumonic pneumonic that you just created locally. And it's going to 8894 and that's Sanford. Okay. >> Yep. >> And then, yeah, we say like 10% 10%, right? >> Yep. Yep. Cool. >> So, it works.

>> And if you hit up and enter again, it's gonna do the same thing and it's going to be 10% of its balance, but it's going to be less now, right? It'll be like point >> 49 or something like that. Yeah. Yeah. >> 49. >> Cool. >> So, let's copy this one. >> And this is the cool thing. It's like programmable money, right? Like now it's scripted and it will do what it's supposed to do over and over again. So, this little script could just sit here and run and do what it needs to do. Very cool. And you can like listen to events and run this code whenever you want or you can like set up a chron and and run this like every hour. It's up to you. So that's that's the good thing about like interacting with the smart contracts and the Ethereum blockchain with the

scripts, right? In instead of like doing manually as we were doing like the first week, this is all programmable and dynamic which is great. >> Awesome stuff. >> Okay, cool. >> I just got so mine mine didn't have things installed. I had to do the mpm install environment npm install ethers. Then I had to edit the package json to add the uh module type and now it's all working. So I've got the same utils going on over here. Is it is it time to talk to some smart contracts? Is that what's next? We're sending heat. Sure. We're sending heat. That's easy. >> Let's let's make some real transactions now.

>> Yes. Yes. >> Let's do that. So I was thinking first let's read something from a contract right so first we can read something and then we can like write or or send like a right transaction to a contract so I was thinking that maybe we can use the San forest out NFT that we created last week you know so we can like do some some testing there so let's create a new a new file this is going to be day two and let's call it like contract the read.

Yes. Okay. Um >> and we'll bring in ethers and we'll bring in >> Yes. >> file >> like always. Yes. The first thing is always like importing ethers. Yeah. >> From ethers. >> Okay. So now I wanted to show the like the heers documentation for yeah the contract instance. Uh so this is yes. So if you want to I mean there are like a few ways to interact with with a contract but is like this is like the the quickest way to go about it

like creating a contract instance in either and then you will have like all the utils for that contract and you can call the functions directly. But I think maybe it would be nice to show maybe when we do like the right transaction like showing how to interact with the contract without this and just like with the raw send transaction and the cal data that's >> I think that if we do a contract interaction and we get on to ether scan and we see it we're going to see like oh wait like interacting with a contract is just a transaction and how does it know how to do it? It's this call data and we'll look through the call data. Yeah.

Sorry, I didn't mean to interrupt. I think that that's the way to go, though. Yeah. Yeah. We want to see that eventually. Right now, it's like, what the heck is this AI and how does that how does that work? Yeah, >> because if we copy and paste this uh Okay, so I think we we know most of this stuff, right? I mean, we know what a contract address is and we know what a signer or provider is, right? But we don't know what an API is for now. So, let's let's start with um with the address, right? Let's call it like a Samford uh Sam for NFT address, right? And then we have this Sanford NFT API that we don't know what that is yet.

And then >> but you're going to learn. >> Yes. And then SER or provider like any idea why we do want to use like a ser or a provider here? You know what would be the difference? >> I would say that if you were on like an airgapped machine and you wanted to sign a a transaction going to the contract but not send it through the provider. Or if you were just reading that that would be you could use a ser. But if you're just reading something you could technically just put in a provider here and it's basically a readonly connection to that. So it's like assigner could be a writeonly connection to the contract where you're writing a contract and setting it up offchain and then putting it in somewhere else or a readonly connection you're just reading balances and stuff like that. Or you could have a

signer that's connected to a provider and put that in and then it's basically a write connection to that uh uh contract. I think that's the way it is but it's like maybe >> Yeah. No, I think so. >> Is that right? Yeah. >> Yeah, I think so. So in this case this is called contract read. So we are going only to read data. So we are going to use a provider. So it's going to be ring because we like the sour uh NFT is deployed on rinkab. So rinkb provider and this is uh going to be just get provider by default is rinkb and this will be here. Okay.

So now what we need is to find the some for FD address and this happens to me like all the time that I always where where the where is the contract right because I deploy it and I forgot about it. So sometimes I have to um u I have to search in in scan where the contract is. So if you remember like um last week Samford bought some NFTs right from from this contract. So what I will do is go to Sanford Sam for stout >> about to do some blockchain detective stuff is what this is all about right we're gonna we know that there's this one account that interacted with this.

So we're going to go to the account and then look through their transactions and see if we can find this address. Is that what we're doing? >> I think Yeah. Yeah. because I think this is important to show because I'm always doing this, you know, so I forgot where so >> so I'm going to go to the Sanford address, but this is mainet, right? So we can click on the B here and go to RinkB. So this is the Samford Rink account. And you can see here that that the NFT that they minted last week and if we check like the history, we'll check that owner mint. This is the function that we called. So we can just click on the transaction and we will see that we interacted with this contract.

So we found it. >> Yeah, we found it. So here's the contract and here's the contract and here is the address that you can just copy here from the URL or or maybe just like here. So we got it. So we are going to paste the address here. So >> So we know what contract we want to interact with. But now is the real heart of this whole ABI learning experience, right? We need to know what functions we can call on the contract and what arguments go with those functions and that's where this ABI is going to come in. It's going to tell us how we can interact with the contract.

>> Yes. Yeah. I think it's actually an interface just um transforming like data to byte code, right? Because the EVM only understand byte code, right? we only the only way to interact with the EVM is with bite code. So we don't I mean we will see later that we can provide the the call data like the the actual like hex digits but I think uh in this case is easier to go with the API and when you have a contract verified on chain like this one you can find the AI down here after all the code you can find the AI here. So just to double down on that, if someone deploys a contract

and you go to Etherscan and you look at it, all you're going to see is bite code. You're going to see this mess of hexodimal characters that says this is what the contract is. And that's really hard because it's it's in it's uh it's compiled bite code, right? So what happens is someone will verify their contract. They'll say, "Hey, for this given bite code, here is the source code that you can compile to get the bite code." And then Etherscan puts the source code and the ABI up for us to make it available here. So once someone's verifies the contract on Etherscan, anybody else can get in and snag that ABI or look through the contract code. And really if you take all that contract contract code and you

compile it exactly like they did, you'll get exactly the same bite code and exactly the same AI. Etherscan just hosts it up and it makes it really nice for us because we can just get in here and copy paste it into our scripts and stuff as long as someone verifies it. >> Yes. Okay. So, let's let's I mean you can uh for example, let's say that we want to read the the mint price from the contract, right? So, it's here. So, we will just go to the API and copy only the mint price definition. So, we could only like copy this this part if we wanted.

>> Oh, wow. Yeah. >> So, I don't know. Maybe let's copy the whole file, right? >> Yeah. Yeah, I think so. It's just cleaner to just copy the whole file. >> Yeah. So, I'm just cop going to copy this. Um, and let's I'm going to create a folder. >> I think it's I think that's a way to go. Yep. >> Because this file is going to be big big, right? It would be nice to have this API stored somewhere where we can load it dynamically and it wouldn't mess up our or messy up our script. >> So it is Sanford um NFT API, right? >> Okay. Um so we want to export this also. So let's do something like con API and just paste this code. And

>> there it is. Yeah, I have like this Pier plugin on my on my IDE. So whenever I save it, it's going to format it for me, which is nice, you know. So you can see like the whole So it's basically like like the type definition of every function that you have on your contract. And since we imported because our contract is actually really small, right? We don't have so much stuff there. It's just like a, you know, like a couple of constant and a couple of functions. That's it. The the thing is that we are like importing in inheriting some stuff. Yeah, inheriting some stuff. So >> all the stuff that you are seeing on the API is also from there. Like for example like the what is like owner? No, not owner like the balance or owner. What is

the >> Yeah. Like the the balance of or even like the there's like an tokens of owner. There's like a bunch of functions that come in with the ERC 721 standard. >> Yes. And if if you see here for example the balance of function which is from the ERC 721 I think uh you have the inputs of that function the name of that function and the output of that function right so with this API ethers know how to interact with your with your contract so in our case >> it's kind of like an API right it's not not an API like a server but it's more like the the uh if someone like swagger I remember back in the day you would

take an API and you would export it and then you have all these nice docs about how to call your a your your backend service, right? This is like a definition that tells you how to call different functions on it. It's like here's the API for the contract but in it's called an API and and uh yeah, just think of it like an API though or or like think of it like an API definition like here are all the functions you can call and here are the arguments you call with each of those functions. >> Yep. So let's import this from here. We can do just like import um Sam for um NFT AI from this would be AI slash Sanford.

Okay. So now we have the API and we can just like paste it here. Right. So now we should have the the contract interface or the contract instance on ethers and when you have that you have remember like the address the API and the provider. So we can start making calls like in this case only with calls right because we are using a provider not a signer. So let's for example check the the mint price. I >> think you might need to pull out line six too. I see. Oh yeah. Yeah.

Thank you. Yeah. >> Yeah. >> So let's do this would be like some for contract and we want to call mint price, right? So we could uh some for some first. Okay. No, SS doesn't work. See, I was like some for a stout, but no, SS is not a good uh >> uh mint price and then we can remember that this is going to come as a big number right?

>> Let's paste it. Let's let's just output it though and let's let's let's run into that problem. Okay, let's, you know, print out the mint price. Let's see what happens. We should get a weird number, right? and and your your uh web three brain should know you're going to get some kind of weird big number here. But let's print it out and see it. >> Let's see if it works. No. >> Export. Oh. Oh, okay. Okay. So, I think >> I think we forgot to export it, right? >> Yeah. >> Yeah. So, let's do export default API. >> Boom. There it is. Big number.

>> So you at home, if you have a big number, how do you format that into a readable format? >> Is it format? >> Yeah, I think we talked about Yeah, format ethers and then you could also like there was some other thing like big number >> dot >> there was like a two number you could do two number but then it's going to be uh It's not going to be actually. Yeah. Yeah. If it's in ether, then it's it's going to be times 10 to the 18, right? I think this is the right way to do it.

>> Let's Yeah. And it's almost like sometimes you just kind of trial and error like let's try format ether and see what it looks like. >> Nice. >> There we go. So, it's it costs 0.01 ETH to mint one of these NFTts. >> Yep. >> Awesome. >> Okay. So now that we read the price, what if we copy and paste like create a new script called contract write and with that price we try because this is only like a read operation. This is free. This is not a transaction. This just like reading but what if we try to mint an NFT from from from the code from the script? What do you think? I think it's a good >> for sure.

>> Yeah. Yeah. I say we duplicate this. We make a contract, right? and we we put a transaction out there. There's there's I feel like we're quickly going through some of this weird um AI and call data stuff that we'll want to dive into and really see. Maybe maybe we create a write script and we write to this contract and then maybe uh we hand it over to EDA and EDA makes a little die contract like read the balance of die and send some die around or something and then we can explore some call data too. Yeah, I think maybe after this we we we can create a new repo and I can push this to the repo and then like Ella can can pull that out and start from the you know with all the we already have.

>> Cool. >> Okay. >> I'm following along the live coding. >> Cool. Um okay so we are on the contract write um script. So this is going to be the same right but instead of having like the rinkb provider we are going to need like the rinkb right because we want to sign a transaction so and we can't do that only with the provider we need a serer connected to a provider and this what is our get uh signer function does right so we don't need this we can have the serer here and then this is going to be the same,

right? Like the instantiation of the contract is going to be the same. And we have the price here. And then we can do the same thing, but instead of calling like mint price, we are going to call um we going to create like this mint transaction and we are going to call some for contract dot I think mint, right? Mint will be the the name of the let's double check. Yeah, I'd need to look at the contract or we'd need to see the code. Yeah, it's mint. Yep. >> And we could see that probably also in the AI if we wanted to search it too.

But I think like looking right there at the contract does it. >> But here you have the mint price and the mint function that as you see is doesn't take any inputs and also is payable which is going to be interesting. Right. >> I don't think we can see the payable thing that you're showing. >> Oh, okay. Sorry. Uh yeah, we're on the screen. This one. Okay, >> there we go. There we go. >> Yes. So you can see the inputs are empty because the main function doesn't take any any arguments. It's just the min function and then it's payable, right?

So that's going to be interesting because let's see what happens if we call the mint like directly like this. What happens? Yes. >> Yep. >> Okay. And um yeah let's console let's do some console log here like minting NFT then send the hash and then oops Let's wait for the transaction to be mined. Let's

wait. >> Okay. What do you think? >> Well, it's not going to work because we're not paying anything. But let's see what it does. Let's get the error. >> Yeah, >> we we know we have to pay for this NFT. We're trying to m it for free. >> Let's see what happens. >> Yeah. >> Okay. The min price is this. And we are I think we got like an error something.

Um Yeah. I think this is good that we get this error because uh >> this is what errors look like in web 3. >> Yeah. And this is >> 99% of this information is useless. >> Yes. Like this is very useful, right? To get like this unpredictable gas limit. That's like a generic error. So, but if you look here, the reason >> is like the exe insufficient e amount. >> Actually, if you check the code h here, I don't know if this is big enough, but uh in this min function, you see that we have a require here. And if this doesn't if this isn't isn't true, it's going to revert the transaction with this

message. And this that's actually that what we are getting in our transaction right like execute reverted insufficient is amount and >> we should talk about value for a second as we're going to get into call data. So everything's a transaction and a transaction is just an object and there's a to and a from and there's a value there and that value is like the amount of value that's coming along with it. You'll pay some gas to have that thing get mined, but value would be actual ETH moving along with the transaction from the from address to the to address. And then there's a data field, and we'll get into that in a second, but just knowing like the the anatomy of a transaction. There's the to the from, and the value, and the value is actual money getting sent along with

it. >> Yeah, as you can see here. Oh, sorry, >> no, no. I was just going to say like payable functions were like new to me when I was starting as well because you can directly like natively have that send payments. Um so like it doesn't seem like it accepts an input but like because it needs like the the native payments layer over there to transfer some ETH to actually mint the NFT. >> Yep. which also goes into how like functions are safe at first and if you tried to call a function on a contract that isn't payable and send in some value it's going to revert it's going to be like yo yo yo no money no money so like you have to mark your functions as payable and this this payable modifier is something

that's obvious to everyone's like oh that like money needs to go in here and we're not sending >> where is this money stored where is this ETH stored if I send some ETH to the contract where is this where is that ETH in the contract. The contract has its own address. Yeah, this is a kind of an aha moment, too. It's like >> we have these EOAs, these externally owned accounts, and we're generating them with these seed phrases, but whenever we deploy a contract, it has an address, too. And it becomes a player in this massive multiplayer game, and the contract can send and receive ETH or tokens or anything else just like an EOA or externally owned account can. And I think that is why it's important to not forget to do a function like this,

right? >> Yes. >> Because because because in mind that if if you forget to do like a withdraw function that people will mean your NFT, they will send ETH to your contract and then your ETH what your if your contract is will be there like forever, right? So don't forget to to have like the withdraw function or something similar. So you can so where you can move funds from the contract to your account or to other accounts or or whatever.

>> And we'll get into smart contract building eventually. You'll you'll learn all this stuff next week. >> Yes. Okay. So let's see. We are here. Okay. So the way to send value into this uh transaction is just creating an object. So in this case if you remember from from send e we have the same transaction and we have the two and the value right but in this case since we are using the like the s for contract the instance of the s4 contract we don't need the two right because the two is already implied on the instance because we already instantiated it with the with the address and everything but maybe later if we are doing like the cal data

stuff we will need the two also but in this case we need the value And the good thing is that we already have the value here because we know that the mean this mint price which is a big number is the the thing that we need to send. So this should be enough I think. >> And if you were writing this raw and you hadn't loaded the mint price and you typed in value equals quote 0.01 that's going to fail, right? You needed you need to do an ethers.youutils.parse ether. Yep. 0. There we go. Perfect. I just wanted to show that just so we know that like, oh, it's got to go to that 10 to the 18 big number.

>> Okay, you can you can clear it out and go back to mint price, but that's a really good thing to show off there just to like >> if you were writing this, you you would run into a problem right there with that mint price because it's coming in as a big number here. But if you just typed it in, you need to do the parse ether. >> Yep. Okay. So, let's go and see what LFG. >> Here we go. GMGM. >> Okay. Okay. Okay. Okay. Let's see if it works. 90% I think that's going to work.

>> 90% sure it's going to work. That's very optimistic. >> 95 95 98 I know. >> 99. Yeah. The transaction is sent. I mean it's >> mind. Okay. Awesome. >> So So now you >> So did we just mint? Let's see if if we go to our address on on either scan. Uh, okay. >> 16 seconds ago called the mint method. >> Yeah. Nice. So, we have >> Let's look at the call data of it real quick to get a peek at it just to start talking about that call data.

>> Yes. >> Yeah. If we look at the raw like what just happened? We just sent a raw transaction to the address where the smart contract is. But there's some extra data in that field. There's this method ID. Look at this. 0x1249 C58B. What the heck is that? It's the It's the actually the hash of mint. Oh yeah. Here we go. Here we go. >> Can we do that online? Catch 256 is what what the hash function is. >> Yeah. Uh let's see if we can do that.

Can we do like an online? Yeah, that's what we want. And if you put in mint Yep. Yep. >> Yeah. It's actually like the first eight >> X which is like the first like 32 >> bits, right? >> So this is six. Yeah. Yeah. It's what is it? Four bytes. It's four bytes of data, right? >> Four by >> Yeah. We're getting this is what's called the function signature. So if let's say let's say mint takes in uh some address too, you would you would have mint and then it'd be parenthesis and then there'd be an address in there and that would change the hash. So this is what's called the function selector and it's just the hash of whatever the

function is you're calling plus the types that are going in as arguments. And the smart contract is smart enough to know when there's a data field that matches this exactly that means the person wants to call the mint function. And so we'll get in and we'll do more call data. But this is just like really hammering home the fact that everything is a transaction. It's not like you make some transactions to send some stuff to people, but when you want to go talk to a smart contract, there's a different way to do it. Everything is a transaction. Everything goes into the me pool and gets m Well, I guess there's me and stuff, but everything gets mined into a block. And that's how you interact with contracts. you're just interacting with the contract by making a transaction with a specific data field that lets the the contract know that you

want to call the mint function on it. >> So can I can I do like a really quick test with the call and see if it works. >> Okay. So here we are using like the contract helper right from from ethers. But let's let's try to do like a like a raw transaction from ethers like using the call data. So we are going to remove all of this. Uh uh and then we have the designer. So let's do this real quick. The main price is going to be ethers uh utils par. No.

And then um the mint cal data is going to be let's copy that from here. >> Yep. Yep. Oops. >> So, we're going to just craft up a raw transaction that does the same exact thing but without the contract interface. >> So, we are using right now the wink designer and then the send transaction. The same thing that we use when when we are sending it. >> But now h we want to send it to the s for NFT address. The value is going to be the mint price and the data is going to be the mint call data. So what would happen if that data wasn't there? So if you just called send transaction with the to the

contract and the value, what would happen? >> I think it will send just to the contract. It will try, right? But >> yep. And I don't know if the contract has a receive function, but the contract has to be again like explicitly set up to receive ETH. And if it's not, it will probably just fail. But without that data, you're just sending money to the contract. with that data field added in. You're sending money, but you want to call a function with that money that comes along with it. And you want to call the mint function on it. And sometimes there's arguments that go with that. And that goes in the data field also. But just the distinction there, that extra data field is really powerful. And when you're deploying a contract, there's no two address and there's a data field that has the bite

code of the contract. Everything is a transaction. It's just packaged a little differently depending on if you're sending money or if you're deploying a contract or if you're talking to a contract. >> Actually, that happened yesterday, right? Like we tried to send like some if and the the two field was like null and like undefined and so we deployed a contract, right? Without >> but it was like an empty contract. The data was also undefined. >> Yeah. Yeah. So also like um Austin was mentioning about arguments. So actually it will go here like I think it's like 32 I don't know something like that and then here it will be like the like the arguments at the end of the of the >> we'll see it if we do a die if we do some die interface later we'll be able to send and receive we'll see it in a

little while. Yeah. >> Okay. So let's let's try this. I mean this should work right day two and this is contract uh cala. Okay, let's see. >> Wow, a raw transaction. We are really leveling up our scripting skills, messing around with details. >> Yeah, getting into it. So, from from the Etherscan point of view, this should look exactly like the last call. Like from the point of view of Etherscan, the transaction looks exactly the same. But for us creating

the script where we had to package it up and use the Whoa, is it not showing up? What did we do? >> No, I think I don't know. I mean, it worked because it's >> Oh, 20 seconds ago. Okay, it's there. Yeah. Yeah. >> But maybe this is not Oh, here you go. >> There it is. Yeah, sometimes it takes ether scan a while, especially on uh like tests. It could take a bit. Yep. Yep. >> So, this is actually like the same >> exact same thing. Yep. We sent in value. We paid some gas. And we have this method ID that we want to call when we call when we make that transaction.

Dang, that is like that is some handcrafted stuff. This is some some bespoke uh transaction creating here. Very nice. Very nice. >> Yes. And also here that you can add like some like gas prices like the nons. You can add like more stuff here like if you want if you want to craft it even more. Uh you can ask like the gas prices, the nons and and more stuff here. >> For instance, like let's let's let's do it real quick. Let's go back to that. Let's figure out what our nons is. Let's hardcode our nons and let's hardcode our gas price. And then let's put that same transaction in at a low price and then a higher price. So it'll be nons number four will be the next one, right? So we do nons for >> I think and then we do >> I think just leave it like that. Let's

see what happens. If we have a problem, we have a problem. Like this is a good exploration. It's a good rabbit hole to go down. >> And then let's do gas price at uh just put like a thousand. So it's like super low a thousand way, right? Actually, it probably won't even let us into the m pool with with a thousand way. But let's see what happens. Let's just like yolo that and see what it does. >> It probably will say that's not that's insufficient gas. And hopefully like it doesn't just we may get away with like minting it at a thousand. If this was on mainet, this transaction would hang out in the m poolool for a long time. See that? It's like 0.0000 zero one guay. If if we were using uh you know a fully setup network where the miners are

picking the the best gas prices. Okay. So hopefully this transaction doesn't go through. And so what we should do now is we want to speed up the transaction. Remember when we had MetaMask up and our transaction went in too slow? We were able to hit speed up. And what that's doing is resubmitting the same transaction with the same nons but a higher gas price. So we've kind of replicated that here hopefully. I think it is stuck. So now let's resubmit the same transaction. So you just control C kill that right. >> You go to non then just add some more zeros to that gas price. Like probably six more zeros.

>> Yeah, maybe seven. Let's just let's just like really go for it. There we go. All right. So now with the same nons there's going to have the same exact transaction in the m poolool. We're going to bring up another one and you're going to see in the m poolool. Oh, this one has lower gas. Same nons. Throw this one out. Put this new one in there. It should get mined. What were you going to say? Sorry, I was I went off on that one. >> No, no. Like like the nons is the the important part, right? Like it needs to be the same nons. If not, if if it's number five is going to be stuck forever because number four is going is never going to be completed. >> Yep.

>> So let's see. Okay. >> Oh, tenway. >> Tenuay, right? That should work. >> Yeah, >> should be enough on on Yeah, it worked. All right, we proved to ourselves the gas and nons worked and we can speed up a transaction manually if we're creating it. Very cool. >> Success. Nice. So, just a a reminder here that this was what we were doing from the MetaMask interface just the other week as well, but it didn't allow us to actually change the nons and like send another transaction.

>> Oh, yeah. >> Um, so like it kept giving us errors, but now like with the code, you can do everything. >> Yeah. >> Yeah. >> Take that Metam mask. >> We'll write our own transactions with black. >> Yeah. For for some reason it didn't work. I don't know. like you could like speed up from the metamas, but if you try to like submit the same transaction with a different nodes, it didn't work. I I I don't know why, but yeah. >> Okay. So, what do you guys think about EDA doing a little die interface now? Did we have we completed it? Have we completed your your stuff so far, Carlos? Or was there more to show there?

>> Oh, I think I think Yeah. >> Is that it? >> Okay. So let's say you're a person at home now and you want to fork this and build something to talk to the die contract either on mainet or on rinkabe. Oh, he you're going to commit that. Now let's look real close here. Make sure there's no environment files, right? >> I'm also going to create like a sorry >> no go ahead. >> I was going to say that let's create like a quick and dirty uh rhythm file which is also always important, right? >> Yeah. Um you have to say like um set up steps I say clone repo um then install dependencies with npm

>> man good spelling on dependencies. I always have to it takes me three or four tries on that one and it's my first language. >> And then what else? Oh, like copy m example to uh M right and fill the I don't know required uh data or keys or keys and now run the your the script of choice with nodes uh I don't know like day

whatever and then skip >> I think this this is good enough right for now at least maybe we can iterate on the read me later but I think this is >> so triple check here we don't have an env file that's getting added when he does this get add all it's very scary make sure when you do a get status you don't have any files that have any private keys or >> and it's just like man you got to be very very careful about that. Yeah, >> you can do this g div cache and then that will show like everything that you have on the staging like the g staging and it will show like all the so you can take like a quick look you know >> private key. Yep. Exactly. Yep. Cool.

>> So here you have to be worry be careful about the m file. This is the only file that that you don't need to to commit, right? And since we added here, it's not going to be committed. Okay. So, I guess now I I need to like create a new repo, right? >> So, >> yes. Or if you could just push that up so Ed could pull it down and we could uh work. Oh, okay. You tell me. >> No, no. I need to create a repo, right, for >> Oh, I see. Okay. Sure. Yeah. Yeah. So, let's script uh how should we name this? Uh >> week two. Week two scripts.

>> Yeah. >> Scripty scripts. >> Scripts. >> Scripts. It's going to be public, right? For now, at least. Yeah. >> Yep. Yep. Maybe throw an MIT license on there just in case. It doesn't matter. >> Yeah. >> It's already >> So, >> okay, cool. Let's add this. And uh okay. Okay. Let's use main also. >> So it's we switched to a main branch. Is that right?

>> Why not just have it on master? Why is the main >> Yeah. It's like a notation I think like people move from from from master to main just for like language language stuff. >> Okay. So some music, please. Can you can you see? >> Yeah, we do see a password. Yeah, be careful. >> We'll put that somewhere else. Meet your thing. This is scary. >> And there password. >> It worked. Good work. I like this. This is a fun game to play. All right. So now any of us can pull that down. could you shoot that repo to us in the chat and we'll put it in like the the video notes

too if someone happens to be watching this. >> So what is where is the rhythm? Oh, okay. I think I I didn't >> I didn't commit this. So it's like day two >> and read me. >> Nice. >> So now let's push in main. >> Uh okay. Now here we go. read me. >> Yep. Okay. So, I'm going to paste this uh to you in the chat. >> Got it.

>> Okay. So, we're cloning that. >> We can do like like the opposite way, right? Like Eda can like clone the repo and and and start from from scratch, which is similar that the same thing that people are going to do when when they see our videos, right? >> Yeah. Do you want me to like ste steal the screen and like do it together or yours? Okay. Okay. Let's let's give it a try. >> Yeah. So, here's the repo. Carlos, I'm just gonna get this. Um, I'm pulling up my terminal here.

>> So, our goal, let's set a goal here. We've got maybe like 20 20 or 30 minutes. Let's set a goal to have a script. Just like we were sending 10% of our ETH, let's have a goal set up where anytime the script runs, it sends 10% of its die to Sanford or something like that. Does that sound like a good enough challenge? So, instead of sending ETH, we're going to be sending a stable coin die, which means we're going to be interacting with a smart contract that moves that token around, not sending it at the at the base of the pro the protocol. I don't know what I'm thinking. We're not sending it as value.

We're actually going to make a smart contract call, >> right? So, the first thing I guess is Oh, yeah. We do need to do npm install, right? Like first install dependencies. >> So, you did a clone. You did a get clone so far. Yep. Then we cdm >> only get clone >> and we mpm install. I'm on it. Yeah. >> So fast. That ethersjs script is really light. Yeah. Rick Rickmoo really takes pride in that I think. >> Yeah.

>> Okay. >> Um and >> what about our file? Oh, go ahead. No, you go. >> Yeah, that was exactly what I was going to say. We don't have the env file for the secret keys. So, that's like one thing which we need to add. And this example M is always super helpful. So, I'm just going to do that, right? Let's just add Oops, this is going to add >> Oh, she's not following your instructions. She's making one straight up. The the read me says you copy the enenv example file to env. You're doing the exact same thing. No, it doesn't matter. I that was a big JK. >> I usually just like copy and like create my own from the same stuff. Yeah.

>> So, do you have I mean not sure if you have the >> do we want to use like the sound for private private key or or what do we want to use for >> uh let's create a new one. Right. Okay. Okay. So, no, no, this is a really good point. Like, when you're building things, you're really you you want to just go grab a private key you already have created. This is awful opsseack. Like, don't do that. Generate for every new script, for every new thing, for every new place, for every new machine. Generate a new pneumonic, generate a new address, and fund that address from an external source with just enough money to do what you need to do. So if that happens to leak in some stupid way, it's an isolated thing, not oh man, Sanford just lost his NFT and all his money

because we used his private key in here, right? So let's let's let's do some good opsac here and let's generate our a new uh pneumonic and let's go ahead and fund it. >> Yeah, I can. So I just >> Yeah. >> Yeah. Just from the utils file, it's already here. So I'm just going to run this file to like generate and save that information, right? Yep. >> Um, so maybe I could just like stop sharing my screen while we do that. Or >> Yeah. Yeah. Yeah. Here I could I could do it over here. I could share the screen. So you could do the same thing. I'll steal the screen and I'll have it up on my side and I'll run the same thing. But you do the same thing, but yours will be a little different. Uh, so what are we doing? We're getting into

>> uh basically I did I need to generate a wallet, right? So I need to do something like >> you can create like a new script or you can even like call the utils file and comment unc comment the line of the >> so I need to bring in our utils and I need to bring in the what is it create wallet oh man why doesn't my thing yours has such good uh yeah so we want the generate wallet right y >> and then I'm going to call something like >> I think I think you just need to call that function because that function is going to print everything on the >> Y.

>> There we go. Okay. So, I have a private key here and I have my address. So then I would take that private key and I would put it right here. Right. And that's what Eda is doing right now. And then I would hide that. So save and get rid of that. And then do I need to put in an Infura ID there too? >> Yes. I just paste it into the chat if you want to use that. >> Okay. >> The one that is >> Oh, that's the the very public scaffold each one. So it doesn't matter. Okay.

And then I would get into here. Oh, whoops. Where is my Oh, it's hidden. Oh, yeah. See, it's gone out of my editor. So, I need to uh let's see. I could just cat the env file, right? And that will show it. Yeah. Yeah. >> So, if I wanted to edit that, I could. Oh, man. Can I do this? >> Oh, yeah. You like that? You like that? >> Oh, >> there we go. You like that? Colon WQ because I know it work. >> Okay. So basically I created my and now if I cat that env file I've got my private key. I've got my infura. Uh hopefully Eda has the same thing but a different private key that is not okay to expose. I'm going to totally trash

that one right now. But I wanted to show that those steps off just so you at home know exactly how to go through that. >> Yeah, I did that in the same second over here on my end. >> Now um yeah, we have our M file and awesome would be funny if I had exposed that right now >> right there. There it is just open and that comes up but no uh so everything is just here the file I didn't do anything just added like the m part.

>> So yeah now >> what's your address can we fund you can we send you some what we need to know is the address of your wallet but we could do that by can we script that up real quick maybe. Yeah, like you can create like a new script and import the utils and then get the serer and then we can just print like serer get address or something like that. >> Okay, so let's see. Okay, so what function would we be calling? We're looking at the utils right now. We need to kind of pick out one of these uh scripts to run, right? >> Or should we even duplicate the send?

Can we can we duplicate the send e script and create a new script called get address or something like that? Is that okay? Okay. Yeah. Get address maybe or something. Yeah. And then in here we just want to instantiate that ser the rinkabe signer and then something that you probably console log rinkaby signer address right. Does it do that? And then we can delete everything else. >> Yep. >> Just so we have >> Okay. So we don't need like all this, right?

I mean, you could leave the balance just in case. Maybe leave the balance, but just say here's my address and here's my balance, right? So, everything on line 11 down can probably go. >> Yep. >> Nice. >> And let's do one more console log that does rinkabe signer address, I think. I can't remember exactly. Oh, yeah. Oh, yeah. All right, let's run it. >> This is an >> Is that an await? Probably not.

>> Nope. You don't want to cd into the day two directory because the env file isn't there. You want to run your script from wherever the env file is. Yep. So, you'll do a node day2 slash get address. All caps when you spell a man name. Oh man. There we go. There we go. There we go. Come on. Give us a balance of zero. And >> I think address is without the functions.

>> Nice. >> Yes. Okay. Can you copy paste that address to me and I'll send you some rinkabe. And again, if you're doing this at home and you don't have a buddy with Ringabe, there's tons of faucets. Hit hit one of us up >> as well. I didn't think >> was that. >> We could get one from the faucet right now if or we're racing time. >> Yeah, I'll race you. You I get the My Metam mask is super slow, but I still bet I get to you before uh the faucet >> running again to print the balance.

>> Yeah. Okay. 5 ETH on the way. >> So, are we going to interact with the with the rinkb die contract or are we going to use the the mainet one? >> Shoot. Yeah, I was thinking mainnet die, but you're right. Maybe we should. Well, we haven't exposed our contract. I mean, this is technically we could talk to mainet. Uh, we could do mainet here, right? Like >> yeah, I mean >> we could send some mainet die and actually do like a real transaction that that would help us like run into gas issues and weird stuff too, right?

>> O, we just upped our our uh target. So now our new goal is to >> Are we still racing against time? >> Well, I mean I got another caller in 30 minutes. We got to get it done. >> So I think we can I think we can do it. I think doing it on mainet is a is a good test. So right now you've got that rinkabe serer there, right? We need to do get serer true and it needs to be mainet signer, right? So that's the first thing we can change here in our get address is to have a main. Yep. Yep. >> Yeah. And maybe rename it to like mainet mainet serer.

>> Yeah. >> Cool. Cool. Nice. And now the balance should be zero. Yep. But it's time for me to send you some real dye, some real money. I'm going to put it on mainet and do it. Let's go. And I'm going to wait 10 minutes for MetaMask to load my tokens. There we go. >> So maybe because now we are checking the balance, >> but the balance is going to be zero like all the time, right? I mean, I guess that we we also need like some ETH, right, to be able to to send Yep.

>> That's where the gas key is, right? Like to pay just to make it. >> Yeah, because >> let's actually not send the ETH at first, right? Let's just say let's send the die in. We do this all the time, right? And then we hit send and we're like, why isn't it sending? Oh, yeah. We don't have money for gas. Let's just remember we need to send some ETH in, but let's get that error. Okay, so you should have some mainet die. Oh man, I think I just paid $8 to send you $10 worth of dye. Oh no, that's >> it's not it hasn't gotten mined yet. I actually Yeah. Okay. Hit hit up and enter. Let's see if we've we have some mainet value on this address.

>> Oh, no. This is your balance. This is your ETH balance, right? Okay. Okay. So, I might Yeah. Uh let's just send some ETH like >> Yeah, let's just send it in. >> We could check. >> Oh, I see. put the address in and then you could see. Yeah, it's got $10. Okay, cool. So, we're I'm I'm sending to the right place at least. I'll send you some ETH just so you have it though. I feel like >> uh we're we're going to be stressed for time here in a little bit. So, what we need to do is we need to interact with the die contract. Let's start by just getting our balance in die, right? So, we need to is there a contract read a right like like we need to we need to

get the AI for the die contract, right? Yeah. >> So I think Eda if you click into die on on either scan if you click in in your balance there you can check the contract there and go to the contract tab and and then just like get the API there. >> Yeah. >> So just like copy the Oops. Copy the API. Um, going back here, just gonna create a new file.

Let's call it D AI. >> Yeah, >> I need that. >> What is it? >> Formatting it. So, >> yeah. >> Yeah, if you want to copy it for NFT. >> Yeah, >> just have to declare a variable and export it. >> You need to export it still. So you want to click on Sanford NFT AAVI and copy the the stuff right at the beginning. >> Yeah, there we go. That part. Yep. And then export >> and the end as well just to make sure like that we export at the end.

>> But I'll do this part. >> I think you don't Yeah, that one. Yeah. >> Yeah, she got it. >> I think we also need this part now. >> Weird copy paste. Grabbing the semicolon and the square brace as part of the copy. Oh, it doesn't have it. Nice. >> Yeah, because it I always like miss or Yeah, this is like you shouldn't usually like copy paste our AI guess like this like use an indexer probably, but just for reading from the contract in this case. >> Okay, so we do we have the AI loaded into our script. So now we've created our AI. We need to load it into the script.

>> Like maybe you can just like copy this this file, right? Copy the contract with and you can say like contract D something. Yep. Nice. >> We might use Sanford's address. >> We need the die transfer.

>> Yeah. >> But this is the the smart contract address, right? All right, we need the die address. Yep. Yep. >> Die address. So just I guess this is >> No, it's right top left. It's that. No, it's the 068. It's that one right there. Right. Yeah. >> And there's $500,000 worth of tokens locked in the die contract because there's not a withdraw function in the die contract and people send tokens directly to the contract on accident. There we go.

We had the ring incubate over here as well because it wasn't changed since we want to talk directly to mainet. Just making that modification. Um and I think >> nine and 10 still. Yep. >> We need to do Sanford address. >> No, this is we can just blow this. >> Oh, get that right. >> Yeah, the on line nine and 10, you still have the Sanford address and API coming in. We need to put the die address and die AVI. There we go. So now the and probably rename Sanford contract to die contract. There we go. So now we have our connection to the die stable coin contract and it wouldn't be mint price. We want to

probably get our balance or something. Right. >> I think it's balance off, right? That is like the function that we want. >> And you pass in an address. Yep. >> Yes. And I think this >> uh I think capital O I think it's camel case with no underscore. Yeah, I think it's that. >> And then you need to pass in what? Our address right? >> C. It's down below there. It's in your console, I think. >> Yeah, >> it's that right there. Right. >> Yeah. Let's just get that >> maybe call it like my address or local guy address. I don't know. Just to be a

little more explicit about our variables. There we go. >> Yeah. This is not mint price, right? This is probably your die balance. Yeah. >> Nice. >> All right. We're getting close here. Yeah. >> Um, yeah, this is I think it's going to require some formatting. I'm not exactly sure what kind of formatting we will need, but we could just print the die balance. >> Yep. >> I would just throw it right into that format ether. I bet it's going to come back with that. >> Yeah.

>> All right, let's run it. See what happens. So, we need to node contract die. And this should go out to the mainet die contract and it should check our address. >> We could check from here why it's right. Like I think we have the wrong. >> Do we need to do methods balance of or something weird like that? Like what's the why did that not work? >> Balance of >> Oh, you could also search balance of in the ABI the file that you have that's dieabi in the top right.

>> Yeah, search for balance of in there. Yeah, it's there. Weird. [Music] >> And it takes an input address. >> Yeah. >> Okay. What are we doing wrong here? Let's go back to that script. What the heck? It's saying that balance. >> Can you print the AI? The console log. Like, can you console log the AI just in case? >> Oh, is she? Yeah. No, she is. H. >> Yeah, I would cons. >> I'm just gonna like fly these over because it's a bit complicated with them. Let's console log the the what you want to console log >> the die first.

>> Yes, >> it's there. Yeah. Okay. >> Uh >> so we get the die AI die contract. Do I have like >> maybe console log the die contract? Yeah, but I'm reading from the die address right? >> Oh, there we go. It needs to be die contract, not balance. There we go. >> With cuts. With cuts. Yeah.

>> All right. >> You have $10 worth of dye. All right. >> Yeah. >> So, now we want to duplicate that >> contract. >> Yeah. So, that's contract. Okay. Let's just let's just keep editing the same script. So, we're able to read our address. Now, the goal is we we want to send some die to Stanford, right? So, we're gonna need to call >> transfer. >> transfer, I think, right? >> Yeah. Yes. >> And you could look that up by looking at the code or looking at the AI. Let's just try it and see what happens though. It's all it's just mainet.

So the thing is that we are going to need the serer that on line 11 >> we are we are using the the provider. So instead of on line six we will need to get ser. So instead of just saying mainnet provider, we want to say mainet signer and we want to do get ser and we can trash the mainet provider and just use the uh I mean maybe use that me there because we show that we're using the provider just to get the balance right. Oh no then then there's like okay this is interesting. So if we do it this way, we can have basically a die contract that's for reading and a die contract that's for writing and it'll go through different providers depending on how you're doing that. And you do that a

lot with your app. You'll see that in scaffold eth in week three. We actually have read contracts and write contracts. So maybe this we we could leave it like this. So we let's have let's have uh the die let's recreate the die contract from line nine. Let's copy and paste that whole thing and let's do die contract write and send in the signer. So pretty interesting here but yeah go ahead. Yeah, I was just going to say like this is because of uh when we want to resolve the ENS, right? We read from like mainet generally. So I think that's and then with scaffolded right like you make the transactions like write actions to incubate but read from mainet. So >> exactly can be faster too.

>> You could have a read provider that's just talking to I don't know Infura or something like that but then your right provider may need to go through MetaMask or some other slower thing. And I think MetaMask is slow because Infur is slow. But let's say you have a read from Alchemy and a write through MetaMask to Infura or something like that. So your app could actually read faster than it can write. So it's nice to have those two separated. Okay. So let's see. Mainet signer. All right. So now we want to do die contract. Right. Right. We want to be talking to the right version of the die contract transfer.

>> The die transfer. >> It can't be die transfer. know >> I think >> no it is is transfer right I just like copy on telegram channel like the the the AI part for the transfer >> okay yep >> I maybe we can give another address right >> you give it an address and an amount yep let's put let's put in Sanford's address if we don't have that already oh we don't yeah we need to get a new address yep >> just going to call it send to address. >> What's Sanford's address? Could you paste that into chat?

>> Or maybe we can we can query from the from the mainet provider, right? We can we can do like a a >> Oh, like let's look up his address. Let's look up his Yeah, >> we're making it harder every step. >> So, is it look up address? Is that the name? So, it's >> his resolve name, right? >> Resolve. No, resolve. >> Resolve name. Is that what it is? Let's do it. Let's do it. >> I think we also have it in another function, but we can just like do it here. Yeah, on the on the send ETH is there. If you want to copy and paste on the send ETH script, we have there. >> Yeah, >> there it is right there. Y >> I'm going to put it here.

>> And it is good that we save like the menu because we can we can do this stuff now. >> Yeah. >> And this is going to >> Yep. That's just our read provider, but it's fine. That should work. >> Yep. >> Yep. So now Sanford's address we went through this this >> should we maybe just console log Sanford's address and make sure it's set before we start writing our right. Should we just do like a console log of like sending die to Stanford's address to make sure it looks good? >> Yeah. There we go. Let's run that just to make

sure that address is there and it does the resolving correctly. >> I mean, you could show your die balance, too. It's not a big deal. >> Give us an address. >> There we go. >> Nice. Okay. This is taking shape now. Yeah. >> Yeah. >> And you can check this on ether scan as well, right? Just to like verify. >> Yep. There he is. And how much dye does he have? 36. He has $36 of dye. So, we're going to send him a little bit more right? Yeah. >> Okay.

Let's not even send him. Let's just send him a hard-coded amount. I was talking about 10%, but that doesn't make sense. Let's just send him five bucks, right? Okay. So, now we're ready for line 31. The main event >> this is transfer. And it will take in I'm just looking at the front. >> It takes in an address and an amount. So it takes in the second argument is a 256 >> and right here let's let's say we wanted to just send five you if you typed in the number five that would be sending five way. So what you want to do is send five ether. So the way to do that is to use parse ether right. So we need ethers utils parse ether and then five in quotes and that should send five bucks.

Yeah, like even we are not sending ETH, we use the the the util parse ether to convert it to the like the you know like the format. >> That's a good point. Yeah, it says parse ether has it's not actually ether. It's just doing the times 10 to the 18 math. And I think you want to have quotes around it too. It doesn't like numbers either. >> Sorry. >> Yep. >> I wasn't sure. Okay. >> Okay. I mean >> I think this should work. And then maybe we can say like transaction on send and then do this D trans.

Yeah. >> So >> you can just grab that from the send E file too probably. >> Yeah. >> Yeah. Like the line 20 and 24. Yes. >> There we go. So it' be die transfer.ash. Nice. Nice. Okay. So what about mainet gas? Do we have ETH in this account?

What what is the account uh address? Should we just double check that we have enough gas? Yeah, let's go to my address on Ether Scan and just look. I think I sent some gas in. I can't even remember. It was like 10 minutes ago. Okay, cool. Yes, we have. >> So, I send in some ETH. >> Yeah. So, you have $27 worth of ETH and you have $10 worth of dye and we're going to try to send five of those dollars of dye to Stanford. Sanford. And if we wanted to just send ETH, we just make a transaction with value. But since we have to send D, D is a token that's its own contract. So, we're gonna have to go to the contract and tell it to transfer some of our dye. But I think it's it looks good. Like, should we should we fire it off and see what

happens? Should we should we set the gas manually? What's going to happen if we don't set the gas price on mainet? Maybe let's I think it'll price it for us, but technically we could set our nons or we could set our gas price here if we wanted to be more surgical with it. 69 guay right now. Little it's a little hot. Let's let's let's fire it off and see if our $27 is enough to send here. Any any last thoughts before we try to execute this mainet transaction? >> I think all good. just printed the die balance over here as well to see the new balance without going to ether scan.

>> Nice. >> But yeah, Carlos, sorry. I didn't mean to interrupt. >> No, no, I was going to say like 90% is my I think it's going to work. >> He's 90% cal I trust I trust Ella. I trust I think >> let's fire it off. Let's see what happens. >> Oh no. >> Okay. >> Oh, it's already been declared cuz the Yeah. seconds like for like new new >> 27 >> you could change it. >> There we go. >> Like instead >> this doesn't count. This doesn't count. >> That doesn't count. 95.

>> Okay. >> That was the last minute when you were not looking. I guess I was just doing that. >> Okay. 90. >> All right. So our die balance is 10. >> We're sending die. Transaction is out there. Can we go look at that on Ether Scan? Yeah, just going to do that. >> There it goes. It's going to take less than 45 seconds, meaning we paid the right amount of gas. If we scroll down, let's see what gas it selected. >> Oh. Oh. Oh. So, it decided to do >> 156.

>> Oh, that was an expensive transaction. We probably should have coded up the gas because it's it only needs to be like 70 something right now to get through. >> But it actually adjusted. I think that was like >> Oh, that was with the base. Yeah, the base fee. Yeah. Yeah. Okay. Can we open up the full transaction? Can we click to see more there? Actually, let's see this first. Yeah. >> The transaction was sent and our new balance is five. And if we go look at Sanford, Sanford should have some die now, right? If we went to Sanford's address on Ether Scan, but I want to keep that transaction around because I want to go look at the the uh call data.

>> And we did it. It worked. And yeah, let's check and see. What did he have? 36 before or something like that. >> Now, now he has 41 D. So, it works, right? We sent some stable coins by writing a script that talks to a contract that tells the contract to send some of our die. >> Can we go look at the call data real quick? Oh, go ahead. Go ahead. >> Yeah, just to note, like you don't see it here, right? You have to look at the ERC20s for transfer because we're transferring the die token. Um, >> yeah. I'm not sure which ones get seen here. Actually, like you can go to all of these, but on the ERC20 token, you can see that it just came in, right? $5 worth of dye.

>> Yep. >> Yeah. If you if Sanford was looking at his transactions and you said, I just sent you sent you $5 and he's like, it's not here. It's not here. Yeah. It's over in that internal or the the ERC20 tokens. Yep. >> Awesome. >> All right. I want to see the call data. So this call data had arguments. So there we go. This is what I wanted to show here. So we called transfer with some destination and wad dang it maker maker dow people. So yeah the address is the two address and then the wad is the amount right it's a 256 amount that we sit in and we can see that the address is we we see the method ID which is if we were to get the hash of transfer with

address 256 parenthesy that's the function signature that would be that a959 CBB so the method ID is that specific transfer function with those that signature And then argument zero is the address and we can see it there. And argument one is the $5 we sent be five* 10 the 18 is that big number there in hex. And that's what the the uh call data looks like. So again to send die it's just a transaction but the transaction looks like this. There's not a value that goes along with it. There's this call data with the selector of the transfer function and the argument saying go to this person and this amount and send

this amount. So, we did it. Any questions there? Am I Are we covering it correctly? Hopefully you at home followed most of this. It was a little wild. I think we did it though. >> Yeah, I think that was a good one. Yeah, we covered a lot of stuff in this episode. I'm gonna call it episode. >> Episode. Yeah, we did it. All right. So hopefully you at home are getting your scripting going. We'll commit some of this uh up to you uh to tomorrow. Next next uh uh day we'll get into more like scripting and more call data stuff and and more automation stuff. Uh any any thoughts? Any closing thoughts? Carlos and I think we did it.

>> No, I think we did a lot of stuff, you know. >> You at home should understand what providers are. You should understand what signers are. You should understand how to create a wallet and load it from an env file. Uh you should understand like imports and modules and some node stuff that we went through, right? Format ether and parse ether. Hopefully you're understanding how to send ETH verse how to interact with a contract and how that's different even when we interact with the contract. If we send it a provider, it's sort of like a readonly. But if we interact with a contract with a signer, then we can write to it by signing transactions.

I think we did it. I think we got it. Like that was and we even did some ENS stuff. So we're actually reading from the ENS contract what their address is and then we're writing to the die contract to send to that address. So we had lots of good contract interaction, too. All right. Happy Thursday. Thanks for being here. Good work, guys. >> Thank you. Thanks, everyone. Thank you.

Related talks