Solidity Intro
Solidity is a statically typed, curly-brace programming language for writing smart contracts: small programs that live on a blockchain and run on the Ethereum Virtual Machine (EVM). Its syntax will feel familiar if you have seen JavaScript, C++ or Java, but the environment it runs in is very different from a normal computer, and that shapes almost every rule of the language.
This course teaches the language itself. Every runnable example is compiled by the official compiler (solc) and executed on a real, in-memory EVM right in your browser, so you can experiment without installing anything and without any real money involved.
Blockchains in one page
A blockchain is a shared database that many independent computers (nodes) keep in sync. Changes are grouped into blocks; each block refers to the previous one by its hash, so history cannot be quietly rewritten. Everyone can verify every change, which is why programs on a blockchain are public and their results are trusted without a central operator.
Ethereum is a blockchain whose database stores not just balances but also code and data. That code is a smart contract. Other EVM chains (Polygon, Arbitrum, Optimism, Base, Avalanche C-Chain, …) run the same machine, so Solidity code works on them too.
| Term | Meaning |
|---|---|
| Account | An entry in the global state, identified by a 20-byte address |
| Externally owned account (EOA) | An account controlled by a private key, i.e. a person or a wallet |
| Contract account | An account that holds code and storage; it only acts when it is called |
| Transaction | A signed message from an EOA: send ether, deploy a contract, or call a function |
| Ether (ETH) | The native currency; the smallest unit is the wei (1 ETH = 10¹⁸ wei) |
| Gas | The unit of computation; every EVM instruction costs some gas, paid for in ether |
| Block | A batch of transactions with a number and a timestamp |
The EVM
The EVM is a simple stack machine with 256-bit words. Every node runs each transaction on its own copy of the EVM and must get exactly the same result. Consequences you'll meet throughout this course:
- Determinism. There is no real randomness, no clock other than the block timestamp, no file system and no network access.
- Cost. Each instruction costs gas, and writing to permanent storage is by far the most expensive thing you can do.
- Atomicity. A transaction either completes entirely or is reverted: every change it made is undone.
- Immutability. Once deployed, a contract's code cannot be edited. (Upgrade patterns exist; see the Proxies lesson.)
- Everything is public. Anyone can read a contract's storage, even variables marked
private.
A first look
Here is a complete contract. Press Run: the playground deploys the contract named Main and calls its main() function.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "hardhat/console.sol";
contract Main {
function main() external view {
console.log("Hello from the EVM!");
console.log("This contract lives at", address(this));
console.log("Current block number:", block.number);
}
}Hello from the EVM!
This contract lives at 0x5FbDB2315678afecb367f032d93F642f64180aa3
Current block number: 1
console.log is not part of Solidity; it comes from the Hardhat development tool and only works on local test networks. On a real chain you communicate results through return values and events. Here it is the easiest way to see what your code does.
How the playground works
Every example in this course follows the same conventions:
| Convention | Detail |
|---|---|
| Entry point | The contract Main is deployed, then main() is called if it exists |
| Caller | Both happen from the account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, which holds 10,000 test ETH |
| Ether for experiments | If Main's constructor is payable, it receives 100 ETH when deployed |
| Block | Block number 1 with timestamp 1767225600 (2026-01-01 00:00:00 UTC), so results are reproducible |
| Output | console.log lines, then the events emitted, then main() returned: … |
| Failures | A revert prints main() failed: … with the reason |
Returning values works too:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Main {
function main() external pure returns (uint256, string memory) {
uint256 secondsPerDay = 24 * 60 * 60;
return (secondsPerDay, "seconds in a day");
}
}main() returned: 86400, seconds in a day
What people build with Solidity
- Tokens: fungible tokens (ERC-20) and unique collectibles (ERC-721).
- Decentralized finance: exchanges, lending pools, escrow and vesting contracts.
- Governance: on-chain voting for organizations (DAOs).
- Registries: names, certificates, supply-chain records anyone can verify.
Note: This course is about programming. Nothing in it is financial advice, and the tokens you create here are local test objects with no value.
Why learning carefully matters
A bug in a web app can be patched in minutes. A bug in a deployed contract is usually permanent, public, and may control real assets. That is why this course pays attention to errors, checks and security from the start, and has dedicated lessons on the classic vulnerabilities and how to avoid them.
Test yourself
What happens to the changes made by a transaction that reverts?
- They are kept up to the point of failure
- They are all undone
- Only storage changes are kept
- They are saved to the next block
How many wei are in one ether?
- 1,000
- 10^9
- 10^18
- 10^24
Which statement about a private state variable is true?
- Nobody outside the contract can read its value
- Other contracts cannot read it directly, but anyone can read the blockchain's storage
- It is encrypted
- It is not stored on chain