Understanding programmable blockchains and the world computer
If Bitcoin is like digital gold (a store of value), Ethereum is like a world computer. It's a blockchain that can run programs, not just track money transfers.
Bitcoin: Like a calculator - it does one thing really well (transfers value)
Ethereum: Like a smartphone - it can run any app you program for it
| Feature | Bitcoin | Ethereum |
|---|---|---|
| Purpose | Digital currency | Programmable platform |
| Block Time | ~10 minutes | ~12 seconds |
| Consensus | Proof of Work | Proof of Stake (since 2022) |
| Programming | Limited scripting | Turing-complete (can run any program) |
| Supply | 21 million max | No hard cap |
The EVM is the heart of Ethereum - it's like a giant, global computer that everyone can use but no one owns. Every computer (node) in the Ethereum network runs a copy of the EVM.
Imagine if every computer in the world was connected and worked together as one massive computer. That's essentially what the EVM is - a decentralized computer that:
You write code (in Solidity), compile it to bytecode, and deploy it to the EVM. The code gets an address and lives on the blockchain forever.
When someone calls your smart contract, every node in the network executes the same code and verifies the results match. This ensures no cheating.
The EVM updates the blockchain's state (balances, data, etc.) based on the execution results. Everyone's copy stays in sync.
The EVM is deterministic - given the same input, it always produces the same output. This is crucial because thousands of computers need to agree on the result. No randomness allowed!
Gas is the fuel that powers the Ethereum network. Every operation on the EVM costs gas, and you pay for it in ETH (Ethereum's cryptocurrency).
Think of Ethereum like a car trip:
Prevents Spam
Without fees, people could spam the network with infinite loops
Rewards Validators
Gas fees compensate validators for processing transactions
Prioritizes Transactions
Higher gas price = faster processing (like express shipping)
Limits Computation
Each block has a gas limit, preventing overload
Gas prices fluctuate based on network demand. To save money:
Ethereum has two types of accounts, and understanding the difference is crucial for working with the blockchain.
A regular user account controlled by a private key. This is what you get when you create a wallet.
Characteristics:
Example Address:
0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb
A smart contract deployed on the blockchain. It has code and can execute logic automatically.
Characteristics:
Example (Uniswap):
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
EOAs are controlled by humans with private keys. Contract Accounts are controlled by code and execute automatically when triggered. Think of EOAs as people and Contract Accounts as robots that follow programmed instructions.
1. EOA → EOA: Simple ETH transfer
Alice sends 1 ETH to Bob
2. EOA → Contract: Call smart contract function
Alice swaps tokens on Uniswap
3. Contract → Contract: Smart contracts calling each other
Uniswap calls a token contract to transfer tokens
4. Contract → EOA: Send ETH/tokens to user
Staking contract sends rewards to Alice
A wallet is software that manages your private keys and lets you interact with the blockchain. It's like a keychain that holds all your keys to different accounts.
Your crypto isn't "in" your wallet - it's on the blockchain. Your wallet just stores the private keys that prove you own it. Think of it like a key to a safe deposit box - the key isn't the money, but it gives you access to it.
Install in your browser (Chrome, Firefox, etc.) for easy access to Web3 apps.
Popular Options:
Physical devices that store your private keys offline. Most secure option for large amounts.
Popular Options:
Apps for your smartphone. Great for on-the-go transactions and QR code scanning.
Popular Options:
Smart contracts are self-executing programs stored on the blockchain. They automatically enforce agreements without needing a middleman like a lawyer or bank.
A smart contract is like a vending machine:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// A simple storage contract
contract SimpleStorage {
// State variable to store a number
uint256 public favoriteNumber;
// Function to store a new number
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
// Function to retrieve the stored number
function retrieve() public view returns (uint256) {
return favoriteNumber;
}
}pragma solidity ^0.8.0 - Specifies Solidity versionuint256 public favoriteNumber - Stores a number on the blockchainstore() - Function to update the number (costs gas)retrieve() - Function to read the number (free, no gas)Immutable
Once deployed, code cannot be changed (unless designed with upgradability)
Deterministic
Same input always produces same output
Transparent
Anyone can view the code and verify what it does
Trustless
No need to trust a person - trust the code
Events are a way for smart contracts to communicate that something happened. They're like notifications that get stored on the blockchain and can be listened to by applications.
Events are like a doorbell. When someone rings it (triggers an event), everyone inside the house (listening applications) knows something happened. The event tells you "who rang" and "when" without you having to constantly check the door.
Cheaper than Storage
Events cost much less gas than storing data in contract variables
Frontend Notifications
Web apps can listen for events and update the UI in real-time
Historical Data
Query past events to build transaction history
Debugging
Track what happened during contract execution
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract EventExample {
// Define an event
event Transfer(
address indexed from, // indexed = searchable
address indexed to, // indexed = searchable
uint256 amount // not indexed
);
// Function that emits an event
function transfer(address to, uint256 amount) public {
// ... transfer logic here ...
// Emit the event
emit Transfer(msg.sender, to, amount);
}
}event Transfer(...) - Declares an event with parametersindexed - Makes parameters searchable (max 3 indexed params)emit Transfer(...) - Triggers the event, logging it to the blockchain// Using ethers.js to listen for events
const contract = new ethers.Contract(address, abi, provider);
// Listen for Transfer events
contract.on("Transfer", (from, to, amount, event) => {
console.log(`${from} sent ${amount} to ${to}`);
// Update your UI here
});
// Query past events
const filter = contract.filters.Transfer(null, myAddress);
const events = await contract.queryFilter(filter);
console.log("Past transfers to me:", events);You now understand Ethereum, the EVM, gas fees, accounts, wallets, and smart contracts! In the next module, we'll dive deep into Solidity programming and learn how to write your own smart contracts.