Blockchain

Ethereum Smart Contracts Tutorial | Deploying Smart Contracts | Blockchain | Edureka Rewind



๐Ÿ”ฅ๐„๐๐ฎ๐ซ๐ž๐ค๐š ๐๐ฅ๐จ๐œ๐ค๐œ๐ก๐š๐ข๐ง ๐‚๐ž๐ซ๐ญ๐ข๐Ÿ๐ข๐œ๐š๐ญ๐ข๐จ๐ง ๐“๐ซ๐š๐ข๐ง๐ข๐ง๐  ๐‚๐จ๐ฎ๐ซ๐ฌ๐ž : https://www.edureka.co/blockchain-training (๐”๐ฌ๐ž ๐‚๐จ๐๐ž: ๐˜๐Ž๐”๐“๐”๐๐„๐Ÿ๐ŸŽ)
This Edureka Ethereum Smart Contracts Tutorial (Ethereum blog: https://goo.gl/9vFwJj ) video will give you a complete understanding on Ethereum and Smart Contracts. This video helps you to learn following topics:
1. Why is Ethereum needed?
2. What is Ethereum?
3. Types of Ethereum Accounts
4. Smart Contracts
5. Solidity
6. Ethereum Virtual Machine and Gas
7. Demo: Deploying Smart Contracts
8. Blockchain Use Cases: DApps and DAOs

๐Ÿ”ด Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV

๐Ÿ“Feel free to share your comments below.๐Ÿ“

๐Ÿ”ด ๐„๐๐ฎ๐ซ๐ž๐ค๐š ๐Ž๐ง๐ฅ๐ข๐ง๐ž ๐“๐ซ๐š๐ข๐ง๐ข๐ง๐  ๐š๐ง๐ ๐‚๐ž๐ซ๐ญ๐ข๐Ÿ๐ข๐œ๐š๐ญ๐ข๐จ๐ง๐ฌ

๐Ÿ”ต DevOps Online Training: http://bit.ly/3VkBRUT
๐ŸŒ• AWS Online Training: http://bit.ly/3ADYwDY
๐Ÿ”ต React Online Training: http://bit.ly/3Vc4yDw
๐ŸŒ• Tableau Online Training: http://bit.ly/3guTe6J
๐Ÿ”ต Power BI Online Training: http://bit.ly/3VntjMY
๐ŸŒ• Selenium Online Training: http://bit.ly/3EVDtis
๐Ÿ”ต PMP Online Training: http://bit.ly/3XugO44
๐ŸŒ• Salesforce Online Training: http://bit.ly/3OsAXDH
๐Ÿ”ต Cybersecurity Online Training: http://bit.ly/3tXgw8t
๐ŸŒ• Java Online Training: http://bit.ly/3tRxghg
๐Ÿ”ต Big Data Online Training: http://bit.ly/3EvUqP5
๐ŸŒ• RPA Online Training: http://bit.ly/3GFHKYB
๐Ÿ”ต Python Online Training: http://bit.ly/3Oubt8M
๐ŸŒ• Azure Online Training: http://bit.ly/3i4P85F
๐Ÿ”ต GCP Online Training: http://bit.ly/3VkCzS3
๐ŸŒ• Microservices Online Training: http://bit.ly/3gxYqqv
๐Ÿ”ต Data Science Online Training: http://bit.ly/3V3nLrc
๐ŸŒ• CEHv12 Online Training: http://bit.ly/3Vhq8Hj
๐Ÿ”ต Angular Online Training: http://bit.ly/3EYcCTe

๐Ÿ”ด ๐„๐๐ฎ๐ซ๐ž๐ค๐š ๐‘๐จ๐ฅ๐ž-๐๐š๐ฌ๐ž๐ ๐‚๐จ๐ฎ๐ซ๐ฌ๐ž๐ฌ

๐Ÿ”ต DevOps Engineer Masters Program: http://bit.ly/3Oud9PC
๐ŸŒ• Cloud Architect Masters Program: http://bit.ly/3OvueZy
๐Ÿ”ต Data Scientist Masters Program: http://bit.ly/3tUAOiT
๐ŸŒ• Big Data Architect Masters Program: http://bit.ly/3tTWT0V
๐Ÿ”ต Machine Learning Engineer Masters Program: http://bit.ly/3AEq4c4
๐ŸŒ• Business Intelligence Masters Program: http://bit.ly/3UZPqJz
๐Ÿ”ต Python Developer Masters Program: http://bit.ly/3EV6kDv
๐ŸŒ• RPA Developer Masters Program: http://bit.ly/3OteYfP
๐Ÿ”ต Web Development Masters Program: http://bit.ly/3U9R5va
๐ŸŒ• Computer Science Bootcamp Program : http://bit.ly/3UZxPBy
๐Ÿ”ต Cyber Security Masters Program: http://bit.ly/3U25rNR
๐ŸŒ• Full Stack Developer Masters Program : http://bit.ly/3tWCE2S
๐Ÿ”ต Automation Testing Engineer Masters Program : http://bit.ly/3AGXg2J
๐ŸŒ• Python Developer Masters Program : https://bit.ly/3EV6kDv
๐Ÿ”ต Azure Cloud Engineer Masters Program: http://bit.ly/3AEBHzH

๐Ÿ”ด ๐„๐๐ฎ๐ซ๐ž๐ค๐š ๐”๐ง๐ข๐ฏ๐ž๐ซ๐ฌ๐ข๐ญ๐ฒ ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ๐ฌ

๐Ÿ”ต Post Graduate Program in DevOps with Purdue University: https://bit.ly/3Ov52lT

๐Ÿ”ต Advanced Certificate Program in Data Science with E&ICT Academy, IIT Guwahati: http://bit.ly/3V7ffrh

๐Ÿ”ต Advanced Certificate Program in Cloud Computing with E&ICT Academy, IIT Guwahati: https://bit.ly/43vmME8

๐Ÿ“Œ๐“๐ž๐ฅ๐ž๐ ๐ซ๐š๐ฆ: https://t.me/edurekaupdates
๐Ÿ“Œ๐“๐ฐ๐ข๐ญ๐ญ๐ž๐ซ: https://twitter.com/edurekain
๐Ÿ“Œ๐‹๐ข๐ง๐ค๐ž๐๐ˆ๐ง: https://www.linkedin.com/company/edureka
๐Ÿ“Œ๐ˆ๐ง๐ฌ๐ญ๐š๐ ๐ซ๐š๐ฆ: https://www.instagram.com/edureka_learning/
๐Ÿ“Œ๐…๐š๐œ๐ž๐›๐จ๐จ๐ค: https://www.facebook.com/edurekaIN/
๐Ÿ“Œ๐’๐ฅ๐ข๐๐ž๐’๐ก๐š๐ซ๐ž: https://www.slideshare.net/EdurekaIN
๐Ÿ“Œ๐‚๐š๐ฌ๐ญ๐›๐จ๐ฑ: https://castbox.fm/networks/505?country=IN
๐Ÿ“Œ๐Œ๐ž๐ž๐ญ๐ฎ๐ฉ: https://www.meetup.com/edureka/
๐Ÿ“Œ๐‚๐จ๐ฆ๐ฆ๐ฎ๐ง๐ข๐ญ๐ฒ: https://www.edureka.co/community/

Please write back to us at sales@edureka.co or call us at IND: 9606058406 / US: 18338555775 (toll-free) for more information.

Hi guys this is tra from edureka and welcome to this interesting tutorial on ethereum now before we move forward let’s have a look at our agenda for today so we’re going to start by developing an understanding of what ethereum is then we’ll move on to talk about the types of ethereum accounts

Following which we’ll see what smart contracts are well these contracts have been made popular in the recent years due to their implementation in blockchain after this we learn about the evm on which these contracts are executed then I’ll also tell you how to practically deploy smart contracts on

The ethereum blockchain under a test environment and towards the end of this session we’ll talk about the real life use cases of the ethereum blockchain these are the decentralized applications and the decentralized organizations now before we start with our first topic let me just brief you on why ethereum is

Needed well most of you here might already be familiar with the Bitcoin blockchain Bitcoin is the original blockchain entity for providing a decentralized system to facilitate peer-to-peer exchange of values ethereum on the other hand came up from the idea that blockchain could be used for a number of purposes beyond the

Bookkeeping of financial transactions so we can also say that ethereum maximizes the usage of potential blockchain applications now coming back to our original topic that is what exactly is ethereum so guys ethereum is an open-source distributed platform that allows decentralized apps to be built on it with the help of smart contract

Functionality it was developed by wallic butan as an extension to the original core blockchain concept let me give you an analogy think of the etherum network as a collection of decentralized and distributed vending machines now you go and you put in tokens inside these vending machines and then specify the

Action that you want to be taken by pressing in the numbers now whenever each number is pressed a certain code gets executed inside the machine these are the smart contracts and then a service is provided to the concerned user on the network now the tokens that you had put inside the machine were

Actually ethers ethers are the cryptocurrency token of the ethereum network and they’re used to pay for the transaction fees there’s also another parameter called gas about which we’ll talk later that is used to pay for the computational services on the ethereum network now since we’re still talking about transactions over here I’m sure

Some of you might be wondering why was there a need to develop ethereum in the first place when Bitcoin blockchain already existed so I’ll give you a clear understanding on how ethereum differs from the Bitcoin blockchain on various fronts now firstly both these blockchains are conceptually different

From each other while Bitcoin score idea was to bring a decentralized digital money that is not governed by anyone ethereum although a derivative extends beyond the realm of cryptocurrencies that is why it is also referred to as the second generation of blockchain now talking about the cryptocurrency tokens

Bitcoin crypto is named after itself and it’s called Bitcoin cash whereas ethereum’s crypto token is called ethers like we just discussed now coming to the scripting language ethereum is a toring complete scripting language whereas bit coin is a simple stack based language and it is not toring complete what I

Mean when I say the word toring complete is a language that can solve any computational problem by itself given enough time and energy now next we come to the consensus algorithms Bitcoin uses the sh 256 hash algorithm while ethereum’s algorithm is called I hash both of these are proof of work

Currently however ethereum will move to proof of stake in the near future as a part of its scale avability plan now proof of stake is still an algorithm with the same purpose as proof of work but unlike it where the minors are rewarded for solving the mathematical problem with the goal of validating

Transactions and then creating a new block with proof of stake the creator of the block is chosen depending on its wealth or stake so more the number of tokens you own more would be your mining power now even the coin release method of both the blockchains were different

While Bitcoin came through the mining of the Genesis block so the first minor earned some Bitcoins as a reward ethereum’s coins were released through initial coin offerings to raise funds for the new cryptocurrency the average block creation time of both the blockchains vary where it takes around 10 minutes

For each new block to be created on a Bitcoin blockchain in the ethereum blockchain a new block is formed in every 15 seconds this is quite faster now since we’re talking about ethereum we have to discuss about the types of ethereum accounts accounts as we can see

Here there are two types of ethereum accounts the externally owned accounts that are owned by people or organizations and the contract accounts which are autonomous in nature now these externally owned accounts are controlled by private Keys which are owned by individuals but on the other hand the contract accounts have Associated

Contract codes and these are triggered by the transactions or the messages received by other contracts or other externally owned accounts now the contracts that we are talking about here are actually the smart contracts contract accounts operate on codes which are written in smart contracts now the users can create a new contract by

Deploying code to the blockchain now guys smart contracts are basically immutable pieces of codes that run on the ethereum network to perform a certain transaction or task and when these contracts are running on the blockchain they act like a self-operating computer program that automatically executes when specific conditions are met

Let me give you an example of this a contract between two parties is written as a code on the blockchain now the individuals involved are Anonymous but the contract is public to everyone on the blockchain so when a triggering event occurs which in this case is a bet

On an ongoing cricket match the contract executes itself according to the terms of the code therefore if england wins the match Bob will receive 10 ether but if England loses the match Andy will receive 10 ether and both their wallets will be updated accordingly now the codes in these smart contracts are

Written in a special contract specific language called solidity a question will naturally arise over here that why was there a need to develop a contract specific language why could we just use the already existing languages like C C++ Java instead so let’s see why solidity is preferred over other

Languages now solidity syntax is very similar to JavaScript it was developed because using the mainstream languages on a public blockchain won’t really add value cuz firstly there are security requirements you see anything that gets recorded on the blockchain becomes immutable so there is absolutely no window for bu fixes and secondly it

Costs money for executing each instruction on the program so if you were to use C language or serpent for example to write a smart contract then you may end up with a very expensive contract and not even know why if you guys want to create your own smart

Contract then you can do that by using the remix IDE now this is a browser based IDE and it’s widely used for developing the smart contracts since it has an integrated debugging and testing environment now here’s what a remix IDE looks like the contract codes are written over here this is the compile

Tab now whenever a new line of code is added to the contract it gets compiled a automatically this is the Run tab under which we can specify the environment the account addresses along with the associated number of ethers the gas limit and the value in ways now every

Time you write a code here you can create a contract by clicking on the create button now guys we’ll be writing a demo contract to understand better how all of this works but before that let me talk about the evm where all of these contracts are actually executed

Evm or the ethereum virtual machine is a teing complete software that runs on the ethereum network it enables anyone to run a program regardless of the programming language and even non-specialized programmers can create a program on the evm let me tell you how all of this works a user requests two

Ethers for example from the sender now the sender initiates the transaction message code and must pay for each step of the program that they activated including the computations and the memory storage now this fee is paid in ethers which is taken from the wallet of the sender then this transaction fee is

Collected by the nodes in the network that run the evm now each and every node of the network runs the evm to execute the same instruction and this is how the blockchain database is maintained and updated by the many nodes connected to the network now all of these nodes are

Actually the minor nodes that execute and verify the transactions and then update the state of the accounts on the ethereum blockchain in turn they’re rewarded with ethers for each successful block mining now once the transaction is verified and recorded the user gets two ether in his wallet now I’m sure some of

Your programmers out there might be wondering the same as what our little guy here is thinking about that if the evm is running the application code then what’s preventing a piece of code from running forever and overloading the network well here’s where the term ethereum gas comes in now gas is

Basically the execution fee that the sender pays for running a program on the evm it’s called gas because the fee acts as a crypto fuel driving the execution in smart contracts now every contract specifies the gas limit which is the maximum quantity of gas that can be

Consumed if you guys want you can just go to your browser and type in the eth gas station and click on the first link now here’s where you can see the gas used for the current trans action you can also see the gas price and the

Top 10 miners that have mined the blocks you can see the cheapest gas price and the highest gas price and also the confirmation time by the gas price now gas price is specified at the start by the initiator of the transaction now as the transaction starts the gas used

Times gas price number of ethers are subtracted from the sender’s account so when a program crosses the gas limit the execution reverts and and the ethers are not refunded so guys it’s very important to keep your program well within the set limits of the gas okay guys now we come to the most

Interesting part of our tutorial that is how to deploy smart contracts so we’ve just learned that smart contracts must pay gas for the computations on the ethereum network hence if you rent the ethereum network to run a contract you’d have to pay for it so before deploying an actual

Contract on the ethereum blockchain we need to experiment CU we cannot afford to make any mistakes as anything deployed on the blockchain becomes immutable and caost gas so we use test nets for developing demonstrative smart contracts and these test Nets simulate the ethereum network with providing free

And unlimited gas so this allows the developers to test contracts without having to pay real money for the execution now I’ll walk you through setting up a development environment so that you can deploy and test your own smart contracts on the ethereum test blockchain we’re going to create a test

Environment on the abantu Linux platform and since I myself have the Windows operating system I’ll be using the Oracle virtual box to run obuntu now let’s open the CLI to run a network we need a server so we need to install nodejs and the node package manager since nodejs will simulate the

Test server on our local machine npm or the notepad package manager is a command line interface program to manage the nodejs libraries now we’ll run the following command on our terminal to install nodejs Pudo apt get install node.js we’ll type in the password it’s asking for confirmation

Tap why and now we’ll just wait for our nodejs to get installed now we’ll also install the npm package for that we’ll use the same installation command Pudo APG get install npm do you want to continue yes and now we’ll just wait for npm to get installed as well

All right let’s just check the version of the nodejs and the npm that we have installed so we’ll type in node.js hyphen V the version is 4.2.6 and npm hyphen V the version is 3.5.2 now guys this is not the latest version so we need to upgrade our

Notepad packages since we need the upgraded versions for running the further commands for that we need to install curl first so we’ll type the installation command Pudo ABG get install curl now curl is a tool that is used to transfer data from the server now we have installed curl so

We’ll just pull the entire note package from curl and for that we’ll use the following link now note that the 6.x here denotes the version of the nodejs that is 6 that we want to install now we’ll install the latest nodejs package using the same installation command Pudo appg get install node.js

Do you want to continue of course I do and now we’ll just wait wait for our latest nodejs package to get installed now let’s check the nodejs version nodejs hyphen V the version is 6.13 so it’s cool now let’s upgrade our npm as well and for that we’ll use the following

Command pseudo npm upgrade npm hyphen G now hyphen G is used for the global installation so that we can access it throughout our system now we’ll just wait for our npm to get updated so guys our npm has upgraded to version 5.7 which is great now let me

Just clear the screen for your convenience okay now guys we need to run the test test RPC on our terminal to deploy and test our blockchain contract now test RPC is a nodejs based ethereum client for testing and development for that we need to create a test RPC file

So we type in the following command Pudo npm install hyph G ganach CLI now note that P Sudo is used so that the user has an authority over the existing files ganach CLI only runs when our nodejs version is at least greater than 6.11 and ours is 6.13 which looks

Good so now we’ll just wait for it to get installed this might take a little while now to install the test RPC file we’ll run the following command Pudo npm install hyph G ethereum JS test RPC with this command We’ll add all the note packages on our local

Machine so now we have created our test RPC file now let’s run it and see what happens all right looks great the test RPC is running and listening on Local Host 8545 now guys you can see the available accounts as well as the private Keys over here and we’ll be using these for

Our contract deployment okay now we just open a new terminal because our test RPC is running on this one let me increase the font okay now next what we need to do is install the block Explorer to help us keep track of the information on the blockchain for that we first need to

Install git now git is a distributed version control system that holds the repository of our block Explorer in this case so for that we’ll use our installation command that is Pudo apt get install git we’ll enter the password and seems like I already have git on my system but anyway you can use

The same command to install git on your system systems as well okay now we need to get a copy of the Explorer on our local machine and so we’ll use the following command git clone https github.com ether party/ Explorer now we can see that it’s cloning into Explorer now it’s basically

Pulling a clone of the repository from the cloud to our system okay so it’s done now we’ll just change the direct Dory to the Explorer by using the following command CD Explorer now guys CD here stands for change directory we’ll just press enter and now we can

See that our directory has been changed to Explorer okay now guys if you want to launch the block Explorer You’ll Use the following command pseudo npm start now this command will install all the packages on our system okay so we’ll just wait for it to get installed

Now we can see the Explorer running on Port 8,000 over here all right now guys if you want to view the blog Explorer you simply need to go to your web browser I installed Chrome because it’s preferable to me and then type in Local Host 8000 on the browser

Tab now here we can see The Ether block Explorer page has been opened opened and this is where all the transactions are being recorded on the ethereum test Network so now that we have set up our test environment let’s create a demo smart contract to deploy it on our

Ethereum test blockchain for that go to your browser and open the remix ID now go to the Run tab and specify the environment as web3 provider they’ll ask you if you want to connect to an ethereum node click okay our web3 provider endpoint is Local Host

8545 click okay again now guys if this message pops up that it’s not possible to connect to the web3 provider then all you need to do is go to your browser tab click here and load the unsaved scripts now we’ll go to our Run tab again and specify the environment once

More click okay click okay now we can see the associated accounts that were in our test RP PC file that we created along with the associated number of ethers as well okay if you want you can go to your file location and just open the test RPC file now these are all

The account addresses and this is the same as you can see over here okay now we’ll create a demo contract so that you guys get an idea about how a smart contract is executed now we’ll write a contract to increase and decrease the value of the variable

Let’s say named counter so we’ll just open a file and let’s name it my contract 001 now these contracts are basically a collection of code functions that correspond to a specific account address on the blockchain as you can see here so now we’ll start writing our contract for

That we’ll first specify the source code version so we’ll type in pragma solidity version 4.1 now guys note that the latest version of solidity is 4.16 but that won’t be supported by our system so I’m using 4.1 if you want you can use 4.16 that will not really

Make any difference in the program that we are writing right now okay now pragma is the instruction for the compiler about how to treat the source code now since we’re creating a contract we’ll use the keyword contract and let’s name it as my contract now our entire contract would

Be written within this scope now we’ll specify our state variable that is counter with the value five so we’ll type in U in 256 counter equal to 5 don’t forget the semicolons guys now u in 256 is basic basically the type of the variable that is unsigned integer of 256 bits now this

Creates a slot in the database that can be access whenever a function in the code is called now also note that we need to keep the state variable outside of all the functions so that they can be accessed globally now we’ll write a function say add which will increment the value of

Our counter by one counter Plus+ okay similarly we’ll create another function let’s call it subtract and this function would be used to decrement the value of counter by one so we’ll write counter minus minus okay now note that the axis modifier in both these functions is public guys although

Public is the default modifier when no visibility is specified typing out the function visibility is a good habit so you should always do it now there are other AIS modifiers like external internal or private but we do not need to know about them right now what we

Need now is a function to Output the value of the counter as it changes with the functions called so we’ll just write a function and we’ll name it get counter get counter the axis modifier is public here as well and since this function is going to return a constant so so we’ll

Use in the constant keyword return counter now guys note that we must tell our function the type of the state variable it will return so we have specified u in 256 over here since this is the type of our counter State variable now whenever a function is

Called a small amount of gas is penned but no gas is required when returning a constant function all right so guys we’ve just finish creating our very first contract on the remix IDE now let’s test our first contract by clicking on the create tab here you can

See all the three functions that we have created just now now if you tap on get counter we get the value of our counter as five if you tap on ADD once and then again on get counter you’ll see that our value of counter has incremented by one

And has become six now now let’s tap on subtract twice and then again on get counter we see that the value of our counter is four now all right now we’ll open our block Explorer to see the details of this transaction here we’ll just refresh it

And as you can see here our contract has been successfully deployed on the ethereum test blockchain so now we have seen how the ethereum is used as a platform to create smart contracts now guys once you start creating your contracts and deploy and and execute them on your blockchain you’ll be ready

To get started with creating full-on decentralized applications now we’re not going to go into details of the dab development but I’ll introduce you to what dabs are well a decentralized application or a dab is a set of smart contracts that operate on the data stored in those contracts now

An application qualifies as a Dap only when it is open- sourced when it’s decentralized it has tokens fueling for itself it generates tokens and has an inbuilt consensus mechanism now these dabs enable direct interaction between the users and the providers and they’re comprised of various organizations that work together to create an application

Now these organizations are basically the decentralized autonomous organizations or the Dows now guys a DA is very similar to a normal company now the only difference is that in a normal company there is a third party of course and and the rules are not enforced digitally but the Dows have their

Business decisions made electronically through the codes written in the smart contracts or through the vote of their members now the priority of these votes depend on the percentage of the assets that the entities within a dow hold let me tell you in detail how all of this

Happens people add funds to the Dow and are given tokens to represent their percentage of assets so more you invest more number of tokens you would hold now when a dow begins to operate the members propose on how to spend the funds and based on the votes The Proposal status

Is decided this way you do not need a third party to depend on and hence more effective operations can take place a number of possibly disruptive dabs have already appeared in the market and are continuously being deployed on the ethereum platform a few of them being y fund 4G capital

Store.io and the kyc chain now these are a few of the most famous dabs and Dows that are in the market currently wund is a DB that uses the smart contracts to enhance crowdfunding services like GoFundMe and Kickstarter 4G capital is a dow that provides microloans for small businesses in

Africa store.io provides censorship free secure cloud storage by sharing data among a decentralized network of computers and last but not the least the kyc chain allows the users to maintain a private identity wallet that can be used to authenticate the identification in finance and commerce settings guys with this we come towards

The end of our session so let’s summarize what all we have learned in this tutorial now we know what ethereum is and about the types of ethereum accounts we learned about the smart contracts and the evm we also performed a practical demo on how to deploy the

Smart contracts and towards the end we talked about the future of ethereum now if you guys have any queries or if there is anything more you want to learn about ethereum feel free to write down in our comment section below with this I take your leave thank you and goodbye

Write A Comment

Share via