Solidity 101 | Session 5 (@HemaKarthickCrypto)

Solidity 101 — dev3pack & Cyfrin Updraft · 1:08:35

The fifth Solidity 101 session covers transfer, send and call for sending Ether. It uses the Cyfrin Code Glossary and tests the functions with different tokens.

Speakers

Topics

From Solidity 101 — dev3pack & Cyfrin Updraft, hosted by dev3pack.

Transcript

Hi, Emma. Hi. Hi, Seline. How are you? I'm doing great. It's a a good weather on my side. Um, so I'm more happy. And you? Great. I'm doing well. Very calm after dinner. Oh, okay. So, you just dinner? Yeah. I just, All right., Uh, I, will, put, a remainder. Um usually we are between like uh 10 and without without AI we are between 10 and and 20. Um um let's wait a bit. Probably five

minutes. and uh and yeah um hello I will put a render no okay so today how's everyone doing it in a one week stretch are they finding it easier than a one month stretch yeah yeah yeah, definitively, like, um, u, some already completed the first section. I I didn't yet follow up on the second section and third one. Um and um I think around 15 people are actually doing siphon. So cool. That's pretty

nice. Yeah. Um um um what is your next event? Uh next I I'm so mad that I couldn't go to Prague. So probably can a nice um but uh visa is already so hard to get from India. So doubtful.

Yes, I can understand. Right. Um a pop-up city will happen just before can um can that's called oit is more for AI AI3 I know will be there um I see so with with uh is global you can be approved uh in a click. Oh yes, you just have to go to the pack um Per something like this. Oh, you can share me the link.

Yeah. [Music] Um guarantee access can here. Wait can take a look. Oh, pioneer. Yeah, yeah, yeah, yeah. I because I said tuner. Sorry. No, I didn't catch it. I'm horrible., All right.

Um, yeah, it's Friday. Um, so Nidi was um part of the base fellowship. Oh, nice. So yes, in India she's participating to uh this one and um they they have like one one hi probably you can show your experience that better than me. How is the fellowship maybe? Is it still ongoing? We can we can't inter we can't uh hear you.

H no you muted yourself. Oh very great you have done. So yeah it was it was really nice. I met like all new people and yeah built a project. The goal was to uh re like um submit the project for B um India. Yeah. Right. And the main goal was not that the main goal was like building experiencing networking.

[Music] That was the main goal. Experiencing the you know mountains and things. Nice. Okay. inside. Um, let me check. [Music] Um, I will send a message um individually like I'm coming. All

right. Ah, Ashley, you you remember Ashley was uh at the in the previous one. Yeah. Yeah. And she made really cool progress. Oh, how far are you actually now? Actually like for during this this week she asked some question and also help help a lot. um a rack into session um when when something was like not wrong but just a little big. So nice. Yes.

Nice. That's good progress. You you can be a mentor in the next one. Yes. All right. Um, what's the next event? Ashley, I don't know if she can talk. Um, oh yeah. Oh, I said, "What's your next event, crypto event?" Because you you were at um Defcon uh last year.

I remember., Oh,, all right., People, are coming. Yeah. I hope to be at their connect, but we will see. All right. Yeah. It's it's like the the gathering of everyone at the end of the year. Nor you will be there. Yeah. And I also have never been to Bones Cyrus and I'm very curious. It's a it's a nice place to be. Um just a bit expensive because of the prices. Um, so for example, one day the meat is like a

price, but another day it's like probably like 30 30% more or things like this. So it's complicated. You want to organize events um in advance, you have to take care of um this different um Yeah, it's Yeah. Is it because of the high inflation? Yeah like Turkey. In Turkey, we have the same. So, I think I won't have problem about that.

Yeah, remember that. All right, let's start. Okay, great. Nice. Share my screen. Sure. Oh, could you present yourself? Yes. Okay. Uh I hope we have uh gone over Yes. Great. I hope we have gone over the basics and build a little bit and today we uh so let's have a quite a recap. We had a fun meme contract where anybody should be able to send an amount to that person. Some person will be the owner of

