Unit 6: Ethereum, Web3 and Decentralized Applications
I. Orientation
Ethereum is a programmable blockchain proposed by Vitalik Buterin in 2013 and launched on 30 July 2015. Unlike a blockchain designed mainly for payments, Ethereum maintains a shared state and executes general-purpose programs called smart contracts. Since The Merge on 15 September 2022, Ethereum has used proof of stake rather than proof of work for consensus.
A. Ethereum—an overview
Ethereum provides a decentralized computation and settlement platform whose native currency is ether.
- Shared state machine: Every valid transaction changes a replicated global state containing accounts, balances, contract code and contract storage.
- Native asset: Ether (
ETH) pays transaction fees and supports staking; its smallest denomination is the wei:
TEXT1 ETH = 10^18 wei - Programmability: Developers deploy bytecode executed deterministically by the Ethereum Virtual Machine (EVM).
- Account model: Ethereum uses addresses and balances rather than Bitcoin-style unspent transaction outputs.
- Externally owned account (EOA): Controlled by a private key.
- Contract account: Controlled by deployed program code.
- Consensus: Validators stake ETH, propose blocks and attest to valid blocks under proof of stake.
- Gas: Computation and storage consume gas, preventing unlimited execution and resource abuse.
- Web3 principle: Users interact through cryptographic wallets, while applications use blockchains and decentralized protocols as shared back ends.
- Public infrastructure: Ethereum mainnet is permissionless, while test networks such as Sepolia support development without using valuable mainnet ETH.
II. Network and Distributed Ledger
The Ethereum network is a peer-to-peer system in which nodes exchange transactions and blocks, independently verify protocol rules and converge on a canonical blockchain.
A. The Ethereum network
The network combines transaction execution, peer-to-peer communication and proof-of-stake consensus.
- Mainnet: The production network identified by chain ID
1; ETH and deployed contracts possess real economic value. - Testnets: Networks such as Sepolia use separate state and test ETH, so their assets cannot be transferred to mainnet.
- Transaction path: A wallet signs a transaction, broadcasts it to a node, and the node propagates it until a block proposer includes it.
- Two-layer architecture:
- Execution layer: Runs EVM transactions and maintains account state; Geth is an execution client.
- Consensus layer: Organizes validators, attestations, fork choice and finality; examples include Lighthouse and Prysm.
- Network identity: A chain ID is included in transaction signing to reduce replay across different chains.
B. Blocks and blockchain
A block packages ordered transactions together with data linking it cryptographically to the previous block.
- Block contents: Important fields include the parent hash, block number, timestamp, state root, transaction root, receipts root and gas limits.
- Hash linkage: Changing an earlier block changes its hash and invalidates subsequent references, making undetected rewriting difficult.
- State root: A compact commitment to Ethereum’s post-block world state, represented using Merkle Patricia trie structures.
- Receipts: Each executed transaction produces a receipt containing status, gas used and emitted event logs.
- Fee calculation:
TEXTtransaction fee = gas used × effective gas price
If21,000gas is used at20 gwei, the fee is420,000 gwei, or0.00042 ETH. - EIP-1559 fees: The protocol burns the block’s base fee, while an optional priority fee rewards the validator.
C. Nodes and miners
Nodes enforce Ethereum’s rules, but miners were replaced by validators on Ethereum mainnet after The Merge.
- Nodes:
- Full node: Verifies blocks and retains enough state to serve current network operations.
- Archive node: Preserves historical states, requiring substantially more storage.
- RPC node: Exposes interfaces through which wallets and DApps query state or submit transactions.
- Miners and validators:
- Historical miners: Before September 2022, miners performed proof-of-work computation to propose mainnet blocks.
- Current validators: A solo validator deposits
32 ETH, proposes blocks when selected and attests to other proposals. - Penalties: Inactivity loses rewards, while serious conflicting behavior can result in slashing.
III. Execution and Smart Contracts
Ethereum computation is performed by the EVM, while smart contracts provide persistent, addressable programs whose state changes through transactions.
A. Ethereum Virtual Machine (EVM)
The EVM is a deterministic, sandboxed virtual machine that executes contract bytecode identically on participating nodes.
- Stack architecture: The EVM uses a stack of 256-bit words, with transient memory and persistent contract storage.
- Opcodes: Instructions such as
ADD,SSTORE,CALLandREVERTperform arithmetic, storage and inter-contract operations. - Determinism: The same pre-state and transaction must produce the same post-state on every valid node.
- Gas accounting: Each opcode has a gas cost; execution stops and reverts if the transaction exhausts its gas limit.
- Isolation: Contracts cannot directly access local files, web pages or external APIs; external facts require trusted oracle mechanisms.
- Result: Successful execution updates state, while
REVERTcancels state changes but still consumes gas already spent.
B. Smart contracts
A smart contract is program code and persistent storage deployed at an Ethereum address.
- Invocation: Users call public functions by sending transaction data containing a function selector and ABI-encoded arguments.
- Persistence: State variables occupy contract storage and remain available across blocks.
- Immutability: Deployed bytecode normally cannot be edited; upgradeable systems instead use proxy patterns that redirect calls.
- Events: Contracts emit indexed logs, allowing DApp interfaces to detect actions efficiently.
- Security concerns: Reentrancy, weak access control, unchecked external calls and price manipulation can cause irreversible loss.
- Simple Solidity contract:
SOLIDITYpragma solidity ^0.8.20; contract Counter { uint256 public count; function increment() external { count += 1; } }
Callingincrement()changes storage and requires a transaction; readingcountcan be performed without an on-chain state change.
C. Contract deployment
Deployment creates a contract account by placing compiled bytecode in a special creation transaction.
- Compilation: Source code becomes creation bytecode, runtime bytecode and an Application Binary Interface (ABI).
- Constructor: Constructor logic runs once during deployment and initializes storage.
- Address creation: For ordinary creation, the address is derived from the deployer’s address and transaction nonce;
CREATE2supports deterministic addressing from a salt and bytecode hash. - Deployment sequence:
- Compile the source.
- Select the network and funded signer.
- Estimate gas and sign the deployment transaction.
- Broadcast it and wait for a receipt.
- Record the resulting contract address and ABI.
- Verification: Publishing matching source and compiler settings on a block explorer allows users to inspect the deployed bytecode’s intended source.
IV. Ethereum Development Ecosystem
Ethereum development combines protocol clients, contract languages, compilers, testing frameworks and local or public networks.
A. Components of the Ethereum ecosystem
The ecosystem consists of interoperating infrastructure rather than a single application.
- Core protocol: Defines transaction validity, EVM execution, fees, consensus and networking rules.
- Clients: Geth, Nethermind and Besu implement the execution layer; Lighthouse, Prysm and Teku implement the consensus layer.
- Layer 2 systems: Optimistic and zero-knowledge rollups execute activity away from mainnet and publish data or proofs to Ethereum.
- Oracles: Oracle networks deliver external information such as asset prices because the EVM cannot fetch web data itself.
- Token standards: ERC-20 defines fungible-token interfaces, while ERC-721 and ERC-1155 support non-fungible and multi-token assets.
B. Ethereum development environment
A development environment supports coding, compilation, testing, deployment and debugging.
- Browser environment: Remix IDE provides Solidity editing, compilation, debugging and deployment through an injected wallet.
- Frameworks: Hardhat and Foundry automate tests, scripts, local chains and deployment workflows.
- Local blockchain: A local node provides deterministic accounts and immediate blocks without spending real ETH.
- Testing levels:
- Unit tests: Check individual contract functions.
- Integration tests: Check interactions among contracts, wallets and front ends.
- Fork tests: Reproduce selected mainnet state locally.
- Configuration security: RPC URLs and private keys belong in environment variables, not committed source files.
C. Programming languages
Ethereum uses several languages at different points in the application stack.
- Solidity: The dominant statically typed contract language, with syntax influenced by JavaScript and C++.
- Vyper: A Python-like contract language emphasizing simplicity and auditability.
- Yul: An intermediate, low-level language used for optimization and direct EVM-oriented programming.
- JavaScript and TypeScript: Common front-end and scripting languages using libraries such as ethers.
- Go: Used to implement Geth and suitable for infrastructure interacting with Ethereum clients.
- Compilation target: High-level contract languages compile to EVM bytecode rather than executing directly on nodes.
V. User Access, Interfaces and Applications
Wallets, APIs and supporting protocols connect users and applications to Ethereum without changing its core consensus rules.
A. Wallets and client software
A wallet manages cryptographic keys and constructs signed messages or transactions.
- Private key: A secret 256-bit value authorizes account actions; possession effectively controls the associated assets.
- Public address: An EOA address is the final 20 bytes of the Keccak-256 hash of its public key.
- Wallet types:
- Software wallet: Convenient but exposed to device compromise.
- Hardware wallet: Keeps signing keys in a dedicated physical device.
- Smart contract wallet: Can implement multisignature approval, recovery or spending rules.
- Seed phrase: Hierarchical deterministic wallets derive many accounts from one recovery secret; it must never be entered into untrusted software.
- Client distinction: A wallet signs user actions, whereas an Ethereum client validates and relays blockchain data.
B. APIs
Ethereum APIs provide standardized methods for communicating with nodes and contracts.
- JSON-RPC: Requests use methods such as
eth_getBalance,eth_call,eth_sendRawTransactionandeth_getLogs. - Read operation:
eth_callsimulates execution against a selected block state without creating a transaction. - Write operation:
eth_sendRawTransactionbroadcasts an already signed transaction that may alter state. - ABI: The ABI describes function names, parameter types, return values and events so software can encode contract calls.
- Transport: HTTP suits request-response access, while WebSocket connections support subscriptions to new blocks or logs.
C. Tools and DApps
A decentralized application combines smart contracts with an interface and wallet-based authorization.
- Typical architecture: Browser interface → wallet provider → JSON-RPC node → smart contract.
- Libraries: Ethers converts ABI definitions into JavaScript contract objects and handles transaction encoding.
- Explorers: Etherscan-style explorers display blocks, addresses, transaction receipts, logs and verified contracts.
- DApp examples: Decentralized exchanges, lending protocols, NFT markets, DAOs and blockchain games.
- Degree of decentralization: A contract may be decentralized while its website, RPC provider or administrative keys remain centralized.
D. Supporting protocols
Supporting protocols extend Ethereum with naming, storage, messaging and off-chain scaling.
- ENS: Ethereum Name Service maps human-readable names to addresses and other records.
- IPFS: Content-addressed storage identifies data by cryptographic content identifiers rather than server location.
- Swarm: A decentralized storage and distribution system associated with the Ethereum ecosystem.
- Whisper history: Whisper was designed for peer-to-peer messaging; newer projects generally use alternative messaging protocols.
- Rollups and bridges: Rollups reduce execution costs, while bridges transfer representations of assets or messages across networks; bridge assumptions introduce additional security risk.
VI. Web3 Interaction with Geth
Geth, the Go implementation of Ethereum’s execution layer, can expose JSON-RPC and an interactive JavaScript console for inspecting blockchain state.
A. Exploring Web3 with Geth
Geth first provides a synchronized execution client and controlled RPC endpoint.
- Node startup:
BASHgeth --sepolia --http --http.api eth,net,web3
--sepoliaselects the testnet, while--http.apilimits exposed namespaces. - Console attachment:
BASHgeth attach http://127.0.0.1:8545 - Basic inspection:
JAVASCRIPTeth.blockNumber net.version web3.clientVersion
These return the latest known block number, network identifier and client version. - Synchronization:
eth.syncingreturns synchronization information orfalsewhen the execution client is caught up. - Security: RPC access should not be exposed publicly with sensitive administrative namespaces or permissive settings.
B. Exploring Web3 with Geth
The attached console can query balances, inspect blocks and submit externally signed transactions.
- Balance query:
JAVASCRIPTweb3.fromWei(eth.getBalance("0xAddress"), "ether")
eth.getBalancereturns wei, andfromWeiconverts the display value to ETH. - Block inspection:
JAVASCRIPTeth.getBlock("latest")
The result includes fields such asnumber,hash,parentHash,gasUsedandtransactions. - Contract read: A read-only ABI-encoded call can be sent through
eth.call, producing return data without mining or validator inclusion. - Transaction submission:
JAVASCRIPTeth.sendRawTransaction("0xSignedTransaction")
The hexadecimal payload must already contain a valid signature, nonce, destination, value, fee fields and chain ID. - Operational principle: Modern practice keeps private keys in wallets or hardware signers and uses Geth primarily for verification, networking and RPC access.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →