Smart Contracts Programming Tutorial | Solidity Programming Language | Solidity Tutorial | Edureka


Blockchain has come a long way in the
last ten years with a lot of innovations
in the system it’s truly becoming a
revolution over time so the thing that
started the revolution was ethereum
with the introduction of smart contracts
and this was mostly revolutionized
because ethereum had very Network
specific languages to actually develop
these smart contracts hi guys this is
Aryaa and today’s video is all about
discussing one of these ethereum
specific coding languages and that is
solidity so before we actually go with
the video let’s see the topics that we
are going to cover today so when the
start of discussing about smart contract
programming then we’re going to see the
different smart contract languages that
are available for us to a program on
aetherium sniffer
next we are going to see into what is
solidity and my solidarity has become so
famous over time drilling down further
we are going to discuss the solidity
tools that are actually used for
developing code and then we are going to
get into the weeds of actual solidity
programming that in the end we are going
to build our very own smart contract
that simulates a lottery with all the
concepts that we learned throughout the
entire video ok so let’s get going
so first of all you guys must realize
that ethereum had a very key feature
that it could apply man smart contracts
smart contracts being business logic
that can run on the blockchain so this
means that the blockchains realms were
open to a lot of more services and feels
like gambling property transfer which
can be easily simulated with code but
the problem was that this code had to be
run somewhere so for that reason the
ethereum virtual machine was made so the
only ethereum virtual machine only very
specific languages can run and these
languages are ethereum specific
development languages so out of all the
languages let’s see some of them so as
you can see on the screen out here the
three most popular languages are
solidity serpent and triple L so let’s
start with triple L first so triple L is
based on Lisp which is another language
for programming and it stands for Lisp
like language triple L was one of the
first languages
that was actually built for running
smart contracts on the ethereum because
of its very minimalistic features and
lightweight which makes it very suitable
for running on the ethereum virtual
machine second that got really popular
was serpent, so serpent is influenced by
Python and uses a dot se extension after
its file it was pretty popular a while
back but due to security breaches it has
now been deprecated in use at this
moment in time the most extensively use
contract programming language is
solidity solidity is influenced heavily
by JavaScript and uses a dot soyal
extension and as I said it’s one of the
most popular things that aetherium
developers are using nowadays for
actually coding their smart contracts so
let’s look into what makes a little ease
so popular so as you guys can see the
definition of solidity is that solidity
is a contract oriented high-level
language for implementing smart
contracts it was influenced by C++
Python and very heavily by JavaScript
and it’s designed that targeting the
etherium virtual machine so many of you
must be asking at this point that why
can’t we actually write our contracts in
languages that we are familiar with like
Java or Python so you guys must remember
that all this code is running on
aetherium virtual machine which can only
decipher ethereum virtual machine
specific bytecode which is also known as
a vm bytecode now even bytecode has to
be very lightweight as this whole thing
is running on a virtual machine and not
some exact hardware so for that reason
we have invented ethereum specific
contract languages like solidity so
first of all solidity is statically
typed so that means that your
compilation is not happening as you’re
typing there’s no interpreter running on
the background that is actually running
and checking your code for errors it’s
something like Java where you write your
whole code and then compile the file
instead of something like Python where
your code is constantly being checked by
our interpreter that is running in the
background secondly solidity is a
high-level language that means it is
written in a very specific syntactical
manner where it’s not just machine code
that the machine can understand anybody
with a good knowledge of programming and
solidity can easily read and understand
solidity code above that it is contract
oriented so contract oriented means that
it is very lightweight in feature and
can be easily compiled and can
voted to evm bytecode which is
understood by the ethereum virtual
machine so moving on let’s see the tools
that are actually used for developing
solidity code so as every language out
there you always need a text editor so
text editors like atom sublime text and
Visual Studio code are excellent for
solidity as I have excellent support for
solidity syntax highlighting and source
code editing above that to actually
compile your code locally you need the
Sol C compiler now this compiler can be
easily installed with the use of taco or
the node.js package manager known as NPM
so code editor and compiler go
hand-in-hand and you’re ready to go now
there’s actually another option for
those of you who actually don’t want to
go through the trouble of actually
installing a compiler and then a text
editor with all its packages for syntax
editing and source code editing and that
other option is called remix so remix is
an online IDE for solidity now remix can
be also installed locally but it is very
much used as an online version so just
like every IDE it is meant to actually
improve productivity and take less time
to actually compile your code so let me
just open remix and show you guys why
it’s so popular so as you guys can see
remix has a very intuitive UI it has a
very clean looking text editor where you
can go and type in your code like this
and it’ll get automatically compiled you
don’t need to actually go ahead and
install a compiler on your own and go
through the troubles of actually setting
the environment variables and all that
stuff next you can actually run and
deploy your smart contracts on various
environments and account settings like
out here I’m using the injected battery
but you can also use some external
battery provider or a JavaScript virtual
machine secondly there’s also this nice
debugger that you can use to actually
debug your code by block number and by
transaction indexes or hashes it’s a
really cool thing once you start
actually using it and developing
solidity code now coming back to our
session I hope I made it clear that
remix is the best way to go if you are a
beginner and you are trying to learn
solidity okay so now that you’ve
actually seen why solidity was invented
how it is coded and all the tools that
are used in this development process
let’s begin actually learning the
language
so the first topic that we’re gonna
start with is the structure of a
contract so as you guys can see here
I’ve shown you guys this very simple
structure of a smart contract when
written in solidity in this gray box out
here so we begin by actually specifying
the compiler version which is said by
the pragma keyboard then we start
defining our contract and this is simply
done by giving the contract name but the
contract keyboard next I’ve shown you
guys how you can write comments and
multi-line comments a well commanded
piece of code is always appreciated
because it is very well understood by
others and it becomes really easy to
work in an organization so you should
always be very very specific about
commenting your code so let’s just run
this very small piece of code on remix
so as I said to specify the compiler
version we go pragma solidity and the up
caret means that anything above what we
specify so zero point four point one
seven so our code will be actually
compiled by any compiler version that is
above zero point four point one seven so
next we have to define our contract and
this is done by actually just saying
contract and then the contract name so
I’m going to need my contract demo and
then I told you all how to die
multi-line comments and single line
commands so single line commands are
just like this this is a single line
command and this is the multi-line
comment
so that’s the basic structure of a smart
contract any smart contract however
complex it is will always begin like
this
so moving on let’s move ahead with
operators so most of the operators used
in solidity are very similar the
JavaScript as you can see like
JavaScript we have three types of
operators those are comparison operators
bitwise operators and asthmatic
operators comparison operators are of
course used for comparing two values
bitwise operators are used for bitwise
functions like and or nor ORS or and
arithmetic operators are used for
estimating so let me just show you that
is a quick example of arithmetic
operators and bitwise operators so we’re
just gonna use this thing that we made
out here so let’s just create a very
simple bitwise operator demo first so
let’s call this bitwise and I’m going to
do all the basic bitwise functions first
of all we actually have to specify two
variables with the size of one byte and
that is done with the bytes keyboards
and then you just specify the space by
saying one so it’s bytes one so you go
bytes one a is equal to zero X B 5 so
the zero X is just to state that we were
typing our think in hexadecimals so this
actually stands for if I’m correct
stands for 1 0 1 1 0 1 0 1 so if you
were to convert this hexadecimal this
would be the binary representative next
we need another variable to actually do
our comparisons with rather bitwise
operations so we go 0x you say 56 and
this probably stands for if I’m not
wrong 0 1 0 and 1 0 1 1 0 okay now we’re
gonna have 3 or out of 4 operations we
are gonna do and our czar and not so
we’re going to use the functions and
I’ll explain how functions work later on
in this video so just catch up with me
for now so bytes
one
or a comma B and then bytes one example
3x or a comma B and bytes example for
just not and it’s gonna pass upon
argument I’ll explain why I just passed
one argument at the not and two
arguments in the others you will
understand in a short while so let’s
make up the functions that actually will
do our stuff so function
you
Titus copy-pasted the functions to make
my life a bit easier
you
so let me just explain to you guys what
I’ve actually done out here so we
declare two variables and we’ve assigned
them hexadecimal values which are of one
byte size next we are actually doing
four functions for the first function we
are doing and then you’re doing all than
we’re doing soar and then we’re doing
not now if you’re actually not
well-versed with what these functions do
I actually suggest you go and look them
up on Google so the first function on
will return the an between a and B so
and both these two binary numbers and
actually return the value second we have
the function all and we’ll return the
all between a and B next we absorb which
is return this or between a and B and
next we have not now not is a bit
different out here as you can see
because there is no actual support for
negation in solidity at the spoon but
you can actually do this arithmetical e
because knowing negation is basically
storing your number with the hexadecimal
1 so that is 0xffff so if you just do
that you’ll get the negation of any
number that you put in
so let’s actually run this thing and see
the output that it gives us so we change
the thing to JavaScript p.m. and we
deploy our thing so as you guys can see
here we have 3 or rather for functions
made now let’s apply each and every one
of them so first we declare and so as
you guys can see here after clicking
deploy we have these four functions that
we can run so in the functions we have
to give the input parameters and we’ll
see that we get the output now suppose I
were to put the parameters into and
always be sure you put double quotes
around your parameters as they are JSON
representations and then we go and run
and so we get our output out here and as
you can see that the decoded input was 0
XB v + 0 x5 6 and the decoded output
when both are handed n 0 x 14 which is
hexadecimal 14 now we can do the same
for not and we’d get the results for not
so if we also run the same thing for not
we’ll have the same results so you go
and press it for naught and you see that
our decoded input was 0 XP 5 and when
you not it you get 0 X for a you can do
the same thing for or just go and copy
paste parameters run or and you see that
we have Ord our two inputs and we get
the results out here in the decoded
output we can also do the same purse or
clicks or and you get the output so this
is basically how bitwise operators book
next thing on our list with arithmetic
operators so let’s go and make a simple
contract just for this thing so we’re
going to call our contract a simple
calculator and we’re going to be doing
some very it’s stupid but very simple
transactions so let’s say we have two
things are you in a which equals five
you NP equals six now I’m going to do
all sorts of functions on this so even
some B equals to a plus B
you in different vehicles to a minus B
now if you want to divide it division
between two integers will always return
an unsigned integer i will properly
floor it to the closest value we will
see when we run this a by B then we can
have a product and that we a star P and
we can also take other remainder with
the modulus function so as you can see
it’s compiled now let’s just try running
this simple thing that we’ve actually
clear so we deploy it
oh I need to give this functions to
actually give me some view of our output
so let me just quickly convert this into
functions
so yeah I kind of quickly just converted
all my things into functions so that we
can actually have an output situation so
now our contract is caller the simple
calculator and we have those two very
basic variables which is equal to 10 and
B equals to 5 now we’ve done five
functions that are the five worth medic
operators we’ve done a summation you’ve
done the difference we’ve done products
that is multiplication then we taken out
the quotient which is the division and
then we’ve also taken out the modulus
which gives us the remainder so this is
just done by passing two variables into
a function that is known as odd which
returns a human so we’ve returned a plus
B from the addition function we’ve
returned a minus B from the difference
function period on a / P from the
division function a multiplied by B in
the multiplication function and then the
remainder function we are returning a
module speak so let’s deploy our
contract and let’s see how it works
so as you can see out here we have five
parameters so now that we’ve actually
deployed our calculator let’s see how it
works
so let’s first test out the add function
so we click on add and it should add a
plus B for us so the answer should be 10
plus 5 which is equal to 15 so as you
guys can see the decoder output was 15
indeed next we tried emission so
Domitian should give us a PI B which is
10 by 5 and the output should be 2 so as
you guys can see out here the decoded
output of our division function is 2
let’s check out the remainder function
because that seems to be interesting so
we try for the remainder function and
this should give us that so once we run
the remainder function you guys can see
that it gives us a remainder of 0 which
is exactly what it should give because
when you divide 10 by 5 you get no
remainder so let’s actually change the
variables and see once so we make it 6
out here and then we run the remainder
thing again so now this time we should
get 4
if we change our available to six out
here instead of five and then we try to
remainder again you can see that it
should return for so and that’s exactly
what it returns so now that we’ve seen
bitwise operators and there’s better
co-operators it’s time we move on so
next on our topic is data types so we
are a bunch of data types to cover so
let’s go through all of them one by one
so as you guys have seen already there
are two types of integers there are
signed integers and unsigned integers
now all these integers are declared with
their spaces when steps of eight so like
you can declare an int with eight bytes
and we’ll be int it then it will go on
increasing from 8 to 16 24 32 up to 256
and this also followed for a UN which
stands for unsigned integers now the
Declaration of an integer value can be
done with the int keyword or the event
keyword followed by the variable name
and then a value for example we define U
and call marks and we assign it to the
value 39 in this manner out here next we
have boolean values now as I said
boolean values are of two types
they’re either true or false they are
declared using the bool keyword followed
by the variable name and then actually
specifying whether the boolean is true
or false for example out here we have a
boolean called pass and it has been
assigned to true also if you remember I
had told you all that logical operators
always return boolean values so things
like and logical and or and logical or
even negation and equality and
inequality all return boolean values so
next on our list is fixed point numbers
fixed point numbers are not fully
supported by solidity yet they can be
declared but cannot be assigned to or
from side an unsigned fixed point
numbers are of various sizes the keyword
you fixed followed by M cross n where m
represents the number of bits taken by
the type and n represents the number of
decimal points that are available it’s
really important to note that M must be
divisible by 8 and goes from 8 to 256
bits while n must be between 0 and 80
with inclusive of 0 and 80 both unsigned
fixed integers and fixed integers are
alias
of you fixed 128 plus 18 and fixed 128
cross 18 respectively next on our list
we have address type now address type is
very specific to solidity as we need to
specify the address of everything or
every component that is residing on the
blockchain so we declare them by
actually saying address then the address
is name and then the value so the
address is normally a hex code which can
be seen out here like that the example
address home and then the hex code
address value so the address member also
has some very important functions so we
can check the balance of any address by
just calling address dot balance then we
can also send some money to some address
by using the send function and then we
can also use transfer send and transfer
both do the same things but it’s always
recommended to use transfer and this is
why so if a transaction fails when you
use send the transaction field you can
go to a call stack depth of one zero two
four and it also feels recip in front of
gas so in order to make safe ether
transfer always check the return value
of send use transfer or even better so
basically send has a lot of security
issues so if your transaction fails amid
way there is no possibility or no
guarantee that the state will be rolled
back to the previous one but you had all
your money this means you can
potentially lose a lot of money if
you’re using send so that’s why with
more updates the etherium community came
up with the transfer method which has no
such security issues so next on our list
of data types we have strings so strings
and solidity are stored in the utf-8
encoding due to this reason strings
consume a lot of space on aetherium
virtual machine and because of this
strings are completely avoided or used
as least as possible as they consume a
lot of gas for the execution instead of
strings the uses of bytes for such
variables has always been promoted by
theorem developers but just in case you
want to know how you can use strings you
can just declare a string by going with
a string keyword then the variable name
and then the value now strings must be
surrounded by double quotes or single
quotes it doesn’t really matter so as
you can see out the example here I’ve
defined my name with the string keyword
with the name of the variable being
named and mine
are you okay so the last type of data
types that we’re going to discuss is
enumerators so enumerators are a neat
way in solidity to create custom death
types so as you can see out here in the
example we have created a custom data
type called a jet state so it has four
members that is take off land autopilot
and still so you can make your custom
enumerator by the following decoration
method it started with the enemy keyword
with the name of the enumerator that you
want to specify and then the members it
is very important to note that every
enumerator must and must have one member
at least ok so let’s try out a simple
enumerator one remix so you’re gonna say
contract and now and it’s just gonna
create a simple enumerator I’m gonna
show you how to do this so suppose we
call creating an enumerator for game
choice so you could actually have a few
games oice is like keep Lane paws
you can say pause or you could say
disconnected
or something like reconnecting but these
are just very arbitrary members to a
game choice that makes no sense but
let’s show you how I can make a game
choice like so you go game choice and
suppose you want to make a default game
choice so suppose you were playing GTA
on a decentralized network so the
default game choice would be keep
playing so you would say go game choice
dot keep playing and that’s how you are
initialized a game choice type of data
so it’s very simple as you can see okay
now we have a lot to cover so let’s move
on quickly so next on our topic is data
structures so the first data structure
that we are going to actually discuss is
arrays now the use of arrays is very
similar to that of JavaScript like
JavaScript we have two types of our is
static and dynamic now static arrays
have their index size or the array
length always specified but dynamic
arrays do not have any specified length
under stored in the memory so you can
also create multi-dimensional arrays
using syntax that is very similar to
JavaScript and it’s shown out here so
you can go double square brackets and
you can choose the index length or you
can create a dynamic array which is also
two-dimensional by just keeping these
two blanks
moving forward strokes and solidity
provide a way to define new types in the
form of strong it is not possible for a
struct to contain a member of its own
type although the structure itself can
be the value type of a mapping member
the restriction is necessary as the size
of the struct has to be finite so as you
guys can see how we have created a
struct called clear and we have four
members of the clear thing so the four
members are named Stark’s age and
mortality and these four members are
each of different data types so
structure of clear is a complex data
type consisting of four member data
types so the next thing we have is data
allocation so the allocation is pretty
important from an a theorem point of
view so every complex type like arrays
and structure has an additional
annotation called data location about
whether it is stored in memory or in
storage depending on the context there
is always a default or it can be
overridden by appending either storage
or memory to the type the
default for function parameters
influenza tone parameter this memory and
the default for local variables is
storage and the location is for storage
for state variables there is also a
third data location called call data
which is non-modifiable is non
persistent area where function arguments
are stored function parameters and of
external functions are also forced to
call data and behave mostly like memory
these are locations are important
because they change how assignments
behave assignments between storage and
memory also to a state variable always
create an independent copy assignment to
a local storage variable only assign a
reference though and this reference
always points to the state variable even
if later is changed in the meantime on
the other hand assignment from memory
stored reference types to another memory
stored reference type do not create a
copy okay so the next type of diff
structures is mapping mapping types are
declared as with the mapping keyboard
then the key type and then the value
type here the ketha it can be almost of
any type except for a mapping in itself
or a dynamically sized array a contract
and a numerator or a struck the value
type can be actually any type possible
including mappings itself now mapping
can be seen as a hash table which are
virtually initialized such that every
possible key exists and is mapped to a
value whose bike representation is all
zeros a types default value so the
similarity ends here the key data is not
actually stored in mapping only it’s
actually stored in a KC CAK 256 hash
table while it is looked up so because
of this mapping do not have a length or
a concept of a key of value being set ok
guys so now that I explain mapping let
me show you guys a quick example of how
mappings work and solidity so let’s head
over to remix first and let’s begin so
we say something like drag maja solidity
contracts
so example of mapping
so we first create a mapping of which
address and points to a um I will call
these balances
we can have a function to update these
you
so as you guys can see you don’t
actually have a counter and we have to
actually do it all manually using a
function and that’s there you go you
have an example of a very simple mapping
now let’s move ahead so next we have
function types so as you know like
JavaScript solidity also has support for
functions functions are generally used
for code reusability and for actually
shortening our code in a modulo via so
the definition of a function is pretty
unique for solidity it starts with the
function keyboard and the function name
then you actually specify the parameters
that you’re passing into the function if
any then the visibility specifiers are
discussed then the function modifiers
are put in and in the end you must
specify the return type with the returns
keyboard so in our example here you can
see that we’ve made a function call is
cached now the parameters that are
passed in either round index and the
support index which are both U and type
then the visibility specify is selected
the public the modifier is selected the
constant and the return type has been
specified as a boolean so let’s see what
this visibility specifier and function
modifiers actually are so there are four
types of visibility specify private
public internal and external so when
something is private it is only visible
inside the current contract if it is
public it’s visible externally and
internally put well internal things are
visible only internally and externally
are only visible externally so one might
think why not just use internal whenever
you’re using private and why not just
use external vannamei using public well
X or it’s actually a good idea to use
external / public when you know that
your data is only being referenced
outside your contract in that way you
can be more secure and always consume
less a gas then we have function
modifiers now solidity comes with four
pre-made function modifiers those are
pure view constant and payable so pure
functions are ones that cannot read or
modify the state of a function it is
just a function that actually just
accesses the data now then we have the
view modifier which means that the
function can only view the data types of
that contract if
not change the datatypes next we have
constant four state variables which
disallow engagement and last but not
least we have the payable modifier which
allows a function to receive ether next
we can also build our custom function
modifiers so modifiers can be used to
easily exchange the behavior of
functions for example they can automat
in check a condition prior to executing
the function and these modifiers are
inheritable properties of contracts and
may be overridden method I contracts
tube so this is the Declaration of a
normal modifier so we declare our
modifier with the modifier keyword then
you put in the mod name and then we put
our logic of the modifier in the end we
have to put this under school and
semicolon to say that the function that
the modifier is used after shall be
passed
if only the modifier is remains true so
suppose out here we have example of
modifier so we say that the modifier is
owner so this means we require that the
message sender has to be the owner if
it’s not the owner this part this
underscore part will not be actually
executed so we have a function called
withdraw money and this can be only done
by the owner so the parameters sent are
in this function is the youant amount
and a zonal is the function modifier so
before the function withdraw money is
actually committed this is owner
modifier will be checked if this is
actually true then and then only will
the function withdraw money will be
committed moving on we come to error
handling
now solidity has a very special type of
error handling solidity uses state
reverting exceptions to handle errors
such an exception will undo all the
changes made to the state in the current
call and all its sub calls and also flag
an error to the caller the convenience
function assert and require and we used
to check for conditions and throw an
exception of the condition is not met
the assert function should only be used
to test for internal errors and the
check invariants the require function
should be used to ensure valid
conditions such as inputs or contracts
state variables are met or to validate
return values from calls to external
contracts if use properly and as this
tools can evaluate your contract to
identify the conditions and function
calls which will reach a failing assert
properly functioning code should never
reach of
a third statement if this happens then
is a bug in your contract which you
should definitely try to fix there are
two other ways to trigger exceptions the
remote function can be used to flag an
arrow and the revert the current call it
is also possible to provide a string
message containing details about the
error that will be passed back to the
column the deprecated keyword through
can also be used as an alternative to
remote but throw is not normally used
because it consumes all the gas that has
been used in the current state next and
the last topic of our day is control
structures so like JavaScript even
solidity has control structures and
they’re mostly very similar so aside
from the support for the control
structure switch and go to solidity if
has support for all the control
structures that are there in JavaScript
so we have the if statement we have the
else statement we have the ternary
operators then we have the break
statements and the return statements and
the continue statements also for looping
we have the for loop we have the while
loop and the do-while loop so now that
we’ve learned all these concepts it’s
only time that we start building our own
first very smart contracts using what we
learned today
so let’s start building ok guys so it’s
time to implement all the concepts that
we learned today into a big smart
contract after just collect here so just
hop into remix and go along with me to
actually practice everything Davila
ok so let’s first head over to remix so
I already have that open but as you guys
already might know you can always visit
remix by just going on remixed or
aetherium tour so once you bean on remix
go and press the plus button out here
and we’re gonna give our contract name
so let’s call it a demo so what our
contract is going to do it’s pretty
simple actually we’re going to create a
few getters and setters which are
actually very simple
so these catters and setters are going
to be for instructors and of working in
my company that is a director so suppose
any rec I wanted to run on a blockchain
system somewhere down in the line so we
could just simulate it using something
very similar so let’s get started so
first things first let’s create a contra
actually first we have to specify the
compiler ocean so pragma solidity
zero point four point one eight okay so
let’s
get on creating our contract so contra
at Utrecht our so first of all you’re
gonna have a bunch of instructors and
working in our company that teach all
these courses so let’s create a struct
for these guys so struct struct oh so
the instructor is gonna have a name
let’s get an H first so he’s gonna have
a name and
the subject he teaches now we need to
map all these instructors to an address
so we do that as you guys know by
creating mapping so our mapping is gonna
get mapped from an address to all the
instructor type Thetas that we’re gonna
have so we do that by saying address
point it to the instructor angry caller
call this instructors as it will just
count all the instructors for us next
we actually need an array for all
instructors so we’ll just create an area
of addresses so it’s gonna be dynamic as
we just don’t know how many instructors
we’re gonna have and let’s call this
instructor axe so these are all the
instructor accounts right now let’s
create an event and then instructor info
so events are actually triggered when
you are showing something on the UI
instructor info and we’re gonna show the
name
subject it teaches and eh
so this is our basic is the event I’m
sorry it’s not girly brackets it’s not
the brackets that we used
okay so now we need a function to
actually set them stuff that’s a very
important aspect so this will be a good
proxy functions so function set
instructor so while setting the
instructor we are gonna pass down the
tress isn’t gonna call address a TDR and
then we gotta pass down the age so you
and age the subject
sorry that’s bytes
his name
so we have available constructor and
it’ll be all instructors
chapters and then you pass in the
address of the instructor that you want
to sell it to
next we just go instructor not eh
and instructor George name early equals
to the name so now we’ve successfully
set up our instructors settle which will
actually set the age the subject and the
name of the instructor next we need a
few ghetto functions so what you gather
functions do they can be inferred a few
just set it so you go function get
instructor so since you’re only reading
four values it’s gonna have the view
modifier so that’s a very good use of
the view modify that we just learnt in
this tutorial so and now this is gonna
return the address to address it’s gonna
turn instructor accounts turn instructor
so that’s done now we need so this is
only when you’re not passing in any
argument so what if we actually pass in
the argument up in address of an
instructor so let’s create a getter for
that too since chapter so this shows you
all that and two functions are the same
name they get compared according to the
parameters just like you even this is
gonna be view coming public to that’s
gonna return basically the same thing on
returns
th
the bite and an otherwise so basically
out here the UN down is going to be
returned out here is the H and the two
bytes are named and the subject
respectively so we need to return
instructor
grass dot age
so let’s just copy this breaker
execution you’re on the h2 name and the
subject so this is also a very good
example of returning multiple values
from a function now we can also have a
function to count all the instructors
let’s make that so count instructor view
public and it’s gonna return you int
which is basically the length so it’s
gonna return instructor stop length
mm chakras is assisting mappings on a
lens say I returned instruction
and there you go you have your contract
set up so let’s try putting some custom
modifiers into this also
so suppose we only wanted the order of
this thing to actually be able to run
this thing
so let’s go contract own it’s a new
contract for us and let’s store the
address of the owner somewhere and
so he set the owner to the message
sender I’m sorry spell owner out here so
order is the message sender and
basically then we have to create or
modify adapt he used to apply so modify
you only
and let’s see how we can do it so should
check the message handle is the owner so
we can go for a require we require
message dot said no equals equals your
owner don’t forget to put the semicolon
so that your function gets executed and
they’ve done so now we actually mean for
this
we owned okay so we’re done so we
implemented a structure of a contract we
implemented custom modifiers we saw the
visibility specifiers we used mappings
we used rocks we saw the different kind
of functions that we can create a view
function in a normal function and we
also saw how to return multiple types of
values from one function in itself so
this is how you can create a really
simple smart contract for actually
practicing everything you’ve learnt in
today’s video so let’s just give it a
run once so for running our thing going
to run top and you just click deploy so
as you can see we have our set
instructor function ready so we can pass
in the address out here then we could
show us command what else if we have to
pass let me just give it a quick check
address then the age the subject so the
age let’s make him 45 years old subject
he teaches blockchain
and his name is aria
so now we said the instructor as you
guys can see here my instructor has been
said
and that’s how you do it
so basically that was it for me so let’s
get back to the video for months before
I actually end let me tell you guys
about aetherium course on anti raka so
we added a cot each aetherium in a very
structure in modulo 8 it make you go
through the beginner level of topics
like blockchain 101 and to advanced
topics like basics of solidity and
decentralized application development
any rekha is an online training platform
but live instructor led sessions at a
directa we also have a 24/7 support team
that is there to guide you through your
technical and non-technical issues
related to your course when you sign up
for a batchat at eureka you are given
access to the learning management system
which contains all your documents all
your powerpoint presentations and even
little classes that you’ve actually
missed out secondly if you’re not
satisfied through go through of a course
at Ida Drecker you can always sign up
for future batches for completely free
of cost and above that for any other
questions that you have regarding the
course there’s always the Edit record
community where you can post your
questions freely and get answers from
technical experts so that’s it from me
guys I hope I was successful in teaching
a bit of solidity to you and I hope
you’ll practice bit more solidity at
home that’s it for me goodbye I hope you
have enjoyed listening to this video
please be kind enough to like it and you
can comment any of your doubts and
queries and we will reply them at the
earliest do look out for more videos in
our playlist and subscribe to any rekha
channel to learn more happy learning

1 thought on “Smart Contracts Programming Tutorial | Solidity Programming Language | Solidity Tutorial | Edureka

  1. Got a question on the topic? Please share it in the comment section below and our experts will answer it for you. For Edureka Ethereum Developer Training Curriculum, Visit our Website: http://bit.ly/2Gv3yZI

Leave a Reply

Your email address will not be published. Required fields are marked *