the contract. For example, you can think of this person as a creator. So this creator has a website that is the fund me. Users can come and fund this person. So a minimum of 5 USD is expected. Anything less would feel a little bit you know it's not worth the gas fee. So you you you're having a restriction of you have to send me a minimum of $5 uh dollars and maximum there's no limit at all and you have to uh there's no direct way to calculate that whether they are sending you $5 or not. So we had a price converter that actually gets the price uh that they send the amount the amount

that they send is sent in ETH. So you compare whether the value they sent in ETH is uh equal to $5 or greater than $5. You check that with the help of the library you created and then it it just keeps uh getting added to an array and it's stored in the contract. So let's say this creator comes and at some point they want to withdraw from the contract. they just go ahead and call this function called withdraw so that they can get it in their own wallet. That's the whole idea of the project.

Before could you say uh some words about you? Oh me I'm sorry. Okay. Hi. Hi everyone. I'm Ha Karthik. I'm actually a smart contract developer. Uh I'm a contract developer. So I work for multiple projects and assist in smart contract architecture and development and she won a whole yeah I I I love hacking so I just attend as much hack as possible that's how I actually got so much experience in okay getting back so yes so this is where I presume we have stopped what we did here is uh

we had a withdraw contract where the owner should be able to withdraw. For this we first oh that's a pattern we follow. Before you withdraw from a contract you first set all of those values to zero so that uh a person is not able to withdraw the same uh amount again and again. This is actually uh slightly on a security perspective that we do this to clear out all of uh all of the data that is in the array. So after this what you have to do is the actual function of the contract that is withdraw this amount from the contract to that creator. So transferring this actually uh transferring any amount of

ETH actually can be done in three ways. Let's go over to the slides. So there are uh there are three ways that's transfer, send and call. So you can use each of these different types of calls but uh what doesn't change is the function should be always payable. Payable actually denotes that this function is accepting ETH. So you you said that context and then the address that is receiving uh this ETH should also be payable.

this uh there's not much difference between uh a normal address and a payable address. It is the same address in the sense of what your address is. You just wrap it around the payable. We'll see uh we'll go over the code example so that you can better understand it. So since we had three, let's go over transfer first. when you uh this this is a very simple example of how you send ether to another person with transfer. What you do is you have a function and inside that you just set up who you're sending the amount to and here if you look at this here

um okay so you you set the function to payable and you have an address you also set that to payable in a lot of cases uh if you know for sure that uh some external address you're going to transfer for that amount. You can also declare this uh as a state variable. But if you haven't done that and you only notice uh at this point or you come you you there's only a case only for this function then at that time you can just add this payable keyword to it. So you just wrap that address into a payable format. That's it. So address payable and this is whoever is receiving it.

This is the actual transfer that takes place. Uh let's go over the syntax. What you do is there is the recipient to whom it is sent. So you put that dot uh so the two is actually coming from the argument. This is the person you want to send the ether to. So you have the two that's the recipient and transfer. This is the keyword that we use. Uh that's what we are doing, right? So that's the keyword and then the amount that you want to send. You must have already understood from previous sessions that the message do value is the actual value of ETH that is being requested or uh the the actual value that you want to

transfer. So you specify that as said that directly as the amount or as message do value. One thing you have to note is for a transfer function there is a gas limit of uh 2,300 and by default this transfer throws an error if the amount is not transferred. So you don't uh typically you would only use this if you know for sure that the person you're transferring to is an EOA. That is it is not a contract. It is an actual address owned by uh someone that is an exter uh externally owned address. That's the transfer function. This is typically not

used in production. We'll go uh I I have uh we'll go over what are the scenarios in which we'll use transfer later. You have some question on the chat for mostly payable is used for functions that receive money and transfer money. Yes. uh not generally money if you're using an ERC20 token for transfer then you wouldn't need to mention it as payable if but when you're using uh ETH that's the native token of uh Ethereum right so in that cases you have to use payable all right okay then we have send ether with send

