Solidity and Ethereum Tutorial
Learn Solidity and Ethereum step by step: 47 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Ethereum? Meet Ethereum before you write Solidity: accounts, transactions, gas, blocks, the EVM and ETH, plus a tiny runnable account-and-balance state machine.
- Smart Contracts: Features, Uses and Limits Understand smart contracts: where the idea came from, their key features, real-world applications such as DAOs, DeFi and supply chains, and their limits, with runnable models.
- How a Smart Contract Runs Follow a smart contract from deployment to execution: addresses, calls versus transactions, storage versus memory, the ABI and why contracts are deterministic.
- Your Solidity Toolbox A tour of the tools behind Solidity work: the solc compiler, Remix, Hardhat, Foundry, ethers.js and viem, wallets, local nodes and testnets, with a runnable loop.
- Your First Contract Write and understand your first Solidity contract: license line, pragma, state variables, functions, view, plus how to deploy it in Remix and a JS twin.
Language Basics
- Comments, NatSpec and the Style Guide Write clear Solidity: single-line, multi-line and NatSpec comments, the SPDX line, the official layout and naming rules, with a runnable NatSpec reader and style checker.
- Value Types Learn Solidity's value types: bool, uint and int sizes, address and address payable, fixed bytes, enums, literals and default values, with BigInt stand-ins.
- Integers, Overflow and Checked Math How Solidity 0.8 checks arithmetic, what a panic is, when to use unchecked, how division rounds and how wad and ray fixed-point math works, with BigInt demos.
- Operators, Ether Units and Time Units Learn every Solidity operator (arithmetic, comparison, logical, bitwise, assignment), the ** and % rules, and wei, gwei, ether and time units, with BigInt demos.
- Strings, Bytes, Arrays and Structs Learn Solidity reference types: dynamic and fixed arrays, string versus bytes, structs, and how memory, storage and calldata copies differ.
- Mappings Learn Solidity mappings: key-value storage, default values, nested mappings, why you cannot loop over them, and the pattern for tracking keys.
- Functions and Visibility Learn Solidity functions: public, external, internal and private visibility, view and pure, multiple and named returns, and function overloading.
- Control Flow, require, revert and Custom Errors Learn Solidity control flow and error handling: loops and their gas cost, require, assert, revert, custom errors, try/catch and panic codes.
- msg.sender, msg.value and Global Variables Learn Solidity's built-in globals: msg.sender, msg.value, msg.data, block.timestamp, block.number, chain ID, and why tx.origin is dangerous.
Contract Structure
- Constructors, Constants and Immutables Learn how Solidity constructors set up a contract at deployment, and how constant and immutable variables save gas compared to storage.
- Events and Logs Learn Solidity events: emit, indexed parameters, how logs are stored and filtered, listening off-chain, and when to use events instead of storage.
- Modifiers and Access Control Write Solidity modifiers, build onlyOwner, roles, two-step ownership transfer and a pause switch, and see the guard pattern in a runnable JavaScript stand-in.
- Sending and Receiving Ether Learn how Solidity contracts receive and send ether: payable, receive, fallback, call vs transfer vs send, the withdrawal pattern and selfdestruct changes.
- Storage, Memory and Calldata Understand Solidity data locations: storage slots and packing, memory, calldata, how costs differ, copy rules and stack depth, with a slot-packing calculator.
Object-Oriented Solidity
- Inheritance and Overriding Learn Solidity inheritance: is, virtual and override, super, constructor arguments, multiple inheritance linearization and abstract contracts, with a runnable C3 model.
- Encapsulation, Polymorphism and Inheritance Shapes Hide state behind validated functions, overload and override functions, call different contracts through one interface, and use multi-level and hierarchical inheritance.
- Interfaces and Libraries Learn Solidity interfaces and libraries: calling other contracts through an interface, internal vs external libraries, using for, and a duck-typed JS stand-in.
- ABI Encoding and Low-Level Calls Learn how function selectors and abi.encode work, why encodePacked can collide, and how call, staticcall and delegatecall differ, with runnable stand-ins.
- Inline Assembly and Yul Learn Solidity inline assembly with Yul: variables, built-in opcodes, if, switch and for, memory and the free memory pointer, storage slots, and why unchecked math is risky.
- Proxies and Upgradeable Contracts Learn how delegatecall proxies upgrade contracts, why storage layout clashes break them, transparent vs UUPS proxies, initializers and the risks.
Tokens and Standards
- Building an ERC-20 Token Build an ERC-20 token step by step: balances, transfer, approve, transferFrom, events, decimals and the allowance race, with a runnable stand-in.
- ERC-721 NFTs Understand ERC-721 non-fungible tokens: ownership per token id, approvals, safeTransferFrom receivers, tokenURI and off-chain metadata, with a runnable registry.
- ERC-1155, ERC-4626 and Friends Learn the multi-token standard ERC-1155, the ERC-4626 vault share standard, ERC-165 interface detection and the permit idea, with runnable stand-ins.
- Using OpenZeppelin Learn why to reuse audited code and how to use OpenZeppelin's Ownable, AccessControl, ReentrancyGuard, Pausable and SafeERC20, with runnable pattern stand-ins.
Security
- Common Vulnerabilities Learn the classic smart contract bugs: reentrancy, tx.origin, unchecked calls, front-running, denial of service, weak randomness and signature replay.
- Reentrancy Step by Step Follow a DAO-style reentrancy attack step by step, then fix it with checks-effects-interactions and reentrancy guards, including cross-function and read-only cases.
- Gas Costs and Optimization Understand what makes Solidity transactions expensive: storage writes, packing, calldata, loops and custom errors, and measure savings with a gas-counting model.
- Testing Contracts Learn how to test smart contracts: unit tests, fuzzing, invariants, forking and coverage, with Foundry and Hardhat examples and a runnable fuzzing stand-in.
- Audits, Tools and Best Practices Learn how contracts are reviewed and kept safe: static analysis such as Slither, fuzzing, formal checks, audits, multisigs, timelocks and deployment checklists.
Working With Contracts From Outside
- Talking to Contracts with JavaScript Learn how JavaScript connects to Ethereum: providers, signers, the ABI, reading and writing contracts and listening to events, with ethers.js and viem.
- Truffle, Ganache and web3.js: The Classic Toolchain Set up and read the classic Truffle, Ganache and web3.js workflow: init, compile, migrate, networks, HDWalletProvider, call versus send, and what replaced it today.
- Deploying to Testnet and Mainnet Deploy a Solidity contract to a testnet and mainnet: networks, faucets, constructor arguments, source verification on explorers and key safety, with a stand-in script.
- Oracles, Randomness and Off-Chain Data Learn why smart contracts need oracles, how price feeds get manipulated, why block data is bad randomness, and how commit-reveal and signed messages work.
Projects
- Project: A Voting Contract Build a Solidity voting contract with proposals, voter registration, one vote per address, a deadline and a tally, then test the same logic in a JavaScript stand-in.
- Project: Crowdfunding With Refunds Build an all-or-nothing crowdfunding contract in Solidity with a goal, a deadline, a state machine, creator withdrawal and pull-based refunds, plus a JavaScript stand-in.
- Project: A Token and Simple Sale Build an ERC-20 token and a sale contract that sells it for ether with a price, a per-buyer cap, a deadline and owner withdrawal, then test a JavaScript stand-in.
- Project: Escrow and English Auction Build two classic contracts: an escrow with a buyer, seller and arbiter, and an English auction with timed bids and pull refunds, and test them in a JavaScript stand-in.
- Project: A Multisig Wallet Build a multisignature wallet in Solidity: owners, proposals, confirmations and execution through low-level calls, plus a runnable JavaScript stand-in.
- Project: On-Chain To-Do List, Employee Registry and Wallet Build three classic contracts: a to-do list with create, read, update and delete, an employee registry with access control, and a personal wallet, then connect them to a front end.
Practice and Review
- Practice Exercises With Solutions Fifteen graded Solidity exercises on types, mappings, errors, tokens and security, each with a runnable JavaScript stand-in solution you can edit.
- Solidity Interview Questions Prepare for a Solidity interview: short answers on the language, gas, security, token standards and design, with runnable JavaScript demos for the tricky ones.
- Solidity Cheat Sheet A one-page Solidity cheat sheet: types, data locations, visibility, globals, panic codes, patterns, token standards and a security checklist, with live helpers.