Module 5: Ethereum, Smart Contracts and Solidity
Module 5 examines the origins of Ethereum and how smart contracts operate on Ethereum. Plus, find out more about the programming language Solidity and much more.
Module 4 examined blockchain applications in financial services, this module looks at where Ethereum first began, smart contracts and even how to create your own smart contract using the programming language, Solidity!
Where Ethereum First Began
Communities of blockchain developers and researchers sprang up worldwide after Satoshi Nakamoto published the Bitcoin whitepaper in 2008. Several journals and online blogs emerged, reporting exciting projects and new ideas in the field.
Vitalik Buterin, a Canadian teenager who wrote for Bitcoin magazine, was one of the community members that was moved by the potential of blockchain. As he watched the ecosystem take shape, he noticed a common problem among the projects: many needed to build their own blockchain. Vitalik believed it would be better to create a single blockchain where all developers could build their applications, similar to how others have a single intranet that allows others to build their websites. Developers could then focus on designing their applications rather than figuring out how to establish a blockchain.
The Ethereum Whitepaper
In late 2013, Vitalik published the Ethereum whitepaper. The whitepaper included many concepts that expanded on and refined many of Bitcoin's original ideas. The whitepaper highlighted the limitations of Bitcoin and proposed a new general-purpose blockchain as a solution that could be used as a decentralised application platform. Ethereum would have all the same capabilities as Bitcoin, such as sending transactions between accounts and more. Bitcoin's main problem was the lack of a general programming language that would allow users to create any application on the blockchain. Bitcoin scripts are not Turing-complete, meaning it is not possible to write simple structures like loops.
Ethereum uses a similar mining algorithm to Bitcoin, which is based on proof of work. The algorithm that Ethereum uses is slightly modified from Bitcoin’s mining algorithm in several respects. The issuance for Ether is different from Bitcoin; whereas Bitcoin is capped at 21 million coins, Ethereum has no limit. Instead, Ethereum has an annual cap of 18 million Ether.
One of the motivations for modifying the mining algorithm from Bitcoin was to make it ASIC (application-specific integrated circuit) resistant. As discussed in the whitepaper, the Bitcoin mining algorithm can be exploited using specialised mining hardware known as ASICs. This has led to the centralisation of Bitcoin. In order to prevent mining centralisation in Ethereum, the algorithm was modified to be geared towards GPUs (graphics processing units), which are more commonly available and less likely to be centralised.
Over the years, a rapidly growing public interest in Ethereum has revealed some of its limitations. These limitations included scalability and security. This has led to massive gas fees, for example, minting an NFT on Ethereum typically costs between $60 and $250, depending on the time of day and the load on the network. The more users competing to get their transactions into the next "block" on the chain, the higher the fees.
Because of this, Ethereum has decided to upgrade the network.
Ethereum 2.0 is an updated version of the existing cryptocurrency Ethereum. Ethereum 2.0 was developed to improve Ethereum's scalability, speed, and efficiency. In addition, the updated version aims to increase the number of transactions and eliminate bottlenecks. The shorthand names for Ethereum 2.0 are Serenity, and some people also call it Eth2. Compared to Ethereum, Ethereum 2.0 has elementary changes in its blueprint and structure.
While Ethereum used to work with a consensus method known as proof-of-work, Ethereum 2.0 is based on a sharding and proof-of-stake mechanism.
Sharding is the process of splitting a blockchain into different blockchains. Multiple blockchains in Ethereum 2.0 are often referred to as shards. The sharding process allows the entire network to operate as a single validator to handle the workload as a whole. There are several validators, and each validator must manage its shard, which holds the information. Unlike the blocks in the blockchain, the validators are mixed to prevent alteration or manipulation of the data. In order to coordinate and communicate between the different shards, a chain known as Beacon Chain is used.
Proof of Stake
Ethereum used the Proof of Work consensus method, but Ethereum 2.0 introduced a Proof of Stake consensus mechanism. In the Proof of Work method, some miners mine bitcoins, while in Proof of Stake, there are validators and no miners. The validators create new blocks with enough storage, bandwidth and processing power to verify and validate the transactions.
Like miners, validators receive compensation for their efforts and hard work in creating blocks. However, the validators have to sign a contract in which they have to deposit 32 ETH, which is then locked. This is a type of deposit that validators make, which will be forfeited in the event of fraud or abuse as per protocol. This practice is a significant improvement made in Ethereum 2.0 to prevent fraud.
Layer 2 is a collective term for solutions that allow users to scale their application by processing transactions outside of the Ethereum mainnet (Layer 1), leveraging the mainnet's robust decentralized security model.
There are three popular L2 solutions outlined below:
Arbitrum is a system that allows Ethereum participants to settle their transactions away from the Ethereum mainnet. The platform consists of three main components - Compiler, EthBridge, and Validators. Furthermore, Arbitrum also supports a sidechain aggregation of transactions called rollup technology.
Optimism is an L2 scaling protocol designed to make transactions affordable and faster for Ethereum users. It is a layer 2 rollup solution that handles transactions "off-chain" on an external layer 2 network and then publishes the transaction data on a layer 1 network like the Ethereum mainnet.
Developers can easily create Solidity smart contracts that can be executed on Optimism.
Polygon is a Layer 2 scaling solution designed to help the Ethereum platform gain mass
adoption. It meets the diverse needs of developers by providing tools for building scalable decentralized applications (dApps) that prioritize performance, usability (UX), and security. It is a framework for building and connecting Ethereum-based blockchain networks.
Layer-2 and other alternative blockchain technologies, such as Polygon, run programs that provide the same services as Uniswap and Sushiswap on Ethereum - but without the exorbitant gas fees. These Layer 2 and alternative exchanges are seeing a surge in users, transactions, and revenue.
L2 solutions can be accessed through Metamask. The Metamask blockchain wallet is very flexible, secure, and allows users to switch between different networks like Ethereum, Polygon, and Binance Smart Chain, etc. However, it is necessary to first set up your MetaMask wallet so you can interact with Layer 2 dapps.
What are the differences between Ethereum and Ethereum 2.0?
Ethereum 2.0 is an updated system that is introduced with new functionalities. Ethereum 2.0 aims to improve speed, efficiency, and scalability. The main difference between the older and new versions of Ethereum is the mechanism it is based on and its uses.
Smart Contracts on the Ethereum Network
Smart contracts are simply application logic that can be expressed using operations defined in the EVM, and they can also store data in the blockchain. The Ethereum whitepaper described a currency called Ether and a new runtime environment for smart contracts called Ethereum Virtual Machine (EVM). In mid-2014, a yellow paper was published by Gavin Wood that defined the technical specification of EVM and how it would work. The yellowpaper was used to create several open-source implementations in different languages, the most popular being the Go language known as Geth. The second most popular implementation was written in the Rust language and is called Parity client. Anyone running a client is a node on the Ethereum network.
Solidity is an object-oriented programming language for creating smart contracts on the blockchain that automate transactions. Although the language is mainly used to make smart contracts on the Ethereum blockchain, it can also be used to create smart contracts on other blockchains.
How Can I Create a Smart Contract Using Solidity?
All users can write a smart contract using Solidity and deploy it to the Ethereum blockchain. First, compile the Solidity smart contract into EVM bytecode and send the bytecode to the Ethereum network as part of a transaction. Once the transaction is mined, the smart contract is deployed on the blockchain and given a public address. Others can then interact with the smart contract by sending transactions to its address. Finally, the result of the method invocation is written to the blockchain after the transaction is mined.
If you would like more in-depth step by step instructions on how to create a smart contract, Ethereum has a walkthrough guide available on their website that can be accessed here.
However, beginners need to be mindful that although smart contracts with Solidity are relatively easy to write, it is often challenging to write them securely. For example, if the withdrawal function in a smart contract is not secure, an attacker can manipulate the vulnerable function to drain an account. An attacker could invoke a withdrawal function to send money to another account by using a loop that repeats the withdrawal function. Private functions are only callable within contracts. They contain instructions that can only be executed after being called by other functions in a chain. This makes it harder to manipulate the code by malicious actors.
How Can Solidity Be Used in Ethereum?
Solidity is used to create smart contracts for fungible tokens and non-fungible tokens. In the Ethereum ecosystem, different standards are used to develop non-fungible tokens and fungible tokens. These allow users of the blockchain to create different types of use cases. Solidity enables users to use tokens and non-fungible tokens on Ethereum. From minting non-fungible tokens to adding tokens to yield farming pools for additional interest, Ethereum allows for different ways to use tokens.
Solidity also enables Decentralised Autonomous Organisations (DAOs). A DAO, a type of online organisational structure that is written primarily in Solidity. DAOs allow different people to join together as members on an online platform where they vote on the most critical decisions of DAO.
Other Solidity Use Cases
The Ethereum ecosystem is unique in that it can support a wide range of cryptocurrencies and decentralised apps. Moreover, thanks to smart contracts, unique technologies for businesses and organisations can be created on Ethereum.
Every year, billions of dollars are spent on blockchain solutions around the world. Solidity is used to construct several of these solutions. Solidity-based smart contracts can be viewed as a mechanism to automate business and non-business procedures between parties. This means that those using the blockchain don't have to worry about things like fraud or not being able to use the same money.
Here is a non-exhaustive list of Solidity uses below:
Currently, there are many problems with voting, such as data tampering, fake voters, voting machine tampering, and voting booth capture. Solidity smart contacts can be created and deployed to make the voting process transparent and efficient.
In an open auction, individuals can see each other's bids, leading to disputes and fraud. With Solidity smart contracts, a blind auction can be designed where users cannot see what someone has bid until it's over.
Crowdfunding via smart contracts can solve problems like hiring a third party and managing data. In addition, Solidity smart contracts for crowdfunding do not require centralised systems to build trust, reducing additional costs.
Smart contracts are self-executing, open-source codes that run when certain circumstances are met. Many projects have utilised the Ethereum platform because it allows anyone to quickly develop their own tokens. Many people believe that smart contracts will eventually replace regular contracts because of their open nature. The contract code is known in advance and cannot be changed or altered by malicious parties. In addition, smart contracts are quick to execute and operate autonomously.
Ethereum, Cardano, Solana, and even the Binance Smart Chain are all based on smart contracts, which set them apart from Bitcoin. Cardano and Ethereum are often compared to each other because their blockchain offers similar features, including smart contracts for creating decentralised applications. Ethereum is an open-source blockchain platform with its own currency, ETH. Cardano is a third-generation decentralised proof-of-stake (PoS) blockchain platform that aims to be a more efficient alternative to proof-of-work (PoW) networks.
Ethereum gained more traction with the boom of decentralised finance (DeFi) in 2020. Increasingly, decentralised applications were created to automate financial services such as lending or borrowing without the need for a third-party intermediary.
Congratulations for completing section 1 of the Ardana academy! Join us for the first module of section 2, here.