uh Earlier uh if you actually saw the previous slide, we don't have any error statements. That's because this transfer directly like automatically returns uh an error if the transaction didn't go through. But when you use send, you have to actually uh keep track of whether you uh the transaction failed or not. First, let's look at the syntax that we do. The same thing goes like you have the payable address and the function is also payable. Now uh let's come back to this first. So what we do is the variable uh to whoever

you're sending the recipient is mentioned dot send message do value same as the previous one but you're keeping track of uh you're introducing a new variable to keep track of whether that transaction went through or not. And on the next step you only have to manually check it whether the transaction went or not. That's how the syntax is. You have to keep track of it. began for sending ether with uh the send type of uh transfer there is a gas limit of 2,300 and you if you have some kind of calculations that goes on within this transaction that it's going to revert

that's why we keep track of this uh with the required statement but not all transactions uh can be accommodated within this 2300 value uh gas value. That's why we also use something called call. This is actually not a direct um uh how do I say it? It's actually a low-level call. We'll go deep into it. This in foundry one. Uh but this call you you have to uh the syntax is not like a your regular syntax. It is a low-level syntax in the sense that usually what call is used for is when you call some other functions in

a contract or something you use call. Uh let's forget about this. How how would a normal call be? Like if you can think then it'll be call dot whichever function you want to call you'll just put it inside this and you know uh that that actually is a call itself the name call but also it calls a particular function from a different uh contract. In our case, we are using that same syntax to actually uh transfer the ether itself. So let's go over and uh look at the syntax. So to is whoever you're

sending the money to, that's the recipient. Dot call is actually the keyword. Now you see value is message dov value. uh this is left empty because we are not calling any particular function. We are just sending an amount of ether. But uh this is the value that we are introducing. Let's look at remix to see where we would uh usually see this. So let's just compile and deploy.

Oh okay. So here you see value right? This is the value in here. When you simply click on something uh for example fund the value is set to zero. So zero means there is no value sent. In that case you wouldn't uh need this at all. But in our case, we are actually sending some amount. You have a question. Yes. What is the expression address? Oh, it was at the beginning.

Yeah. Oh, okay. I thought it was covered. It's nothing. What you do is when you with um Okay, let me explain this code of what has happened here. You have a mapping of all the funders who have sent you. For example, if uh Solen has sent me, then the contract is actually keeping track of Solen's address and if you had sent it, it also keeps track of your address. So this is maintained in an array and it is al it also has an associated mapping that is who sent which amount. That is what we are clearing here. So new is not

just uh used for creation of new contracts. It is also used to clear an array itself. So when funders equal to new address of zero, this means you're taking the address uh uh address array of uh I mean sorry you're taking the funders array and clearing it out and setting it to zero. So the default value is always zero. So after this step what happens is you won't have a mapping of oh Sing sent this sent this it is all cleared now why do we do this uh when

when you withdraw uh your it's actually a step to avoid uh having multiple uh you know um uh saving it multiple times. For example, if you do let's look at what if if you don't do this, what will happen? The array remains uh the same. So you will withdraw and go. But the next time again if you call this withdraw function what what's happening in here? If you see all of the um you're looping through every address that is in the funders array and you are uh adding

it up and withdrawing that whole amount uh in here uh you're actually first uh that that would be the scenario when if you don't set it uh set it to zero but you want to set it to zero because you don't want to keep track of those uh mappings again and again that it's like a design choice you can say you can skip it but uh I I I would keep it that's it it's not something uh very much mandatory does that answer your

[Music] question. Okay. All right. In here. Okay. Um, so we have the call and you actually have the value that you're sending. In this case, we are just putting it at as message dov value and you're also keeping track of whether this transaction went through or not. you're setting a uh this is actually uh as I already told you call is actually low-level function. This function accepts uh the function that you want to call and it also returns something. For

