Contents
- 1 Ethereum Tutorial – An Indepth Look at Ethereum!
Ethereum Tutorial – An Indepth Look at Ethereum!
Ethereum Tutorial
This Ethereum Tutorial blog will cover the architecture of Ethereum and show how it is implemented through a simple smartcontract.
Ethereum is a programmable blockchain I believe will be used by the majority of B2C enterprises in the future. Ethereum allows developers to create complex models that can be executed on the blockchain. This is in contrast to the Bitcoin blockchain which restricts them to predefined operations.
This approach has made Ethereum a platform for many decentralized applications and organizations, including crypto-currencies.
Through the “Ethereum Tutorial”, I will be covering many topics in an extensive manner. These topics include:
See more products : Magento POS, BigCommerce POS, Shopify POS, Woocommerce POS, Restaurant POS, NetSuite POS, Thailand POS, South Africa POS and Commercetools POS
This recording of Ethereum Tutorial may be viewed. Our instructors have discussed the topics in detail with real world problems and projects that will help you better understand this concept.
See our services : blockchain development service, Backbase, system integration services, workflow management software, enterprise integration platform,
Ethereum Smart Contracts
Ethereum Tutorial. Ethereum Accounts
There are two types of Ethereum accounts:
- External Accounts
- Contract Accounts
These accounts, both Contract and External, are called “state objects” in the ethereum system and constitute the “state”. Each state object has its own state. The state of external accounts consists of the balance, while contract accounts are defined by the balance and memory storage.
External accounts will be simply referred to as accounts. These accounts are managed by external agents who are made up of all users, miners and automated agents.
These accounts can be managed using public key cryptography algorithms such as RSA. External accounts are used to allow users to interact with Ethereum Blockchain.
Contract accounts are code collections that reside on the blockchain at a particular address. These contracts can be invoked by external accounts or other contracts via a specific call to-action function. These contracts are written using high-level scripting languages such as Solidity, Serpent, or LLL. Each contract stored on the Ethereum blockchain is saved in an EVM (Ethereum Virtual Machine), bytecode, which is a specific binary format.
It is fair that I now explain EVM after I have already explained EVM-bytecode.
Blockchain Certification Training Course
- Instructor-led Sessions
- Real-life Case Studies
- Assignments
- Access for Life
Ethereum Tutorial
In a simple way, Ethereum defines a group of generalized protocols that have been the foundations for the development decentralized applications. The Ethereum Virtual Machine is at the heart of all this. This diagram explains the architecture.
Important to remember that the Ethereum Virtual Machine is completely isolated and sandboxed. The EVM is completely isolated, meaning that any code running at the moment has no access to either the network or the files system. However, it can access some other contracts.
Let’s now look at the network nodes.
Ethereum Tutorial The Ethereum Network
The ethereum blockchain network is a public network of blockchains. It is the foundation of all peer-to-peer decentralized applications and organizations that run on the network. There are two types of nodes in the network: full nodes or light-weight nodes.
Full Nodes include the complete history of transactions from the genesis block. They provide a complete proof of the network’s integrity. Each transaction must be contained in full nodes that have been verified to conform to the Ethereum specifications.
The light-weight nodes only have a subset the whole blockchain. These nodes are most commonly used in ewallets, which must be lightweight in nature so that the entire blockchain can be stored on them. These nodes do not verify each block or transaction and they may not have a copy the current state of the blockchain. They depend on full nodes for missing details or functionality. The advantage of light nodes is that they can get up and running much more quickly, can run on more computationally/memory constrained devices, and don’t eat up nearly as much storage.
Each public blockchain is linked to a currency. Ethereum is no exception. Let’s look at Ethereum’s cryptocurrency.
Ethereum Tutorial: Ether and Gas
The name of the crypto-currency Ether used to pay for transactions on ethereum is “Ether”. Apart from being used for transactions, Ether can also be used to purchase Gas which, in turn, is used for computation within EVM.
Ether is the metric unit. It has many denominations that can be used to accurately pay for transactions or gas. Wei is the smallest denomination, also known as a base unit. Below is a table listing the denominations and their names.
Units | Wei Value | Wei |
Wei | 1 wei | 1 |
Kwei | 1e3 wei | 1,000 |
Mwei | 1e6 wei | 1,000,000 |
Gwei | 1e9 wei | 1,000,000,000 |
microEther | 1e12 wei | 1,000,000,000,000 |
milliEther | 1e15 wei | 1,000,000,000,000,000 |
Ether | 1e18 wei | 1,000,000,000,000,000,000 |
We know that EVM runs the code that is installed on its network, as we discussed previously. What’s the stopping factor for someone running an endless loop on EVM, causing it to overload its memory? Gas is the answer to this problem.
Gas is used to pay for computing resources on the network. Each contract on the network is limited in how much gas it can use to compute. This is called the ” Limit“. Other terms that are associated with gas terms include:
- Gas price: This represents the cost of gas using tokens such as Ether or other denominations. Gas Price is a floating price that helps to stabilize gas’s value. It can fluctuate with currency or token costs, but the Gas Price will remain the same.
- Gas Fee – This is the cost of gas to execute a specific transaction or program (called an agreement).
If someone attempts to run code that runs forever then the contract’s gas limit will be exceeded and the entire transaction will be rolled back.
Blockchain Training
Let’s now look at how new currency is created.
Ethereum Tutorial
Ethereum, like all other public blockchain technologies, ensures security via an incentive-based model. This is known as a proof of work mechanism. This figure shows you how ethereum mining works.
Technically speaking, Ethash is the proof-of work algorithm. It is an algorithm that uses a hashing algorithm inspired from the Dagger-Hashimoto algorithm.
Let’s now look at a real-world problem, and discuss the ethereum approach.
Ethereum Tutorial: A Decentralized Crowdfunding Use Case
Problem Statement A great idea is not enough to make a business a success in today’s market. To implement an idea, it takes a lot of effort and funding. Organizations like “Kickstarter”, can help with this. These organizations provide public exposure for projects to raise funds towards the project’s success. However, the central architecture of such a motive can have its downfalls, especially in the way rewards are managed. Systems are susceptible to rules such as:
- Anyone who missed the deadline cannot enter the campaign again
- Any donor who changes their mind cannot get out
Approach:
As shown in the image below, we use a decentralized approach to solve the problem.
Solution:
For the above problem statement, here is the solidity smartcontract.
Blockchain Certification Training Course
pragma solidity ^0.4.16; interface token function transfer(address receiver, uint amount); contract Crowdsale { address public beneficiary; uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price; token public tokenReward; mapping(address => uint256) public balanceOf; bool fundingGoalReached = false; bool crowdsaleClosed = false; event GoalReached(address recipient, uint totalAmountRaised); event FundTransfer(address backer, uint amount, bool isContribution); /** * Constrctor function * * Setup the owner */ function Crowdsale( address ifSuccessfulSendTo; // the address of the owner when funding is successful uint fundingGoalInEthers; // target amount to raise uint durationInMinutes; //given time uint etherCostOfEachToken; //cost of equity in ether address addressOfTokenUsedAsReward; //token address ) beneficiary = ifSuccessfulSendTo; fundingGoal = fundingGoalInEthers * 1 ether; deadline = now + durationInMinutes * 1 minutes; price = etherCostOfEachToken * 1 ether; tokenReward = token(addressOfTokenUsedAsReward); /** * Fallback function * * The function without name is the default function that is called whenever anyone sends funds to a contract */ function () payable require(!crowdsaleClosed); uint amount = msg.value; balanceOf[msg.sender] += amount; amountRaised += amount; tokenReward.transfer(msg.sender, amount / price); FundTransfer(msg.sender, amount, true); modifier afterDeadline() if (now <= deadline) _; /** * Check if goal was reached * * Checks if the goal or time limit has been reached and ends the campaign */ function checkGoalReached() afterDeadline if (amountRaised >= fundingGoal) fundingGoalReached = true; GoalReached(beneficiary, amountRaised); crowdsaleClosed = true; /** * Withdraw the funds * * Checks to see if goal or time limit has been reached, and if so, and the funding goal was reached, * sends the entire amount to the beneficiary. Each contributor can withdraw the amount contributed if the goal is not met. */ function safeWithdrawal() afterDeadline if (!fundingGoalReached) uint amount = balanceOf[msg.sender]; balanceOf[msg.sender] = 0; if (amount > 0) if (msg.sender.send(amount)) FundTransfer(msg.sender, amount, false); else balanceOf[msg.sender] = amount; if (fundingGoalReached && beneficiary == msg.sender) if (beneficiary.send(amountRaised)) FundTransfer(beneficiary, amountRaised, false); else //If we fail to send the funds to beneficiary, unlock funders balance fundingGoalReached = false; }
If you’re interested in learning more about solidity, visit our blog on Solidity Programing. This is useful for creating personalized smart-contracts.
Learn Blockchain Technologies and make a career out of it with our Blockchain Course. This course includes instructor-led live training as well as real-life projects. This training will allow you to understand Blockchain and master the subject.
Got a question for us? We will respond as quickly as possible to your question by commenting in the section below.
source https://www.edureka.co/blog/ethereum-tutorial-with-smart-contracts/