Transcripts
1. Introduction: Hi, everybody, and welcome back to the fund project course. So in this course, I will provide you
the solution of the challenge project in the SMAT contract course
for complete beginners. So in this course, we learn
new concept like payable, also the receive
fallback functions, and also the struck
of the project is we are going to create the fund
project, all those steps. So creating the project, also, sorry, creating
the contract, also those functions
fund and withdraw the modifiers and
receive back functions. Then we are going to
move to the Remix to test all the functionality
of this project. As well, we are going to
deploy this project to the Sepula Disney and use it live in Supolia SCAD.
That's it, okay? Let's go back to the visual studio code
to create our project.
2. Building the Functionalities of the Project: And then if that's true, we send the funds to
the to the owner. How's that going? We
have three functions. Transfer functions. It's it. Transfer And send and caught. The difference between
those factions transfer, it's send the ether funds
to the destinations. Otherwise, revert. Send, it's the same
thing. Send factions. And call, it's different. Send the funds to the
destination address. Otherwise, return
through or false. Which means, if the sender
received the funds. Oh, sorry, if the
destination address received the funds,
return through. Otherwise, return false. Which means not revert
to transactions. That's it. Call is low level.
Factions. Okay, let's use. Call. Okay. Who can receive the faction the
fans? Of course, it's honor. Yeah, you have to
do it like this. Payable, honor. But we specify in the
declaration here. Okay, we market this one
payable, so we don't need this. Because the destination
address have to be payable to receive the fonts. Call specify the value. In this case, it's address, dot, this dot balance, which means balance of the
address of the contract to send the contract we called the core is the fandom contract. Which means the balance
of the contract. Address this always
is the contract. And that's it. This one, you can put some data if you want to send some
data with the funds, maybe like here. That's it. This misunderstood.
Tows leads ENT. But as I said, its
return true or false. Imagine if the
destination address not receiving the funds, and the transaction
goes through. So the fund is gone. In this case, what you revert? The transactions if the misunderen if the
destination address not receiving the funds. So what we will do, basically, we add some
bulling hair success. As the call returned to us. We require her. Okay, I success? Okay, move on. Otherwise,
Charles, fair. Faith. That's it. And let's reset the balances. Okay, let's have
to create a book. A L equal. Sandra that's it. No len. We store the length
of the Sanders, which means how many centers
you have in length variable. Okay, four, four. The initial is equal zero, then I less then. Then I plus plus equal rims. And then this address
Sander and Sanders I basically delete
the balance this and this And let's delete
this center in the array. How to do this? Basically,
we have the array. One, two, three, four. That's it. So here
is the first dex? These the last andex. What we do? Basically, move this. We want to
delete this one. To the last the last index and call pop actions to
delete the last one. To cin the length of
the array. That's it. Sanders the last one is lng. Minus one. Why? Because
length is starts with zero. Minus, yeah, one. Then there's always
starts with zero, so it makes sense if you
have to minus inter lento. Why? Okay. Maybe this is not confusing
but I will explain. We have five students. Zero, one, two,
three, four. Five. The length is five.
If the last one here is dex, four, not five. That's why we minus always one. And equal senders. This one. Hi. And pop that's it. Pop, which means the
lead the last of the lid, the last element. And that's it. I hope
this makes sense. Okay, C five is at modifiers. Okay, let's at modifier. Modifier only honor. Okay, here. Modifier only honor only model. Only honor. That's it. And let's copy paste. Is. Mm hmm. Is it. And the rest of
the coat is this icon. And let's implement this
in withdraw factions. Here it is. And that's
it. It's the same thing. Five sub six is implement receive and
fallback functions to handle direct ether transfer, as I said, receive
and fullback is a functions trigger once a contract receive
funds or data. Receive just trigger once the
contractor receive funds. Fund Ether binus also. And fullback trigger if the contract receive
ether or data yeah. So let's create those functions. Because if Sam sender sent
the ether to this contract, and this contract has
not those functions, so the ether will lost. And the contract not
receiving this ether. That's Okay, receive that's it. Is it? Okay, it's external. You have to mark it external. It's payable and inside. So the logic we
want to execute was the contract to
receive some ether is called the Fant factions. That's it. To add the sandal to
the sander arrays and to the mapping balance.
Okay, that's it. If you receive it's enough, but let's add fob swag. External. Payable. Yeah. Okay, bonus step seven, deploy this in upoant is it. Before that, we are
going to deploy first in remix virtual machine to
test all this functionality. Then we move on to
deploy in Supoaate.
3. Complete the Project: And the solidity
course and exercises. Here is the final
funding exercises. Let's open up into the
visuals you could. Okay, here it is. It is the final project. So just Okay, eh? Closes window. Okay, fund me projects. Steps. First step is create
the fund me contract. Okay, start the common PDX PTX, lags identifier. IT and specify the pragma. Virgin's more above
the zero.eight.36. That contract Kor KO. Or cats. Okay. Step two is
create honor the honor. Basically your honor.
The honor is address, and it's payable, which means can accept the funds payable. And also, it's immutable, which means cannot
be changed to honor. Once you see the honor, so this variable is
constant, imitable. Ichangeable honor. That's it. And another variable
is the M. Okay, N 2056, it's constant as well. Constant. Yeah. The why we mark this constant because we
mark this one constant because constant is lower
gasps than normal variable. Okay, meant. It's stored directly
in the storage. Mineter say one
ether, for example. And the mapping. Okay, array. The array of the addresses
the Sanders array. Okay, it's public. Let's say
Sanders. Also the mapping. Okay, address to the value. The balance of the senders. Okay, it's balance. Bass. That's it. Okay. The owner is
who deployed this conduct. So we see the owner
in the constructor. Cs what Constructor. That's it. Owner. Equal? What? Who called the constructor?
Always it's the owner. It's the missile
to Sander Sander. Who deploy this contacts? That's it. The admin
of the project. Okay, constructor, that's it. And what is the second steps? Okay, honor and mean
contribution and Constantine. Step three is fund. Fund factors. Z Okay. And and Okay, first, let's write the
night spect. Okay. Is functions?
Factions. To? Hello. Two deposits. Two deposits. And me contract. And that's it. This is the thief. And uh parters. Retal ters. So tox. Okay, functions. And it's public, but we are not going to use
this and I win to contact. So this market external. Why? Because external
is low gas public. External. That's it. And just contact
receive the ether, which means it's public.
Sorry, it's payable. Payable L and and
and and and and and the amount the cinders sent should be great or
equal to mid either. So it's added require. If mess the cinder, that values and the
value is less is great, or equal Meight Okay. Move on. Otherwise, reverts not enough. What. Okay, and then add the
sender to the arrays Sanders sanders dot push
the message dot Sander. Yeah. And also added
Mapping palace. Or balance mapping.
Okay. I don't know. Balances. Yeah, specify the key, which means the address. In this case, it is Mr.
Sander. Equal what? Equal the value. Mr. Dot. The value. That's it. Okay, we finish this one. Let's move on to the next
step. It's step four. Withdraw facts. This
withdraw is only honor. Can call these functions. And once the fans
send it to the owner, so we recite the bans. Mampon. Okay. Factions withdraw. Okay, basically, the expect
these these factions. Four, withdraw the balance of the contract to the other
withdraw that six poet. No. We draw. We're not going to
specify the amount because we want to
withdraw all the funds, all the balance of
the contract. Okay? Of course, it's external. It's not payable. It's
not. It's not peer. And we add acquire. Why? Because only
honor can call this. Misses Sander, equal honor. That's what we want. Otherwise, not honor. Only honor. Can withdraw. It's Soly. Withdrew the bass. That's it.
4. Add Bonus & Test in Remix: So we are in the remix and we have to do some
updates to the code. Like, for example,
he's an error of this one and receive
and fallback. He said, The font
is not visible. Why? Because font functions, we market external, and we
call it within the contacts. So we have to market public. That's it, okay? Different number of the companer than the right hand side too. Yeah. Okay, that's it. Yes, y. Here we have two uteral because the call functions two
variables, Bullion and data. Bol valid. Ocean salt vari gas. Okay. Value. Okay, that's it. What another error. Yeah. This one is really aftermarket payable
because honor is payable. Change just to payable. And chick Max. That's it. So no, to this one, we have to make another update. Healon and this is work to
delete every time element. Basically, another
thing you can do. Just let real rotuff the sender. That's like this. Sender
equal new address Brazil. Okay, another thing
like this add a function to return
the top contributor. So in this case, we have to declare an address. Address. Okay, it's
nomal address, public or private spots private, top, C picture. Another thing, you
went to the six. Same as well. Mm hmm. Bottom parts. That's it. Okay, in the fund. Let's compare this
one balance sender. What Sender. Me the up balance. It is true. And here we
have to add this one. Because if a sender, call the fund and then
call the fund again. So we store the previous one and add the new
one, new balance. Okay. Tack, tack,
tack, it is one. Okay? Pop, let's store the Sander balance
to the top one and the contributor to the miss
Sanda to the top contributor. That's it. Okay, at the end, we create function,
get top contributor. That's external. That's it. Return that's it, address undertreTp Contributor. That's it. Okay, let's compiled
successfully. Because this auto compiler, let's deploy this one. Spl it. Okay. First, this guy here. Call this version.
But then ether. With ten ether funds. Transactions goes through, and the balance of the
contract is ten. That's it. Another
user is this one. Call with Blitz 55 ether. Let's call the funds. Transactions go through,
and the balance is 15. Okay, let's get the top. We expected the first one. Okay, let's say zero, it's a B eight, four. It's not this one? Okay, it's this one.
Look, it's the same. Why? Because this deposit more
ether than the second one. Okay. Sand let's say Sender one. Zero zero. First one. Okay, it's the. Mm. There's the map. Let's make the map in public. Okay, let's do this
one. And diplo it. Okay. Balance is zero. So
this guy deposit, let's say the same t,
and okay but is ten. Another one is this one. Deposit Well, it's a
five, and that's it. Okay. The top one, the first one. Let's say others. Okay. Let's copy as it here, let's copy the top one
to get the balance. That's it. Okay, the
parens is ten wei. No. Ten ether. In this case, it's let's say. It's gars say ether, too we.Oh wait to eat? Where Hiza. Lada Who am I. Okay, it's t. That's it. Is it? And another
stat is zero Cener. Okay, is this one. One is the
5. Deploy on Sepolia Testnet & Test Receive/Fallback Functions: Okay, let's deploy this fund
project to the SupolaTsNt. Okay, here we go.
Let's delete this one and injected meta
mask, Tara Pola. And let's deploy. Transaction. Let's
confirm the transactions. What? At fee, Margaret. There is no insufficient
balance, okay? Let's add some
Sapolia to my wallet. Basically, supolia faucet,
SapoliaFaucet, there. Okay, recei boolia, yeah. And let's copy our address. Copy this one.
Just receive some. Do it provide automatic use? Please verify your wife ads. Let's take a few moments. Okay, let's
transaction slow slow. Let's check our wallet. Okay. That's good. Let's
go back to Dreams. Redeploy. Create or fund pend. Yeah. It's firm. Okay, the transaction
goes through. It's confirm it and the
contract is deployed. Okay, it's this's one, but, me. So let's change just to where. Okay, this is not going through. Why? Because the
minimum is one ether. And in my wallet, I have just zero about 00. Fortunately, is chill
see, it's mainly one. At least delete this one.
Yeah, through the point. I hope this go through. Okay, yeah.'s confirm again. And keep it in fund. And then that's it. Okay, the primer, let's add two way B confirm
the transactions. Anytime you want
to add something, update the state
of the blocking, you have to pay some fee. That's a takeover in
the transactions. Okay? As you know, blocking is not
fast, so we have to wait until the
transaction is confirmed. Okay, that's transactions.
It's confirmed, but the balance still is zero. I don't know why.
I don't know why. Why? Because this is
A, okay, it changes. Oh. 00.00 00002 ether. And basically, it's two way. Okay. Okay. It's, yep. Okay, the top one. Call. Okay. Amex doesn't tell me
to confirm the transactions. Why? Because this is
just a view factions. So I don't have to pay some fee. So I don't have to
confirm the transactions. And that's it. Let's get the balance of
my balance, my. Okay? It's two w zero sender. Okay. That's it. Okay, now, let's withdraw
this transaction. Okay, this account I
have just one address, that's what Cl's. Of course, I have to
confirm this transaction. Let's update the
state of the block. Okay, I confirm
the transactions. Let's say the balance should
be zero of the contract. Let's see. Okay, we wait at
the transaction, it's confirm. Is it transaction. It's confirm, but
here still zero.000, blah, blah, blah,
blah, blah, blah. Yeah. Okay, it's zero. Let's check our account. Yeah. It's cheese.
Okay, as you know, just it's 02 way. So this is not you cannot see the difference
here because this is ether. Yeah, it's Apulia ether. So this is so much. Okay, that's it. Let's
say this in the Supula. Mm hmm. We transactions Kat. Get in smashed. No, no,
no, no, no, no, no. No, no, no, it's not this one. It's not this one.
The second one. Yeah. Second butts this Okay. Here's the transactions.
No, this one. He's transactions. Our contract. This check. Okay, we draw. We called the fund
first by this guy, which means me then By we. Okay And then withdraw
this gets zero. Yeah, okay. I withdraw transactions, this
contract sent to this guy, which means I get me to weigh. Okay, let's go back. So check another one. Okay, let's change
this, this one, and let's reply
this one to check. Okay, in this case,
this is the honor. Let's say if another
one can withdraw the funds by calling
the withdraw factions. Okay, let's do this. Okay, okay, okay, okay. This one. Mm hmm. Deposit. Let's see,
one Okay, that's it. And, uh. Okay, let's see. Another person wants
to withdraw this. We expect it. Transaction
should be reversed. Okay, it's reverse. Why? This is reversed. Okay, so only owner can
withdraw the balance. That's it. Okay. Let's say
if there's another factions. One to check. Mm hmm. We'll cheat this one. Okay, now let's test
the receive functions and feedback functions.
How to do this? Basically, we are going
to send some funds to fund me Smart contract without calling fund factions directly. Okay, let's do this. Okay. As we have in the
balance three ether. Let's withdraw this
with the owner. The owner is this one.
Okay, withdraw all this. Okay, the fund is zero
let's delete this one. Prepare understand. Okay.
Make sure those fractions, receive and fullback
fractions has the same code. Okay, you can put any
code inside those. Okay. Basically,
receive is three gated. The ones. Yeah, you send a fund
to the SMAT contract. And this one full back. To girls, you send data with fans or just
data without funds, data. Data. Okay. Now
here called data. This button, we use it to send some data to the
smart contracts, remix. Yeah. Okay, let's choose
user, this one. Let's say one ether. We click this one without clicking the fund and functions, this one, which means external. Okay. The transactions
is go through. How basically fund
and code C factions. All the balance is increase. Then we are going to collet. It's two with some data. At the same time,
the same thing, but triggering the
full back factions. Let's do the same thing
without funds. It's reverse. Why? Because, okay,
there is a message, enough because in
the fun functions, there is a require to compare message that value
with me and zero is, of course, less than me. It. Okay. Let's say, let's redeploy this one. Okay, delete this one first, and delete those and try to
send some it to this contact. Okay, deploy this one. Yeah. And the pm here and choose
another guy, this one. Let's say one
ether, for example, transactions A, this is just
for creating the contract. He said, Okay. In order to receive
ether transfer, the contract should have either receive or payable
fallback functions. He said, Okay, this contract has not receive and
fallback functions. So the contract cannot
be accept this money. Does it okay we finish here
and see you in Camil course.