example, do we have any return statements here? Okay, we don't. But uh usually when there is a function sometimes they return some value. Okay, for example uh let's say return the amount or something. So when this is returned it's you uh when a call function happens it calls the function whatever happens and whatever is in this return is actually sent back as a argument in here where is it here.

So that's why we have bytes memory data. uh so there can be multiple return values that comes out of calling a function. So this data is actually an array and it's a byte array and it is uh stored in memory but you can act uh since it's just transfer of value we don't need to have it uh there's nothing to return at this point. So you can actually remove it and leave a blank space. Removing does not mean uh you you I if you would just remove the comma comma and the space you'll actually get

an error. You need to have it. It just means that yeah I know that there's a return value. I just don't care about it. That's all. And then again uh there's a require statement that actually ver uh you know checks if the transfer went through or not. These are the three ways in which we send. how have we done for our contract? Okay so usually it is a much safer uh call the low-level call is actually a much safer way to handle any transfer of functions.

[Music] We sometimes call it pull pull request rather uh let let me explain what is a pull and a push. Pull is when you are a uh you are uh the owner of this and you go and withdraw the amount that you want. That is the owner comes and calls this withdraw to get their balance to their own uh address. But there's also another method of doing this which is called as push.

Usually push is not um widely used because of security constraints that it consumes a lots of gas and could lead to DOS. So push is let's say you are the owner of this contract uh and by default the contract will transfer to you directly. For example, in case of this transfer, what does it do? It payable of message. sender is whoever is calling this contract and it just transfers to that person. So you can also modify this to be uh directly sent to the owner.

But the point is push is when the contract directly uh sends you the transfer. You don't need to go and call a specific function or do anything. For example, uh earlier uh when airdrops were starting out, you wouldn't have to go and click on claim to actually claim your airrop. it would automatically I think they don't know what is they don't know what is an airdrop I guess oh okay adrop uh is when uh a any any project could actually have a token generation event and they would have some tokens. So

whoever participated in this community in uh you know their protocol they would actually the protocol would actually incentivize them and send them some of the tokens when they actually launch. So that is called an airdrop. During the earlier version during the initial years the users would just try out the protocol and the protocol would actually recognize and and air drop them directly to their wallet. they wouldn't have to go claim their ad drop. But now uh since that actually leads to a lot of security issues. Now you have to go and uh maybe check if you have an adrop and you have to click claim and it would be uh like

it's a pull that is uh the recipient is actually pulling that from the contract. it is not pushed that is the the protocol is not directly pushing it to you to your wallet. So that's the difference. So in case of pull you always prefer call and even even in that call I would say uh usually it's much better to have something called a re re-entry modifier. So what you will learn it in the next section but a quick recap is when a transaction goes through until it is fully complete nobody can come in and

interrupt that transaction. That's that's a very oversimplified way of seeing it. But just remember to use call in most cases. uh that would be best for a lot of security reasons and this is just a summary of when to use what you can take it as a guideline and do not like blindly go for these uh whenever you have a contract or when you design something choose according to your use cases this is supposed to provide you with a grind line but not a very hardcoded way to go about

it. Next is the modifier. Okay. So how if let's go over and write the syntax here so that we can better understand it. So what happens here? We have bool that is actually our keyword. We should always have bool and call success. They are just uh assigning bool uh you know a variable name to bool. That's it. It's a variable. We just store whether the transaction was successful or not. And comma we are just ignoring all of the return values that would come from this because we are just sending ether. We

don't want any return values or we just don't care. And then whoever is the recipient. So here you see message dots sender message dots sender is whoever is calling this particular function is the message dot sender uh they are the immediate next person before this interaction that's how I would define it so message dot sender and this message dot sender should also be wrapped as a payable let's say it was not message sender let's say it was I don't know uh maybe it it it was owner and we already had owner variable and

the owner was if you don't want if you actually don't want to uh you know do this you can actually store this message dot uh sender as an owner and that owner also as a payable it would be something like oh here we at here we have address public owner right so you would have address public payable owner that's it you you would just wrap it in the state variable itself so that you don't have to deal with it later but since we didn't do it there here we wrap it up as message dot sender dot call that GAN is the keyword

