Transcripts
1. Welcome to Solidity: Your Journey Begins Here!: Welcome to the ultimate
Solidity Smart contra course for complete beginners. In this course, I will guide you step by step
to take you from zero to kick start your career
as a solidity developer. So, that's diving. We will started with
the fundamentals of solidity, like
variables, functions, and arrays, and then
we are going to build a small project
like a calculator so you can practice what we did. Next, we are diving into intermediate topics like
mapping, strap, loops, and modifiers and
then use all those in a letter complex
project class booth. Class Smart contrast and deploy
all those in SupoyaTsNt. Then we are going to the advanced topics like
require statement and events. So you will learn how decentralized applications
like Opens talk to the blockchain and
get the updates and the real time words
using solidity events. We will also explore
the inheritance and how to contract can talk together using something
called interface. At the end of forces,
I will give you an exercise challenge so you can apply all everything you
have learned in this course. Okay, it is dived into the
world of blocking development, CEO and the first lessons Sala
2. What is Solidity? Unlock Its Power to Build DApps: T. Solidity is a
programming language that creates mad controverst and instructs them
how to behave. That's it. And the life cycle
of SMAT contract, first, we create a code using solidity, a normal code and
compile it to the P code 01 and then run it on EVM
Etherium Virtual machine. Okay? It's basically
a server that creates your code that run your code. So, what can you
build using solidity? Actually, Amazing things. First, dabs. So what is deps. To better understand dabs, I give you an overview what is a traditional
applications. In traditional applications
rely on a single, a single entity or organization for their
functionality and data storage. And that's create what's
called centralization arrays, which means if the
server goes down, so the data is lost and
the application will fail. Or if an attacker
hack the server, so he gets the fell access to the network and stall the data. So that's why we transfer it to the tabs, decentralized
applications. So decentralized
applications store the data in multiple nodes into the
blockchain around the world, which means your data is safe, and if some notes goes down, the data will be safe because multiple Nuts has the same data. And an attacker cannot
get the full access to the network unless successfully hug every nuts in the network, and that's nearly impossible. Another thing is
decentralized social media. Basically, it is a social media like Facebook, but decentralize. Another thing is DoS, decentralized autonomation
organizations. In Taos basically is an applications managed
by SMAT contract, not central authority,
which means the people, the members, create
the proposal. For example, say, Hey, please add this
feature into the app. And this proposal get voting by the holders and then if
the proposal goes through, so the holders create a SMAT contract and add
it to the applications. Opposite to the
traditional applications when the CEO or the organization decide everything and control all the decision of
the applications. Another measle things. That's the biggest one
NFT, non fungible tokens. NFTs is a digital asset. Create ownership of
specific items. That's it. And the biggest case of the NTs is digital arts also in games. So in games, the NFT
or the blockchain gives the players
the possibility to trade or sell their items. Of course, you can
create your Crypto, like theror bets coin, dash coin, et coin. And the good thing here, if you have, for example, a platform or decks, so you can create your own
crypto to your own platform. That's mazing. Actually,
in the coming lessons, we are going to create
our own stable coin. Okay, the salary. Blocking developer gets
around 110 k 250 k a year. And the solidity developer
get one get 120 K to 200 k. So let's dive into
the difference between Web two and web three. Okay. Web three. So before we three, user use the app, the applications like face and the application
store the data into a server and
somewhere in the cloud, so in the database. But a single server, which means another server
doesn't has the same data. But in web free, user use crypt wallet, which the wallet hold
their private key. And the wallet use DAPs,
decentralized applications. Then the application that store the data in multiple server into the block chain
around the world, which means your data is stored in multiple
server around the world, and you are the own
who control this data. So let's create our
first SMAT contact.
3. Hands-On: Building Your First Solidity Smart Contract: So we are going to Remix, the online ID for
creating Smart contact. Okay, RmxRmx Here it is. Okay, here is the
remix online ID. He gave us a beautiful interface to interact with
the SMAT contract. This the functionality,
and even deploy it into the block shehet Okay, there's a folder here. I was created. So it is solidity tutorial. Ok are going to
create another file, call it, for example, file. This icon for directory. These four files, okay? Let's say hello. Okay, dot SOT. Dot SOT is to tell the ID, this is solidity file. Okay. We start with a command called PDX, Speed x, License. Unify upper. Okay? T. Basically, this is to specific
the license, okay? Let's say IT, which
means open source, so anyone can clone
it and use it. You can use another type
like license or something, then the keyword contract
on dact is hello. Hello contract, okay? Okay. Strength. Strength.
Let's say head equal? Okay, high solidity. Kids in hair, does it? Yeah, he say Sears fine doesn't specify require
compiler version. Consider add pragma solidity. Yeah. This told me you have to specific to specify the
required version compiler. So in the solidity file, you have to tell the ID
which version of solidity want to compile your
contract. Okay? To do this, we write
Pagn Solnit t say. So it Okay, Tata. So after this, we
specify, so the ID. Hey, our contract, please
comply with zero dot at 26 version of solidity. And this and this one, it this version,
0820 says above. This one above. So for example, zero dot eight dot 29, for example, yeah, we
can compare it to it. And this icon have to
compile solidity compiler. Okay, I market auto, so let's disable this feature. We can compile it,
compile successfully. Okay, look at here. This is the version we specify to compile
our contact, Okay? And plus here, this and above. And this icon have to deploy
and run transactions. So for deploying our contract. Okay, here's the
virtual machine RMx. Okay, for testing, a block chain to test to deploy your data,
just for testing. Here is an account with a
fake ether to taste as well. And yeah, here we choose which contract
we want to deploy. It's a hello because, of course, we are just one. And click the bottom, deploy
the transaction go through. And here in the bottom, we have our contract. Let's say we have to
market this public. Obanoc and the point. No, you have to compare it and delete this
one and this one. Okay, here is our variable. Hello. Inside high solidity. So, congratulations. You create your
first SMAT contract. Okay. Don't worry. If you don't understand what is
this string, public? Hello. What's going
on here? Don't worry. We go step by step until
you create your bests, not just a simple
contract like this. Okay, let's back to
the presentation.
4. Solidity Basics: Variables, Functions, and Arrays Explained: So variables. Variable basically is a space
you can put your value. For example, this
is space, okay, in memory, and the cafe
is the value. That's it. Space to store your value. Okay, there is different types. Okay, there is an address, strength, bullying,
and you teach. This is the biggest one, okay? Okay, address, we start
with the address keyword, the name of address, and the address represent
an eim address. There is a two types of
address external hot address, which means the address of
wallet, the honor, the person. And the smart contract address. And why we need
the address. Okay? The address is very important in the Eastern Blockchain
to get the funds, get the data, sign up
to the applications. Many things you can do
using the addresses. And the string string. We start with the
keyword string, name of the string, and input. So basically, it's
just a string. Yeah, just a string. And the Bola, basically, it's true or false. You start with the ball
and the name of Bola, and true or false. Okay, integer, the biggest one. U integer variables. So integer, there's two
types integer and U integer. Integer accept negatives
number, and positives number. And the integer accept
just positive. That's it. How to declare, basically, win keyword and max
supply equality. The name of the
variables and the value. And here is eight, and
here is another one. You win 256. This is
the number of di byte. So the size and the memory Okay, if the number is small, so this number will take a
small size in the memory. If it's big and we don't know how this will
take in the memory, we choose a big size for. For example, eight,
basically it's eight byte. And 256 byte. Like, what do you
think one day is? We don't know. Maybe 1,000, maybe 2000 of second, of course. So that's why we choose
the biggest one, which is 256 to
store this number. Because if we choose,
for example, eight, it byte maybe one
day more than that, than the range of
you went eight. So there's a
problem. Okay, here, with time, the day is 86400. Of second. That's why
we started in this one. You went 256. Here's a table of
those because it's me, not just eight or 256. Okay, you went 88 byte. The range is 0-255, which means more than that, you have to use another
one, more byte. And you went, for example, 16, six bytes, 026 5535. You went 1802802,
blah, blah, blah. You went 250 602,
the biggest one. Billion or trillion
or what is it? Okay, that's it.
And sometimes you found you find just wet
without specific dvte. So in this case, by default
is the biggest one, which is you went 256. And that's it in the wins. I hope this makes
sense. It doesn't. We will see more examples
in the calculator project, as well as in the
classroom project. Okay, please always, always, if you don't know how
the number will be. For example, one day, one year, one week. You don't know how second
in one week, for example. So always, always choose
the biggest size for it. Because if you don't,
you choose, for example, a small one, like you
went eight. You went 16. We'll take in this, we'll take the max of this, for example, you win 8255, and then the
rest of this will gone. This is a problem,
a big problem. And a lot of developers
do this mistake. So what is a functions? Basically, functions
is repeatable task, which means, for example, we want to increment a number. So we create a logic sanctions. And every time we
want to increment, just call these sanctions. Okay? That's what is a
repeatable task. That's it. So let's move on to the struct of the functions.
Okay, basically. So if you have a
background in Java, create Python, any
programming language. Okay, it's the same. But if
you have no it's nothing. Okay, it's fine. We explain everything. Okay? First, we start with
the function keywords. Then the name of the functions, then we specific the type, the visibility and the
type of the functions. And the last we specific
the type of the router. That's so the
visibility visibility, basically we decide
is this factions, public, which means visible to everyone. Everyone
can call it. Contract itself,
external contract, another wallet, anyone can call this functions or private, we want to make these functions call inside the contract or in internal,
there is a mutual. So first, as I said, can be public, can be used
internally and externally. So, for example,
it at functions. We can call it internally
the functions, the contract, and external. So any contract can
call these functions, anyone any wallet can
call these functions. Or private private basically can be used within the contact. So if there is a variable, private or functions,
which means this variable or functions just visible within
the functions. So sorry, within the contact. So the contact itself can call this variable
or this functions. Internal. Okay, basically, internal can be used it within
the contract, okay, like private and other
inheritance contracts, which means within the contract, that's clear, but
other inheritance, not other contract, like public. No. Inheritance
contract. There is, for example, this
basic calculatorre. Okay, this add
functions is internal, and advance calculatorre
inherits the functions. In basically okay. Explain what is
inherent in camulons. Just here, see the
advanced calculator, inherit all the logic of
the basic calculator. And yeah, so there is a functions
here and subtract. Why? Because it's internal. And external can
only be accessed from external
contract or account. Basically, it's
opposite of private. So the ad function, for example, it is external, which means we cannot call it
within the contract. Just only external
wallet or other conduct. And that's it. So view
and per functions, view functions is functions for reading the state
into the blockchain, not updating the state. Just to read them. For
example, the Git functions, is just for the
value of the result. And the result is store
into the blockchain. And by calling these functions, we just display the value
of result. That's it. And per functions
and per functions. Functions is not for
reading and not for update dstcs not uplton
dstate not reading the value. It's just for some logic, independent of the
blockchre like, for example, at functions. Basically, get two variables
A and B, and router. They're additional.
A plus B. That's it. So A is not storing
until the bloing. No, it's locally, not
global. That's it. And those functions is for free. The Bloching but
updating the state, for example, add some
variable to the result. And this update the
state of the Bloching. In this case, you have to
pay some fee. That's it. Okay, array. So let's say what is an array. Array, basically, it is a
list of six. That's it. Like, for example,
a list of boxes. Every box has a data and
has index, the number. Okay, for example, box one, two, three, four, and so on. And there's an
array, for example, NAS, Victoria, Dan
and Harry Potter. The more important hair is the index here, okay? The index. This index is useful
if you want to access some data into an array. And the Adix always
starts with zero, like any programming language. Start with zero, not one, zero. So zero is NAS. One is Victoria and so so how to create an
array in SMAT contact. There is a several way to get declared an array
in a SMAT contact. First, we start with the type. Then it says string
address, bytes, and so on. So in this case, it's
wet square bracket, and it's public visibility
and, of course, the knee. There's another way if you
want to initialize this array with some data say calibraces. One, two, three, list of things. In this case, list of numbers. And of course, you
can pix the size. Which means, say, Hey, I want this I want
store in this array, 1010 elements in max. That's it. So in the memory, you create an array with ten with ten elements,
staffed with zero. Say all element initialized to zero and string five publicly. So this array accept five names. And took it element, an array, you say, there is an
array, the values. And here, every
values has an index. So basically, put the
index of the value in array and you will get the
value inside this index. But yes, function, get UN, I Public VU returns Ns returns, array, I R. And if you
want to get sorry. Basically, in return, you
have to specific calibrass which means I want to get full array and return
the N. That's. Otherwise, if you want to
add some elements in array. For example, array examples, this is a dynamic array. It can be sized, which means if you
don't specify the size, this it will osise every
time you add an elements. For example, first, it's empty, so one, one elements,
accidually. Add two elements, so
the size it's two, three, and so one. That it's opposite
if you fix the size. For example, in this case, this is a fixed size array. You win five,
public, fixed size. It cannot be resized, which means if this array
it's foul for example, there is five elements, you cannot add another one. That's opposite if you
declare a dynamic array. And try an element. Basically the name
and dot push value. Add a new element to
the end of the array. So for example,
it's like a pull. There is a body. Push another
one. Okay, add another. D tack, tack, tack, and so on. So you cannot add it
in center or bottom. And if you want to the function, get dynamic array length, the size, you want
to get the size. Basically, the name dot
length tin the leg. This is useful for
dynamic array, of course, because the fixed array that's
fixed so always get five.
5. Build & Deploy a Calculator on Sepolia Testnet: Okay, let's go back to
the remix or creating the calculator smart contact and practice all the fundamentals
of solidity variables, functions. Yeah, that's it. So let's create a folder,
name it. Fundamentos. Inside this, we create a
file called calculator, Cal That's it. And we go to the Tab
repo for this course. Okay, and use your name
Hussein page 2001, the repository ultimate solidity
smart contract. Course. And here. Okay. He's exercises,
solution, the rhythm. Okay, I highly
recommend to create this to boil this
calculature before we did. Okay? Where is. He is. Here's exercise and
solution. Exercise. Okay, let's copy this Okay. That's it. Okay, make a contra
Colt calculator, it is. Create results result
variable to store the result. It is as well. It's public and create
function to add, okay? Create add functions. Let's create this function. Add you went hinge 566, then when it's external. Okay, let's make it private. Private and result
equal result plus nine. Perfect. Here is the
first functions. You can create this line, change it like this without repeating the result variable. Just do this plus equal. That's it. Like Python and C
plus plus as well. Okay. And here's the compiler. Okay, it's auto compiler. Let's compiling as
well, and deploy it. Okay, here's the
virtual machine, the account, our
contract, deploy. Okay, in the param here, there is our SMAT contract. But just display the
result and not the add. Why? Because the result is
public and ad is private, which means add functions we can it's usable just
within the contract, which means we can
call it externally. And by the way, the public variable has Git by default, Git
function by default. Okay, and it should by zero. By default is zero. Okay, let's change this
one to public or external. Of course, if it's
internal as well, we cannot call it externally. So let's market external
and copy and redeploy. First, we delete this one,
remove it list and deploy. Transactions goes through. Okay, here it is. Okay, check
the result first. Mm hm. It's zero by default.
Let's at five. Transactions goes through. Expected five. Yeah, it's five. Congratulations. Okay,
let's add on the functions. Subtract and multiply. Function, keywords. S. Subtract went 206 external scores, results minus equal. Another one it's multiply. Toxic keywords, Milt,
you went 206 name, it'sternal and results
multiply equal. The last functions is create
a function to get result. But since the result is public, we don't need it
because by default, this variable has a get functs. But sometimes we
want some variable, we want it to be private, like password, username, owner. So that's why we change this
one to private private. And in this case, we need this one Git without
any parameter, external. External. Yeah. Okay? We
specify the return types. B, we have to
return this number. Okay, return. Returns
not just return. Returns win en because
it's the results. And return award. Ret Add results. That's it. There is a
warning. What is it? Is that function state, Vutability can be
restricted to view. That's it. Because these
functions basically it just to read some data in the block sheheet
not to update the data, so we have to market view. And this is not cost any gas. It's free. Reading and
blocking? It's free. Least deploy this one. The transaction goes through. Okay. Here is. Our function. First it's at five. That's it. Ts actions
goes through. Five. Let's multiply by two. We expected ten. Git. That's it ten minus three. We expected seven. Congratulations.
Seven. Now, let's deploy this in SepulaTNt. First, prerequisite. You have to install
the metask and stand the extension
extension in the crew. As well, you have to create
your account and get some thick money
SuplaFacet. To do this. Okay, I'm not going to how to create your account
and how to stand. Okay, there is a bunch
of retrisEplain how. Okay? And Sepolia SepoliaFaucet. To bit some fake money. Okay, so Okay, here is basically copy
past your address, and you get zero.05 Sepolieter. And once you have
it, let's buter. Okay, Batful, this one
is in the ether minute. You have to turn on
this show test network and choose SEPolia. Okay, here it is. Okay, let's back to the remix. Let's deploy this in real lock. Check it Mamask. Okay, here's pola here's the network, and
there is my others. Look zero X, three, four, four. Look. The same here. It's connected. Maybe I ask you to connect, just confirm the connections,
and you get this. Okay, let's deploy
this one. Deploy it. We have to pay some fee
for deploying some gas, 0.00 17, eight, and so on. Let's confirm this.
Pending transaction pen off calculator. Okay, this takes some time
to confirm the transaction. Okay 22. As you know blocking
is not fast. Okay, O transaction
is confirmed. Let's view in Poli scan. Here's this polacanGt
and duck it. Okay, here is our contract. Okay, this is just up code. But you byte code because
it's not verify yet. Let's verify this
functions. Smart contar. Okay, of course, it's just
single fi, the version. Okay, our version may be this 1826 plus, which
means more than that. Our license open sers ciscopys there. Verify and notable. At this time. Okay verify and publish. That's it. It's fine.
Let's take a look. Okay the check mark. Okay, it is. It's the
same strive functions. I is ABI. Okay, the red faction Okay, it's gate right functions, which means the updates of
the state in the blocking, at functions, multiply, and
sutra, subtract, subtract. Okay, let's go back to this one. Okay. Let's add a number four. Okay, our result, what is it? A zero. Okay, I have to confirm transactions because anything you want
to do into the blockchain, you have to pay some
fee for this one. This is not fast. Transaction is confirmed. Okay. And we get four. When we click the Gt we
don't have to pay some fee. Audit it. Yeah, because I double click to
the advanctions. And that's it for
this time. Graasia.
6. Solidity Intermediate: Mastering Mappings & Structs: Another topic is mappings. So mappings it's amazing things in solidity, and it's cool. I love it personally. So out work basically, okay, pointed to value. That's it. Once you get value, should has the K. Call the K, get the value like student IA. Every student name student
has ID, zero, get NAs. Call the mapping one, get Bonny to Larissa. And the cool things
here decay is not something for
example, here 013. The following one doesn't
must be three, for example. No, maybe four to my name. Seeing for example, maybe it's a ten to
Victoria, for example. That's different between
the mappings and arrays. For example, in this addresses. So that's different
between this. Okay? The address
pointed to the name. You have the address,
you have the name. So to create a mapping
in the SMAT contract, we use the mapping
keywords and specific type of the key and then the type of the
value and the visibility. So here by default is private. But you can market, for example, public
or external s. So students the name. So if you want to
add an element, basically student
specific the key and gate the value, that's it. You want to get some value, basically student
address, specifically the K. So you have the value. Okay, another thing is struct. Strack, basically,
it's useful if you want to describe something. For example, car a sum. So models so any card
has a model year color. In this case, model is Y, years is 2023, the color, sorry. You got di. Okay, Struct. Strat
is very useful if you want to describe something.
For example, a car. He every car has a
models heir and color. This case, for example, Y, 2050 today and blue. And by the way, this
is very useful. So for example, if you
want to add a student, okay, we see that in
the classroom pro. So a student has ID and
name, a for example, result and other
things present or not, okay, everything you can
edit and add the data, how to add data. In this tract and other
things useful in this tract, you have the group of variables
with different types. For example, string, you
went boolean, and so. Okay, here is a Tis la struct. We start with this tract
Tisla string model, you went 256, string
color and so on. And here's an array of struct. So to add atract Tis la, so the name of the
struct, memory, we store this in the memory, not in the storage because
it's a lot of space, so that cost a lot of gas. And new Tis la, this is locally, so
inside the functions, equal Tisla and models. So decay, the value is models. We get it in the
parameter, year, year, color, color, and so on. Then we push the new Tisla
to the Tis Ls array.
7. Classroom DApp: Your First Intermediate Solidity Project: Go to the Github
repository of this course. Github.com, we've
seen pH and 202 001. And then in the repository, and the ultimate solid
smart contract course. And then we copy this. Go and create a file, a folder. Let's say mate solidity. Solidity course. No, no. Et's open the base so copy this and get loon So we have. Close this, go to the Remix. Remix. Okay, create a new workspace. Add new workspace. Let's say, a solidity. Course. Course. Create a folder name contact. And then upload a folder. Upload a folder, not file. Where is solidity? The Solid of course, okay? This one. But plot, okay? Is. As exercises as the solutions. Okay, first, exercise. So it's calculator we did this. And create a students
this contract. Define student tract with ID, name result, create a
mapping, create an array. So let's create a struct. Act. Name it. What? Student? Yes, student. Student student and doing 26, ID, this, then the name string. Name. Result is eight. It's eight. Because result is 0-20. And success or not? Oh, it's a yeah. Success. Warning. Why, why, why. This je data, the name. Okay? You said you
constr same name. Okay. Now the warning is good. Okay. Let's add a
MPI Mapping QR, MPI. The key what is it? The key basically is ID to
the student ID type of uid. Student is struct. Okay, UT six, call ID. T. No, sorry. To students. Students. And let's public or not. Okay, let's say
public at this time. Okay, no, ID two. Students. That's it. Okay, let's add an array. Array array of students. So array of this struct. It's student. Okay. Students. Square bracket, size dynamical. We don't fix the size. Because we don't know
how many students will be in this class. Let's say it's public and students let's
say students is good. Okay, that's it
for this exercise. The second exercise, what is it? Okay. The second head
is a constructor. Set the owner. Who?
Who deploy this? And the honors private. So the exercis add the
struck to the array. The struck to the array. Okay,
the function add student. Okay, let's add functions
student functions. Add student to Marpin. Create a function to students. Basically, create a Function. Get set or ate Studens Ads Okay, ID, name results. First, let's say, ID. You 286 IE. Next string string. In memory. Sydney starting the memory. Okay. It's int, int, okay? At. You know why we market
the int because the memory, the result can be negatives. Fortunately, can be
negatives. Okay, the result. So result. And, success. So bull Success. Okay, external, of course, none. And external, so
little, no, fear, no. Okay. Mm hmm. Students. The clarss did memory. Set use students equal what? Students. Like sorry T and this. So ID ID, the it is ID. The nk As a name kit name value. And sotaRsultR sont. And then Bola, success. Sorry. This is not. I'd like
this. First, yeah. Basically, it's just Come on. Perfect. What? Say, not found or not ek. Don't de fire. No fun. Too too dent. So it's my fault. Yeah, I mean. You see, we push this suds cod push students. Student. That's okay.
Let's make sure. Okay, and adapt as
well in the memory. Sorry, in the mapping. Okay, like this. ID, specific
to ID and new student. That's it. That's it this? Caperton arid and biglmt,
students or students. What's that? Students, yeah. Okay, that's it. Okay, it's create a
function student function. Git students. Perimeters external, of course, and it's a view because
we want to read a data in the block chain tool
tours the students. Students. Of course, it's memory,
starting in memory. Basically, in memory,
strings in memory, structs in memory,
arrays in memory. Numbers? No, you won't. In this case, you
have two options. You can use the student
array or the mapping. Let's use mapping. Okay, I T two students, square bracket and
specifically I. Tt. Let's compile this one. Okay, you can make
this auto compile. So it will compile at the time. It's deployed and see
if this is a pin. The transaction goes through. The partner, there's a punches. Okay. Let's say I am number one. My name is RusinaRsult,
of course, 20. Success is true. And it transacts. That's it. Okay, let's, let's add
another another user. Okay? It's ID ten. It's Bob, for example, ands ten. Okay, two. Yeah.
And another one is, let's say, with ID five. Let's say Alice. Sorry, Alice. 24. Add transaction.
Okay, my ID is one. It's it Cob? Yeah, that's it. Okay, one, mice, two, and three. Let's Let's bit Ale. To maybe? No, five. Okay, five, Ax, two, and fours.
That's great. Okay, in the mapping, for example, let's say Bob. Ten maybe. Huh? Ten?
Yeah, it's Bob. Okay, it is Bob and throw student index
here to the index. So Bob dex, what is it? My index is zero. The Bob index is one, push, and Alex index is two. So my index is zero S zero. Okay, man. They'd
say, two is Alice. We expected Alice. That's it. Alice. He is Alice. Okay, congratulations.
8. Mastering Loops in Solidity (Made Simple): Loops. Loops and the programming. So there is a four. We stopped with the
initialization, condon updates,
initial condition, updates, and so on. First, we win I equal zero. Then we make sure the
condition is through. So I less than five, and we increment this variable. In this case, we
increment by one, you can choose a basic by five, I plus five plus
ten, as you want. And the logic, we
execute this logic. For example, so I equal zero. First, the condition is through, execute this logic here. Then update the I
Ecrement by one. Two condition is true. Logic. Equipment,
three, through, logic. EguimentFour. Four is less than
five. That's it. So execute this logic. And then increment 425. The logic is not true. Is not less than five
equal five, so out. And his heritage in the event. For example, function,
count up, weight, limit, public per
returns, event. So you went sum equal zero, or you wind equal one. The condition by one, two, three, as you want. And the condition, this
should be less than limited. Limit, we got it
in the parameta. Less or equal, and
we increment by one. So then some we add
this e to the sum. Until finished until
the condition is false, then return to su. Oops.
9. Solidity Loops: Hands-On Exercises for Beginners: Loops to our classroom contract. Okay. And in this exercise, add a function to the success. Okay, we love to check if the
student is success or not. Okay? So, function. Okay. Sick says student. So parameters external. Yeah, external. It's a view and returns Rs. A array of struct. Sorry. Student. Student. A array. And m. Sorry. Me Murray. Yep. So first, we stop the length
of the student's array. So how many students we have? Okay, 200. Okay. Length equal sudentTt
length. That's it. And then we create first. Okay. Let's create the
array of students. Another array to store just
the student who success, and then return it. Okay? It's student. F it's students, and it's array. Memory. And let's say, success success, Equal new. Okay, the instance
of the student ray. Then sorry, the student struct student
calibrate, and that's it. This is an error. Okay? Wrong argument, count for the zero argument given
but expected one. Okay? In this because this is we start in the
memory, not in the storage. So when you sort an
array, in the memory, you have to specific the site, especially if it's a strat. If a strat array, you have to specific the size. So which the size in this case is the number of the
success student. We don't have how many success. So we create a loop to
count those students. So 4156 equal zero have to be less than the
length the students array. I say, less than length. And then we increment by one. So we create an account, counter, sorry, counter count. So in the success student, the success is always through. That's okay. Add if statement
if students index. Let's say, students
zero index zero, Studentx one sus success, the variable of the str
successequal, what equal through. So this student is success. Hurl so we increment
count plus plus. So and then when the
loops is finished, which means the I is
equal the length. Why we don't do this equal? Because this I,
yeah, equal zero. We initialize by zero. Let's say, the length is, for example, five, we
have five student. The I is zero is one is two, is three is four. Okay, four is less than five, but there is a five students. That's why we don't equal
list or equal. That's it. So when the account is finished, so we have the number
of the success student. So we fix the size of the
tract array by discount. That's it. And then we create
the same loop, the same But In this time, we add this student. We push it to success array. Okay, like this. So sixes. Sixes to push. Student Hey. It's not a verbal. Instructs students. Outside of storage. Yeah. Okay. We don't
create a push. We have to create like this. Equal say students. And then finally this success. Okay, let's compile. Okay. By default, it's autocompiler, so it's
compiled successfully. Then let's deploy this contract
and say, what happened? Okay, student. Let's add a student like one. Is Bob. Bob is the first one
has 1510 children. Sorry. True. Then there is a ten
unless let's twin. It's time. It's true, of course. Another one. Five. Let's say, Victoria, Victoria. And let's say it's just four. Sorry. So four, it's
four. That's it. Now let's go to
get six as people. Okay. Okay, here it is. There is one, Bob, 15, through. Ten, Alice, 20,
through. That's it. Okay. We'll create
these functions. Congratulations. Okay?
This is the exercise. Let's move on to the next step.
10. Solidity Modifiers & Requires Demystified: This is the cool thing. Another cool thing, and
the solidity is modifiers. Modifiers basically
is a piece of code. Inside of factions. So for example, you
have a piece of code. You have to create this code every time
in all the factions. And that's Cosa gas, time, and so on. So what you have to do is create a modifier and every time you
want to execute this logic, just call this
modifier. That's it. Okay, say modifier is functions. You can see that. Okay modifier. Make sure only the owner can
code change owner functions. So there is a change owner
functions to change the owner. So the owner, who is the
owner? There is a constructor. Which means the function you call when you deploy
the contract. So once you deploy the
contract, the message sender. So who deployed this contra? Me, for example. So I
deploy this contract. So I am the messages sender. This sender store in
the honor variable. So I am the owner of
this SMRT contract. That's it. But there is a
function to change the owner. Change the owner. So if someone's see this function,
Oh, change the owner. Maybe can call this
function with his address, and he will build the owner, the admin of the contract. And that's it's risk. So what we did, what
we have to do is make sure these functions should
call by the owner only. That's what we add this one
modifier, on the honor. So here require message
send equal honor. If the message is sender
who called this function? Here is a modifier on the honor. This is execute, then
the race expli letter. So only honor, I
call the functions. I'm not the owner. I
called the functions. Then the message is sent. So messageen equal honor,
no, I'm not the honor. So reverse, and the
honor will be safe. Otherwise, if the owner
called these functions, puts a new honor, so he called these functions, this is Sander who is the owner who called
these functions. He called the
owner, that's true, so change the honor
to the new honor. And here is this icon here, this is the wrist code, okay? Execute this first and
then the wrist code. I hope this makes sense. If it doesn't, we
explain this step by step in the classroom project. We do a lot of this exercise by this. What can you require? We saw it in the
modifiers, we explain now. Modifier basically
is a condition. If sited, like if segment. Make sure condition is through. If condition is
through, continue. Otherwise, revert. That's it. So you create this condition. And the rest SMAT
conta do the rest continue or revert based
on the conditions. For example, in these functions, there is a MAX permit
three functions meant you win 256 amount
public. Okay required. Amount is less or
equal the MAX permit. If yes, if this
condition is true. So the continue, which means you can it
the rest of the logic. Which means meant this amount. If it doesn't revert and show this no more
than the allowed. For example, I
call the factions, and I said the amount two, so two is less than three. Okay, I mean this amount. I, for example, call it again with the FOB for less
or equal max permit. No. It's more than three. So the transaction liver
and show this one. No more than three, allow it. This is not just option just to know what is
the prob in the code. Show it in the concept. And
11. Modifiers & Requires: Practice Challenges in Solidity: Let's add a modifier to our
classroom smart contract. Okay, first exercise, create a function to delete student, create only owner modifier, implement the modifier to allow only the owner to
call the factits. First, let's create
the modifiers. Start with the modifier keyword. And the name on. Sorry. Ana. On Onur.This and here we add the require require statements and come in listens, okay? And do like this. That's it. This icon hair, it's basically the rest of the logic and the faction. Okay, here is a bogic of the
code of the modifier here. And then this will tell
you the compiler, okay, execute this one first, and then move to the rest
code of the function. You can't do like
this. Say, Okay, execute the code first
of the functions, then execute this one. So this is basically
is function logic. Okay. Create a
function to delete this the bottom function. Okay? The, the late to the ID, of course, external so we do the same in this one. We compare the ID because
we want to delete this on in the just
to guess degree, we want to delete this student in the array and in the mapping. First, let's delete
this one in the array. To delete some element in array. Basically, move of this to the last element and size the array. So students. Students. But we
don't know the ID. We don't know the dex of this student that we
have to create a look. Okay. Firstly
started the size in length variable equal to students Lock length, then 44206 equal, sorry, equals ten, less
than length Sorry, I plus plus plus. If. Now, if the students, A, adds ID equal equal ID equal, equal ID ten students. The last one that
last is length, the last index minus one equal. Students. Students. We start this. We move this student to the
last element of the array. And then, basically we pop students dot Pop Pop
the last elements. And remove it in the mapping. We use the late T word. Okay. I D to mapping and
specific the ID. And that's it. So this
function is a risk. So if we don't
implement the modifier, so anyone can delete
any student, anybody. So that's why we have to
implement the modifier only owner can call
the functions. So in the require
require exercise, we add this line, okay? So let's move on to the
require require exers. The required exercise. Oh said implement a
require modified check if the user if the
caller or user okay. He is the owner of the contract. Basically, the only owner. We require message
that Sender call these functions is equal to the owner or deploy
this contract or not. If yes, move on. Not at revert transactions
and log this one. Only owner can call this method. And note. And that's it. Okay, that's before
we deploy it. We then the last one and deploy. Okay? Go through here the one. Okay, let's say at say quan Kemi say ten. Let's say zero. Okay. Another one, ten, S, Bob, 20, and three. And we want to delete
someone. But make sure. This account, who
deployed this contract? So this account, this guy
here is the owner of this. So the message sender, the owner is this one. First, let's call this
function with this others. Since it is the owner, so the student will
delete say one. Transactions goes through,
get the student ID one. No, it's a zero, zero faults, which
means in the tuple. First, I have the
ID zero by name, you see, and through
and results. But this okay, let's t's clear he Okay, here. But delete after call this
delete and call this function, we get zero and empty, and in the result zero and
false which means zero. That's a let's say, Okay, we have another one. It's BG the Bobo, ten, Bob, 20 through.
It's delete this car. But it's not the owner
who delete this one. No, another one. Say this one. Try to delete Bob.
Is that possible? Let's say we expected
revert. S it's Bi. Delete. Okay, it's reverse. Why? See why it's reverse. Basically, this
action, basically, okay, look at it only owner
can call this method.
12. Solidity Events: How They Work & Why They Matter: Is basically a notification from the blocking. And
that's very useful. Very, very, very useful. It's a logs to the blocking. Okay, there is a functions.
There's a logic, at the end, there's an
event from the blockchin. So there is this could
execute successfully, then the blocking tells and
notifies this function, it's called and
execute successfully. Here is a clear example,
smart contract. Okay, there is a tabs
here, functions one, called the smart contract,
and there is a event. So we call dysfunctions, and these functions has a event. So events it's the blockchains. And this app is listings event listener
to the blockchain. If anything, update
the blockchain. So the block chain will
notify the app by this event. For example, there
is a function to add a student
function in the app. Function to add
the student. Okay. This function has a event
and ban event student with student ID and the
name of the student. That's it. And in coming day, someone some student
call these functions. With his information, then
and added to the block chin. So the block chain, when
he receive this student, he notify the apps, say, Hey, there is a new student
added in your app tag. Here is his ID and his name. That's it. So events, create
events and events. So in smart contract, we create event like this
with the keyword events, the name of the events. And this side, the data, want to log log in, okay? You went to 256 index it data
one and string data two. So this index it is
useful if you want to filter the data. To accelerate and do easier. No. So that is very useful if you want to
test your functions. We see that in the
foundry framework. Foundry course, sorry. So functions, function, some
function. Okay, public. Dig logic, and then
emit this event with the data one and data
to emit the name logic, the name of the
events and the data.
13. Events in Action: Interactive Solidity Exercises: Let's move to the contract. As exercise events. Okay, events, create an
event with four arguments. ID, name result success
called student added, and then emit this event
in add student function. Create an event with
two arguments, ID, name called, student deleted, and emit this one in
delayed Student functions. Okay, first let's delete this c. Event keyword. The name student. Okay? Students. Nope. So this one. Okay. And then, first, the ID. The ID is into win 66. ID. N strength. Name. The result ends, not ends. So the result Sixspola. Okay. We want to filter the student, by ID and N, which means this is the
most important data. So we make it this one index. And of course, the name,
of course, is index. The other is not just. And he said, create another
one called student Delay. Okay? As always, even sky
words Student deleted. The ID 256 indexed and ID. Then the name string index, that's it and name. So let's emit those events. First, emit this event
and add factions. So emit d, and the name of one students students that the first part is ID, so ID and name Kate Nims a guy results results. Then Bola success. Sirk Success. Ad function is this
event is is very ab. So this up smart classroom, he listen to the Block
list by this event. If somebody called
this ad student. So the Bloc chin,
say, Hey, classroom, there is another
student at his ID, his name, his result, and success or not. Okay, this is the
purpose of the events. And, of course, we
inmate this one in That's it. Thanks. The name for this one. We
will start the name here. Okay? First, save the
name to trigger it here. And that's it. This is b, actually.
Not like this. It's like this.
This is the branch. Store this one and the last one. No. Last one in the actual. Okay, let's com pie. There is a error. What? Added problem. Events. Got expectedly. Ah, I hear you. This semicon? That's it. It's
compiled successfully. It's deploy and see the events. Loud or not? It's a. Okay. Let's add someone. Five. My friend Bob ten and through
Transactions. It's show her or not? Okay. Here is. Here is in the log. Here is our guy. In there, of course. Yeah, Heats. Even
student addts argue. The index is true. So one. But what is the
name? Yeah, Herits. Okay. The ID is five above
and ten and through.
14. Inheritance & Interfaces: Building Smarter Contracts: Inheritance. So inheritance,
here's an example, here's a blue car and truck. So the blue car has
some functionality. Drive and reverse and stop. So this is a general car. And but the green car has some additional
functionality because most of the time, it can tow and go off road. So but at the same time, has those functionality
drive and reverse and stop. So this green car basically it inherits there was functionality in the normal car and add
some own functionality. That's it. So let's go ahead and say how this can happen
in the SMAT contact. Inherited and smart
contract use the is keyword to inherit
some contact. For example, there is a contact parent int has this variable parent
data. It's public. Child contract
inherits from parents. So the contact child is parent, which means inherit
the content of the parents and has a
variable child data. So and the constructor
and the constructor of the child it set the child data. And the inheritance in real
world is real contract. The Azuki contact inherit
the honorable and ERC 721 A and retrinc card
from the imports Okay, there is a open Zeppln library. So the honorable, this is
inherit all the contents, the variables and the
functions with internal, internal and public visibility. The private cannot be inherits. So let's see how to contract can talk together interactions. Contract interactions. So here is to
contract user and G. So this two contact actually has a lot of
interactions because the key, the users who play the G.
So in the contract users, these functions, create user, the late user, increase level. And in the game contract is
a start game and play gay. Basically, the
interactions maybe can happen called the
struct struct game, this immediately create a user, which means destruct
contract called the create user
or the game over, for example, the late
user or increase user. So this contract, talk to
this one user contract. Okay, in smart
contracts, for example, is contract A with the
data and the set data. And here is a contract, contract B, the interface, we see what is interface layer. So this interface has
the same functions, set data and the variable
data. It's also a function. So in contract B, there is a constructor sit the interface by the address of the contract A and here and that's how the connections
actually create. This is how to create
the connections between the contract A and contract B. And basically when this
connection is done, so you can call the set data and set the data variable as you want in
Contract D, like this. Okay, this function
set data in Contact A, you wait to 8,256 data external. Okay, Contract A dot set data, call these functions in the
parameter put this data. So this one change by this. So where is the interface? The interface basically
is a blue parents. Okay, there is a multiple room. It's play like functions. Okay? So in real world, in the smart contract, here is a contract A, win 256 public and
data function set data as we sell and in the interface, his function, see
data at in interface, you have to declare a
functions without definitions. The k, the parameter, theirs. The same k must be match the name of the
functions in the contract A. And this is a variable here. By why we create our functions. Basically because the functions
is like a Git functions. And the variable public variable has by default Gitter
functions, here it is. Okay. And this is useful
when there is a function, for example, there is a contract
had a lot of functions. For example, it user data user, stfile change, owner, and so on. And in your contract, you create a contract. You want to you don't want to
inherit all those factions. Just you want some of them. Okay? It's a change
owner and sit Sitauser. That's it. So you have
to create an interface with the same declaration
without definition. And in constructor, you
declare this interface, and then you sit
this interface by the address of that contact. Okay. That's it. So we see this in the exercises. In remix, here is ARC RC 20
tokens, has some functions. These symbols, symbol,
name, and signature, total supplier and
balance of and transfer, approve and a lot of functions. And I want to create a contract. Okay. Contract Lexi
test. Just test. Mm. Okay, Biggs. Le sins bot fryers. Mm hmm. And in my taste contract, I want to use this
mint factions, maybe, or name factions. So what I will do,
I don't want to use all the functions of the ART. I want just name and mint. So what I will do, create
an interface and interface Okay. Interface.
Interface, limit ARC to T. And you go to the name of
this name name fractions. We'll copy the signature of these fractions. Copy this one. Past public, so
cheer to external. As I told you, all the function in interface,
it's external. There's view and without
definitions. That's it. And functions I won't
use it is let's say, let's say mint Mint W is mint. Yeah, this is it is
Mint's external internal. Do internal. Change it to external,
as I told you. External. And yeah. And I will declare this one. CC 20. Is public and RC Constructor for the address of the RCT. Let's say ARC two equal ARC and change this
address to the ARC. And this is how to
create the connections. Now, my Airc it's the same address of the ARC
I want to interact with. Basically, let's say functions. Name. Let's say string memory. Starting the memory. Well, let's say name. Okay, it's public wary and ARC 20 dot N. No, without
parameter. Okay? And just return then. Return. RTs. What? Strain.
And the memory sub return Ko That's it. It's mac to you. And that's it. I return the name of the ARC. No, no, no, virtual. Ill to you. Okay, and
the MintiaFaction. Fiction Mint. The same here Adessen Okay, ARC 20 Mint count. A not. That's it. This is
how to contract interact interact
using interface. In
15. Finalizing Classroom DApp: Adding Inheritance & Interfaces: Booking now is a grade
parent contract. Created Inherit student
contact from Astral, Q. Let's do this. A to inherit
and students That's it. And he said, create a function to check if the
student is success or not. Okay. Now, the parent has all the functionality
of the student. Additionally, he has
another function called checks the parent, he want to check if their
student is success or not. Let's say function. Okay? Check Success, it's just it's called
success, okay? Success, you buy ID. Okay, six force or
public, anything? And Richards. What is what? Bula.
True or false. So just Bolt. Through tools, sold and it's pure factions because we want to
check if true or f. Okay, I IT students IT S says equal true true. Otherwise. As Sorry. As. Return FOS. Yeah. Okay, basically, you can you
can just do like this, okay. Return Sorry. Return IT to students
ID Taught success. That's it. And this
return true or false. That leads sales. This just for No, this is a chick. Not to know just three or four. No, to check if there
is success or not. Maybe you can add some
logic here, okay? The bonus or can
do anything here. But if just return, no, maybe that's it. Okay. I I think it's very good. But, you have the choice. Okay, let's deploy this C chat. Without deleting this one. B. You don't eat this
one. The parents. Yeah, the parents. Let's deploy the parent. Okay, now we create a parents contract and
inherit the students, then we add additional functions which is successful success. Okay, the parent now he has
the ID of their students. So check if true or false. So when we deploy this one, can we still it and redeploy it. Wow, we get all
the functionality in the student contract. Additionally, we
check successful. Let's add five poke. Always my friend Bob. And then ten. Through. This guy is good.
Always through. Then we check five Oh,
through. That's it. Add another one.
Walls. Okay. It's two less Sorry, Alice, again. Five. And false rest, check the Alice parent to fobs. Okay exercise of this
interface, TT T T. Okay, you don't need
those Actually, we don't need those. Send it memory. You have to take this one. Okay. Cuz interface
over there is in B student create two
functions in ad student. So let's go to the ad
student He's students. Okay, let's copy this one. And why we need this
one just for this type? It because I have this
hair and get student. So in this contract
is not defined yet, so that's why I copy paste the student struct on
the student contact. Okay, here is the function. Okay, let's delete
this line by line. Understand how that's going. Okay. First, he said, add add student functions. So we add the
function signature. Let's go to student student. He's at functions. Okay, let's copy this. Here, F. And that's it
without definition. And G student let's get the signature of G
student. Signature only. O here's signature. That's it. I did. So now we
have two functions. Head student, get student. And we create, I said, Okay, let's do all these things to
answer this line by line. Okay. Okay, create
a teacher contact. Here it is. Create a constructor to sit student contract
bypassing it as a parameter. Okay, do the globe students. I said it's public
and student compact. And constructor
constructor, passing the address of student contract and a student student contract equal I student. Convert this to interface, get student. That's it. Now we create the
connection between the teacher contract
and student contract. Now we have the possibility to call the add function
of the student. So we create a function.
Let's call it sit my student or add my
student as you want, with the same parameter. Okay. You can add any
functions as you want. And call this function
student contact first. But, but what? Here
is the possibility, add functions and get
student a function. Okay? Pass the ID, the name, the
result, the success. Okay, what is success here,
so we add apola Success. That's it. Name results all done. Then another function it's
function, get my student. You run ID by ID. It's external force, the
view and the return. You have to specific this
interface because it will return this Okay. So this is not the students
not distract of the student. No, it's distract
of the interface. That's why we add
this and dot student. Let's take literature. What's. Okay, litre student dot git student and pass
the ID. That's it. Okay, contact calls. Let's Let's compile this one. Okay, it's compiled
successfully. Check Mark. Let's deploy the
Interface first. Hm can't. What? No one
can deploy this one. Wow. Okay, we deploy the students
first str let's deploy. Okay? This check
marks. I love it. And the params our
student contract. Then let's deploy this one. It's compiled
successfully Deploy. Sorry. We're passing first
the address of the student. Okay? And the constructor. Because once you
deploy the contract, it's directly called
the constructor. So we pass the address of
the student, then done. Mm hmm. And that's my student
and get student. Contract is deployed, and let's add a student and teacher. True. Bob is my student. Bob results. Let's say ten. Okay, true. That check mats. That's it. Let's say three. My student Alice. Go job Alas 20. True. Let's keep my student two. Here it is two, Bob, ten, through. And what? Yeah, three in Alice. Student Alice. That's it. And the ads of the student
Cuts 0d60 CD six a four. That's it for this license. Okay, we finish this one.
16. The Ultimate Solidity Challenge: FundMe DApp: Finally, the fund me project. So this project is more complex, and there's a new
concept in this. You have to know before
you start this project. Okay, Pike work basically, when you market an
address payable, this address is going
to accept eight funds. If it doesn't, just declare normal address that
cannot be accepted ether. And any iteration to this
address, it will be lost. Another thing you can market
payable is functions, functions, constructor
functions, receive fallback, all those functions,
you can market payable. Once you market a function, payable, so these functions
can accept Ether, which means when you
call these functions, you can send some ether
to this function. It's a message that
sender, which means hold the address of who
these functions. Message dot value is the data, the funds you send
with this call, exactly, your call functions, and you send some Ether. So message dot value is the
funds you receive you send. So that's why in step three, there is a fun functions
allow user to send it. So it is Mr. Dot
value in this case. So in functions, there
is a step two, owner. Okay, the owner, the one
who deployed this contract. Minimum contribution
is like a threshd. Okay. The minimum amount you have to send
to this contract, the infant functions, there
is a user can send it, which means you have to
market the functions payable. And the store this
amount in a mapping. Mapping with address to amount. Address to, you went, which means the miss
GSander who sent who called these functions
and sent this eater and the eater who
sent the amount, which means innate the
name, for example, balance, balance miss sender
equal misers dot value. And at the require
above. That's it. And scep for declare
it withdraw functions. Create the withdraw functions only can only be coll
it by the owner, which means only on the fire
and recet the contribution. So this withdraw, send all the balance off the
contract to the owner, then reset the mapping, reset to zero, which means
again, the game is over. So send all the ether
in this contract to balance to the owner
and rest the balance. And yeah, so how to
send all the either of the contract basically
is address address this. This is the address
of the contract. Address this dot
balance. That's it. Like, for example, a user, for example, address user,
address dot Balance. Router, the balance
of this address. And the CP five modifier, I set and CP six, a contract cannot be accepted. Ether until have two functions, C or fallback functions. Otherwise, the ether will go. So receive it's a trigger that trigger once a
contract exit ether, fullback trigger
once the contractor accept ether or data. We're explain more two
functions in the fund course. To hold Ether. That's it. And S four deploys
in Support, a bonus. Okay, or, the top contributor. That's it.
Congratulations. A huge thank you to take this course. And I'm so excited
to teach you and the first step to jump into the block chain and learn this
powerful language. So solidity, okay, I
love it personally. It's beautiful language. And more than that, when
you learn the solidity, so you have the solidity and taste this code using foundry, this is amaze. This is amazing. So in the next course
on the project, I will provide you the
solution of this project with additional thing
concepts like payable, receive, fallback, as we we add. We know what is a chili, C chili, very and so much more. So, see you in the me project. Again, thank you so much.