This article explains the core concepts of Ethereum and Smart Contracts. We will also briefly explore the typical architecture of a Dapp built on the Ethereum network.
A Brief History of Ethereum
Ethereum was conceived by Vitalik Buterin, who was an active participant in the early Bitcoin community and even co-founded Bitcoin Magazine. Recognizing the potential of blockchain technology to power decentralized applications, Buterin published the Ethereum whitepaper, "A Next-Generation Smart Contract and Decentralized Application Platform," in 2013. In 2014, Gavin Wood followed with the Ethereum yellow paper, "ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER."
The development of Ethereum was planned to occur across four distinct phases: Frontier, Homestead, Metropolis, and Serenity. The network officially entered the Metropolis phase in October 2017, marking a significant milestone in its evolution.
What is Ethereum?
Ethereum is often described in various ways, but its creator provided a succinct definition:
"Ethereum is a platform that is specifically designed for people to build these kinds of decentralized applications."
In essence, Ethereum leverages blockchain technology to create a global platform where anyone can build and deploy their own decentralized applications (Dapps).
A key difference between Bitcoin and Ethereum lies in their block data. While Bitcoin blocks primarily store transaction data, Ethereum blocks are designed to store both transaction data and executable code. This gives Ethereum not just storage capabilities, but also computation power. Developers write code in specific programming languages, which is then compiled into bytecode and stored on the blockchain.
Understanding Turing Completeness in Ethereum
Ethereum provides a decentralized virtual machine to execute this bytecode, known as the Ethereum Virtual Machine (EVM). The EVM exists on every node in the Ethereum network and is responsible for running the bytecode stored in the blocks.
A critical feature of the EVM is that it is Turing complete. Turing completeness describes a system that can solve any computational problem, given enough time and resources. A computational problem is any problem that can be solved by calculation, such as determining if a number is prime. A Turing-complete machine requires infinite storage space, variable computational power, conditional logic (if-else), and looping capabilities. The EVM possesses these attributes.
You can think of Ethereum as a massive, decentralized world computer. Theoretically, this computer has near-infinite storage space and computational capability. You can write any program and run it on this computer. Because it's built on blockchain technology, the data and programs on it are highly resistant to tampering. Its decentralized nature means no single entity has control over it. Ethereum is a blockchain-based development platform designed for building and running Dapps.
What is a Smart Contract?
The concept of a "smart contract" was first proposed by scholar Nick Szabo in 1994. He defined it as:
"A smart contract is a computerized transaction protocol that executes the terms of a contract."
This can sound abstract. A perfect analogy is a vending machine. When you insert coins, the machine dispenses your selected product. This interaction represents a contractual transaction between you and the vendor. The contract is a set of mutually agreed-upon rules. In this case, the rule is that inserting coins of sufficient value results in receiving a chosen item. The vending machine itself is the entity enforcing this contract. The vendor programs the rules (the contract) into the machine. When specific conditions are met (sufficient coins are received), the machine executes the corresponding action (dispensing the product). This is the core concept of a smart contract.
The primary goals of smart contracts are to:
- Satisfy common contractual conditions.
- Minimize malicious exceptions and accidental losses.
- Reduce the need for trusted intermediaries.
- Lower arbitration, enforcement, and other transaction costs.
Smart Contracts on the Blockchain
Consider the vulnerabilities of a traditional vending machine. What if a hacker tampers with it? What if the vendor maliciously changes its rules to take money without providing a product? Blockchain technology offers solutions to these problems.
Blockchain's inherent characteristics make it an ideal host for smart contracts. Its immutable nature makes it extremely difficult for hackers to alter data once it's on the chain. Its decentralized structure prevents any single party from controlling or manipulating a program that is already running. Vitalik Buterin recognized that blockchain could solve the fundamental issues of trust and security for smart contracts, leading to the creation of Ethereum.
Deploying a smart contract on a blockchain significantly enhances its security and reliability due to these properties.
How Smart Contracts Work on Ethereum
On the Ethereum network, a smart contract is the code we write for the EVM to execute; it is the bytecode stored on the blockchain. When a smart contract runs, its output depends on its current state and the instructions sent by a user.
Returning to the vending machine analogy: its state is a balance of $0 when no money is inserted. Inserting $10 changes its state to a $10 balance. Inserting another $10 updates the state to $20. Each smart contract has a unique purpose, design, and set of interaction methods. These methods are defined by an ABI (Application Binary Interface).
When we write smart contract code and compile it, we get two things:
- The compiled bytecode.
- A JSON-formatted ABI file.
To deploy a smart contract to the Ethereum blockchain, we use the ABI as a shell, place the bytecode in the data field, and broadcast this transaction to the Ethereum network. Miners then include this contract in a new block. Once deployed, the contract is assigned an address, creating what is known as a contract account. We interact with the smart contract through this address.
When we send an instruction to a contract, a miner looks up the contract's current state from the blockchain based on the address provided. The miner then performs computations based on this state and the new instruction. The resulting new state is written into a new block. Once this block is accepted by the rest of the network, all nodes update their copy of the contract's state. The blockchain synchronizes this data automatically, ensuring every node has an identical view of the contract's state.
Dapp Architecture on Ethereum
It's helpful to compare the architecture of a traditional web application with that of an Ethereum-based Dapp.
A traditional web application uses a client-server model. A server provides a UI (built with HTML/CSS/JavaScript) to the user. The server receives user requests, performs computations, and stores the results in a backend database. The server and database can be hosted in a local data center or on cloud services like Amazon S3 and EC2.
In an Ethereum Dapp architecture, the core business logic is handled by Ethereum smart contracts. The data is stored on the Ethereum blockchain network. The server's role is primarily to fetch information from the blockchain and present it to the user, as the complex computations are now managed by smart contracts. Users interact with smart contracts directly by sending transactions from their Ethereum wallets.
👉 Explore more strategies for building Dapps
A Practical Smart Contract Example
Let's consider a simple example of a smart contract in action for a car sale between Bob (the seller) and Kevin (the buyer):
- Bob uses his account to register the car for sale on a smart contract.
- Bob places the car and its keys in a garage whose lock is controlled by the smart contract.
- Kevin sees the car and likes it. He transfers the agreed-upon amount of Ether to the smart contract's account.
- The smart contract automatically verifies two conditions: the car is still available, and Kevin has sent the correct amount of Ether.
- If all conditions are met, the smart contract executes two actions: it releases the Ether to Bob's account, and it grants Kevin's private key permission to unlock the garage door.
- Kevin uses his private key to open the garage lock and takes possession of the car and keys.
This process demonstrates how a smart contract can automate and secure a transaction, removing the need for a middleman and building trust between strangers.
Frequently Asked Questions
Q: What is the main difference between Bitcoin and Ethereum?
A: While both are blockchains, Bitcoin is primarily a decentralized digital currency system. Ethereum is a decentralized computing platform. Its blocks can store and execute code (smart contracts), enabling it to run decentralized applications far beyond simple monetary transactions.
Q: Is Ethereum truly Turing complete?
A: Yes, the Ethereum Virtual Machine (EVM) is Turing complete. This means it can, in theory, compute anything that is computable, given enough resources. However, in practice, a mechanism called "gas" limits infinite loops by requiring fees for computation, ensuring network stability.
Q: What is gas in Ethereum?
A: Gas is a unit that measures the computational effort required to execute operations, like running a smart contract or making a transaction. Users pay for gas in Ether. This fee compensates miners for the energy required to process and validate transactions, preventing network spam.
Q: Can deployed smart contracts be changed or updated?
A: Generally, no. Once a smart contract is deployed to the Ethereum blockchain, its code is immutable and cannot be altered. This ensures predictability and trust. Developers who anticipate needing updates often build proxy patterns or implement upgradeability mechanisms into the contract's design from the start.
Q: What programming language is used for Ethereum smart contracts?
A: The most popular and main language for writing Ethereum smart contracts is Solidity. Its syntax is similar to JavaScript and it is specifically designed for targeting the EVM. Another language used is Vyper, which focuses on simplicity and security.
Q: Are smart contracts legally binding?
A: This is a complex and evolving area of law. While a smart contract can automatically execute terms, its legal status as a binding contract depends on jurisdiction and whether it meets traditional legal requirements for a contract (offer, acceptance, consideration, etc.). It's best to consult legal experts for specific cases.
Conclusion
This guide has introduced the fundamental concepts of Ethereum and smart contracts, explaining why Ethereum serves as a powerful platform for Dapp development. While the technology continues to evolve and face challenges like scalability and user experience, it holds immense potential for creating a more decentralized internet. The ongoing efforts of developers and the growing community are crucial to realizing this vision.