you can't change it then you assign the value. This is again the keyword and what does this mean? Address of this dotbalance. So address of uh okay first let's come from here dot balance is straightforward. It's the balance of something right? Uh so it's a predefined one but this h this is actually a sub syntax. So dotbalance before this to whoever you want to see balance or to whichever contract you want to see balance you would just put that contract address

dotbalance but we don't know the contract assuming we don't know the contract address of this to simplify we just put address of this dot balance so address of this contract because this contract is what has all of the amount that was sent to this creator. So address of this dot balance and we're not calling any particular function. We just leave it as empty. Question.

Is the empty string part of the function name? Um can you please mention which function name? I'm not quite sure I got the question. in call. Oh, this one uh no it is it is not a function name. We just say that there is no function name. We are not calling any function. We are just sending value. So we just ignore that part and leave it empty. That's it. Does that answer your question? Okay.

All right. So, and then you have uh another statement of require where you actually check if the call actually went through or not. We already know this. Now over to the next part modifiers. So here all we are just uh if if you actually look at this there is no permission of who can actually withdraw. But how do you want uh let's say Solen actually funds this contract as well and she also wants to withdraw but I'm the creator then that would be a problem right I if I'm the creator and Solen is sending to me I want to be able to withdraw it since I am the creator and the funds are all uh getting accumulated

in this contract so only I should be able to withdraw so essentially if you think of this it is like uh someone is actually like the owner of this contract and only this owner should have certain permissions. In that case what you do is you in uh you you can actually have it as require uh some statement checking hey this if someone is calling this withdraw function um it it's not open to all so I only want to restrict it to her whoever is the owner so what you do is you include a statement require message dot sender that is whoever is calling the contract

equal to equal to. So single equal to is just setting that is you assign owner uh to a particular variable but we don't want that. So we have double equal to which is you're checking if this is equal to this. So you you actually check if message sender equal to equal to owner. you already have this I owner variable in here. Uh okay. So I think we should go with constructor first and then come here. Okay guys, let's first go with constructor. So we need an owner. Ideally uh the person who is

actually deploying this contract is going to be the owner. That's that's an assumption. If I'm creating an app and I want to withdraw from money from it, uh I I put my name as I'm the owner. What uh uh you know in all different programming languages we have constructors in all oops it's exactly the same. That is a constructor is also a function but unlike other functions you don't have function and a function name or nothing like that. you just put it as a function. Uh you just put it as constructor and there is no name for it.

Whenever a contract is deployed uh the con the constructor is the first function that would be called and also when the contract is deployed immediately on the same transaction itself the constru whatever whatever code is within the constructor will get executed. Okay. So how can we use this to our best uh way that we want? If I'm going to be the owner of the contract then when deploying itself, I can just assign that uh I am the owner of this contract, right? That's that's a very straightforward use case. Let's think

about what happens if uh that there is no owner of this contract and let's say this statement is not there at all and there is some other uh function let's say function assign owner let let's just imagine this function is there and anybody is able to with you know call this if this statement is not there and I deploy this contract contract then somebody who is you know who who actually wants to take over this contract before I call this function after deploying this contract before I call hey assign me uh the ownership for

this contract before I assign it for myself somebody could pay example very high gas overtake me and come and call this function. So if they do then the ownership would go to them right you don't want that to happen. So this is what happens when uh you separated between two transactions. So ideally any access control is usually assigned within the constructor itself because it is uh going through in the same transaction that the contract is being deployed. So we have this what happens.

Look uh here it's a single equal to. That means this is a constructor. Who is calling the constructor? I'm calling the constructor. So message sender is anyone that is calling the constructor. That person is assigned to a variable. So we have a variable in here. Address public I owner. So to this person you you don't give any explicit permission at this point. You're just saying hey whoever is calling that contract save their address and uh and assign it to I

