What is Ethereum?
Ethereum is an open-source, public blockchain platform with smart contract functionality. It uses its native cryptocurrency, Ether (ETH), to power decentralized applications (dApps) through the Ethereum Virtual Machine (EVM).
Key Features of Ethereum
- Smart Contracts: Self-executing contracts with terms written in code
- Decentralized: Operates on a peer-to-peer network without central authorities
- Immutable: Once deployed, contract code cannot be altered
Understanding Ethereum Blockchain
The Ethereum blockchain consists of two core components:
Data Storage
- Records all transactions permanently
- Maintains transparent, verifiable history
- Uses Proof-of-Work (PoW) consensus mechanism
Code Execution
- Smart contracts written in Solidity
- Compiled to EVM bytecode
- Executed across all network nodes
Prerequisites for Ethereum Development
Before starting, you should have basic knowledge of:
- Programming: Python, Java, or Go
- Web Technologies: HTML/CSS/JavaScript
- Command Line: Linux shell commands
- Database Concepts: Basic understanding
Recommended Tools
- Web3.js for dApp development
- Frameworks: React, Angular, or Vue
Example: Building a Voting dApp
We'll create a decentralized voting application that:
- Initializes candidates
- Records votes on blockchain
- Tracks vote counts transparently
๐ Learn more about blockchain applications
Setting Up Development Environment
Linux (Ubuntu 16.04)
sudo apt-get update
curl -sL https://deb.nodesource.com/setup_7.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
mkdir -p ethereum_voting_dapp/chapter1
cd ethereum_voting_dapp/chapter1
npm install ganache-cli [email protected] solc
node_modules/.bin/ganache-cliMacOS
brew update
brew install nodejs
mkdir -p ethereum_voting_dapp/chapter1
cd ethereum_voting_dapp/chapter1
npm install ganache-cli [email protected] solc
node_modules/.bin/ganache-cliWindows
- Install Visual Studio Community Edition
- Install Windows SDK
- Install Python 2.7
- Install Git
- Install OpenSSL
- Install Node v8.1.2
- Run:
npm install ganache-cli [email protected] solc
Writing Your First Smart Contract
Here's our Voting.sol contract:
pragma solidity ^0.4.18;
contract Voting {
mapping (bytes32 => uint8) public votesReceived;
bytes32[] public candidateList;
function Voting(bytes32[] candidateNames) public {
candidateList = candidateNames;
}
function totalVotesFor(bytes32 candidate) view public returns (uint8) {
require(validCandidate(candidate));
return votesReceived[candidate];
}
function voteForCandidate(bytes32 candidate) public {
require(validCandidate(candidate));
votesReceived[candidate] += 1;
}
function validCandidate(bytes32 candidate) view public returns (bool) {
for(uint i = 0; i < candidateList.length; i++) {
if (candidateList[i] == candidate) {
return true;
}
}
return false;
}
}Key Components Explained
- Mapping: Stores vote counts per candidate
- Constructor: Initializes candidate list
- Methods: Vote counting and validation
- Visibility: Public vs private functions
- View Modifier: Marks read-only functions
Compiling the Smart Contract
- Run Node console
- Initialize Web3
- Compile contract
> Web3 = require('web3')
> web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
> code = fs.readFileSync('Voting.sol').toString()
> solc = require('solc')
> compiledCode = solc.compile(code)Important Outputs
- Bytecode: The compiled code for deployment
- ABI: Application Binary Interface definition
๐ Explore more blockchain development tools
FAQ
What's the difference between Ethereum and Bitcoin?
While both use blockchain technology, Ethereum enables smart contracts and dApp development, whereas Bitcoin is primarily a digital currency.
How long does it take to deploy a smart contract?
Deployment time varies based on network congestion, but typically takes seconds to minutes.
Can I update a deployed smart contract?
No, smart contracts are immutable once deployed. You must deploy a new version.
What's Gas in Ethereum?
Gas refers to the computational fees required to execute operations on the Ethereum network.
How secure are smart contracts?
They're highly secure due to blockchain immutability, but vulnerabilities can exist in contract code.
Do I need Ether to develop Ethereum apps?
You only need Ether for deploying to mainnet. For development, testnets provide free Ether.