owner. Now how can we use this uh in our withdraw function? Uh we saw that you're checking if if I'm the owner I should be able to withdraw. If anybody else withdraws, it's going to revert. That's what this statement means. But let's say uh you're using this in and this statement is being um used in any other use case. We we also had something uh you know in our example like uh function uh assign owner, right?

So if I don't want to be the owner and I want to transfer to Solen after this point. So only I should be able to do it because I'm the current owner. In that case what do you do first? You take the statement and you would insert it here because only you should be able to transfer the ownership from uh you to someone else, right? So you you you would actually uh not allow anybody else to call this assign owner the same statement that you had for withdraw. So essentially what what is happening only one person is

here and you're giving certain access control only to that person and you you're also checking that before they do anything. So it's kind of getting repetitive at this point. you're having the same request statement here and another same request statement here as well. You can actually simplify this by something called modifiers. So here we have the code of modifiers. What modifiers does is any statement that is within the modifier usually gets executed first.

Let's just remove this for now. In a modifier, you you actually can have the same uh it actually has a very similar syntax to that of a function that is like modifier and you give it a name with a parenthesis and inside that you can have certain statements. In our case, what do we do? We just take this require statement and we just put it here so that uh we actually can check their ownership. You know one of this is enough. Let's just forget about this.

You just check if message dots sender is equal to equal to owner. Okay that that's the only thing that is here. And then you take this modifier name and use it to any function that you want this execution to takes take place. So we just remove this. You just have a question. Defio just reduce. Yes, it does reduce the uh redundancy. That's the primary goal. You can actually uh cleverly use this to uh have certain restrictions of who can own certain

uh powers as well. That that's one of the primary use cases but it was primarily brought in to reduce redundancy. Okay. Where did he leave? Okay. We have owner. Okay. So you specify this modifier name in whichever function you want to use. So earlier we had uh assign owner. So same thing would be here. You just take this modifier and put it right next to it. That's it. So when this uh when when this function executes it would start line by line.

when it sees this modifier what it does is it'll go to where this only owner code is. So it'll come here and it'll see hey first step is it will see where this underscore uh semicolon is. If it is here, what it would do is first it will check this uh you know it will first execute this statement and then it would go uh continue with whatever is within the function. If let's say this was here, what would happen?

The same thing uh the function would be there. When it comes to this line, it would go to this part of the code. See that there is uh an underscore. But hey you don't have to do anything right now. So because uh this underscore is at the top and there are no statements preceding to it. So it will just hold off in here. Go ahead execute whatever is within this. And after that it will come back to the modifier and it will execute everything that is uh below this underscore. So essentially uh the way you use

underscore will actually determine at what point you are executing whatever is inside the modifier. So if you have this require statement uh here uh I mean below the underscore after going through the whole process it will come back and execute it. But if this underscore was here when it comes to this point it will go see whatever code is there it will first uh execute this code and only if that passes it will go on and execute the remaining code. Hope that was clear question.

Okay. Is the required statements place matter because if it fails state changes rewards? Yes, it matters. Usually when you have any kind of checks that you have uh when you use require statement most most commonly it is used for checks right before executing any function is when you actually want to check. You don't want to have those checks at the end. You can I if the uh you know if if it is going to revert it would revert at the end but what's the most efficient way when you have request statements checking it at the beginning uh you you don't execute the remaining at all so

you're actually saving a lot of energy right okay and okay this is the syntax of modifiers you have the modifier name and any statement, that, you, want., It, it's it's not a rule that you should only have require statements or any checks within it. You can have any type of code within this modifier and that will get executed. Uh don't restrict yourself to only require or if or custom errors or anything. You can have normal statement executions as well. It's it's a design decision that you take. Uh if you want

to have if you have certain parts of code that is redund then put it under a modifier. uh if you want uh it to go through if if you want a function execution to go through only if it meets a certain condition then it's best to have uh you know require statements or if custom errors within uh modifiers. Okay. So modifiers also can take arguments within it. And are modifiers necessary? Yeah. So they're not necessary but they do improve. You can actually uh still work having this

require statement here and the same statement within in other functions as well. It's just easier this way to not write repeated code. And we saw the constructor and you know constructor is easy. Let's go over and see how we can run this. Okay, I made a lot of changes. Let's Okay. Okay. So, a few things before you start with your test net deployment.

First is get uh you know get your accounts with MetaMask or any other wallet service providers. then go and get uh some ETH for yourself. Since our contract is entirely dependent on ETH you don't need any other uh tokens just ETH since it's Sepholia. Uh so there are different test nets that are released uh based on different versions. So Ethereum Sephogia is a very standard one and is wellmaintained. We are using that test net. You can use any faucet. E- global.

If you are a e- global hacker, you can go to e- global.com/faucet. If you don't have an account, I highly recommend creating one. It's a great platform for hackathons. So, if you have an account there, you'll be able to claim one ETH per day, etc. So, you will have ETH. So you have an account, you have uh plenty of ETH in it and you open your code in Remix and always check the environment here. You see um if you if you are just executing your code within a virtual environment, you you just choose Ethereum, you know, Reinix VM Prague or Canon or anything. But if you want to

use a certain test net with a certain address that is your address with your test net then you have to use this uh inject provider and choose here we I only have metam mask if you have any other wallets it will show that name you just click on this and um also if you uh while doing this if you don't see a deploy button that turns uh orange and it is grayed out something like this then always check uh your uh extensions.

If you have more than a few wallets enabled and they are also active sometimes remix might throw an error or might get confused of which uh wallet you're trying to use. So it's like an case you know H case if you do face that check your extensions disable the rest of them except Metam mask and you'll be good to go. just about uh the foretling that uh is related to is global you can get access to it uh if you don't participate to is global aon before so when you will do it when you will participate to it you will get access to

it yes great okay let me share the link you will get uh now two but you won't get one e as you progress press and hack more your limits will increase. For now, you'll get a minimum droppings. Okay. Uh so all of this is set. Now go ahead and deploy your Okay. First we have to compile. We already did. Now we come here. We check everything. And here Yeah. Uh check if you're choosing the right account. So here we have F 0F something. Let me

check again. 0 F. Okay, deploy. You just confirm uh you know the permissions. Okay, it got deployed. That's it. He actually did it.

Now, uh so I want to fund it. Let me check what's the minimum. Okay. So you see I just clicked on minimum but no metam mask popped up. That's because these are all read functions. That is they don't require any gas to just see certain values from the contract. If you come here what is the minimum USD? Here we have minimum USD as a state variable.

So for all state variables by default there are getters created here we have owner and we have minimum USD. So for just reading certain values which are uh in the state you do not uh need to pay any gas you can just read it. So, it's five. It's probably how I don't know seven or eight.

Oh my Okay, let's go with five itself. And uh you just uh enter the value. Okay, we are going to fund this contract. Uh it's a payable function. So, always you have to enter what value you are sending into the contract. So, here I put as uh 5 0 0 0 which is which should be equal to or greater than. No, they were estimated gas invocation.

No, I did have plenty of gas. Today we got some issue like this.

Oh, not sure why this is happening. How did you resolve yesterday? Uh I think yesterday it was related to um just injected provider something like this. Um like did you cancel um you cancel um a transaction or anything like this where the transaction can be stuck and then you can proceed to any any other one.

Mhm. Okay. Maybe reload like rael reload a lot. Um um okay. Okay. Oh, sorry. You can reload remix. Oh okay. Did that yesterday like um completely re reload? I don't know how we Yeah. Yeah. I just did reload. Okay. Meanwhile, we had our contract deployed and this is our contract. Uh usually now you see a bite code but when you use uh any any other

frameworks other than uh remix you would actually be able to uh verify your contracts. That is when you put your contract in here you can um so you see verify and publish here right so you will be able to see your contract code itself in here. Uh we'll go over that in our foundry session, but just remember that uh to save your contracts. Oh okay. Ah, yeah. And she put something like um with the exponential uh check check the the chat.

Okay. Oh, like that. Okay, we are going to have to deploy it again. Compile check provider. Okay. Yes. um creation of fun pending because if if you can uh close remix and open a new a new window.

Uh okay. Actually transaction went through. Okay. Nice. Nice then. Okay. So you want me to enter as value in ether? Uh yesterday it was in way nah I think we have to enter value as such only.

Okay, let's It's okay. I think I have enough E. How much do I have? Oh, I have plenty. It's okay. Let's go with one ether. I'm very generous. Click on fund. And yes, transaction is going through. This is going to take a little while. Usually, uh test net transactions are quite slow. It takes two to 3 minutes on average but on mainet you would not face that uh the transactions are near instant. Okay here our transaction did go through. So let's check who are the

funders. Okay. So I sent the transaction and I'm checking who is the funer. Why am I putting zero? because here where is our array? Okay, here funers array is where all uh all all everyone's address whoever sent is being stored and since it's an array the index starts with zero. So the first person who sends will be on the zerooth uh storage slot and the next person uh the the second person who sends will will be in the first storage slot and the third will be in the second and so on. That's why it's zero and not one that it begins

with. So this is me and we'll also check to my address how much was sent. So we see one ether was sent. Okay since I use the same contract, I'm also the owner at this point, which is not very typical way to do it. But let's go and try withdrawing. Okay. We have any question?

Yeah. Any questions? Great. And it went through. Oh, not this contract. Always uh store your contracts. Sometimes when you deploy uh if you just close the terminal or uh in this case if you close remix and you reset next time you come if you reset your uh remix by mistake then you're not going to get this address. So whenever you deploy immediately copy and save it somewhere save. So you can go to sepholia.ecan uh just don't uh forget and go to the

regular etherscan this is sepholia do etherscan this is only for testn net. If you go to the norm if you just search for ether scan in general on Google and go from there then you're going to go to the mainet one. We are on test net here. So if you see first we tried to fund it and it went through with one E and we also withdrew the amount and the amount okay amount is 08 that is no maybe I'll check the balance [Music]

Oh, this was a transaction. [Music] Okay. Okay. I was able to withdraw. That is not right. Why is it [Music] shock number all is

okay? Um, okay. There might have been some mistake in the code. What did we do? We did fund it and we did withdraw. What was the Okay, we sent 18. Let's call it again and see. It has gone. So I think uh it's because okay one E did go but when I withdraw there was already some uh little bit it

was a little bit less than 18 that I withdraw because uh this transaction fees gets subtracted from the amount right and this transaction fee also gets subtracted from the amount. So any decimal point value that starts with zero is shown as zero. That's why our code is correct. No worries. So that was it. How did you find it? Maybe use a conversion state. Oh yeah. Yeah. I will use it from now on.

So she's stuck and uh please don't get uh so you know carried away by uh the zero e it is because it is in decimal you you paid transaction fee so you don't get exactly the one E back because from the contract the transaction fee gets subtracted so you will get something like 0.99999 since the uh since we eat The ether scan doesn't support decimal. It shows as zero. But in your actual address, you would have the same e. Okay, that's it for today's session and our next next session, let's

continue with uh errors and fallback functions. All right. Uh thanks for that um being clear., Uh, and, yeah, I, I I think you you and you reply to all question, well, so, thank thanks, for everything and let's capture tomorrow. So just about [Music] um what you have to do for tomorrow. Um so basically let me come back to the notion. So complete uh lesson 20 from section three. So it was for today and for tomorrow is complete complete

everything complete. Yeah, it would actually be so much easier if you actually completed that part earlier and you just come here and it's a recap and you you know get your doubts. I think it's the best way uh to to learn is like to uh start with siphoning um the courses and then after that get a recap an entire recap with the session and where you can ask your question if you have anything um that you need to go more deeper in and yeah thanks again and uh let's say see you tomorrow. Yeah, see you all study well. Byebye. Bye.