Skip to content

Lesson 2 · 1 min · Advanced

A 30-second Solidity primer

On this page

A 30-second Solidity primer (the language of Ethereum)

Solidity is the dominant smart-contract language on Ethereum and other EVM chains. The key concepts you need for the snippets:

  • State variables: persistent storage on the contract (e.g. mapping(address => uint) balances;).
  • Functions: callable, with visibility (public/external/internal/private).
  • Modifiers: reusable preconditions (e.g. onlyOwner to restrict a function to the contract owner).
  • Events: logs that off-chain code can read.
  • External calls: calling another contract's function (to.call{...}) — a primary risk surface.
  • Immutability: once deployed, the bytecode (usually) can't change. Upgradable proxies exist but add their own risks.

The primer, in one contract

1contract Vault {2 address owner;3 mapping(address => uint) balances;4 event Withdrawn(address to, uint amount);5 modifier onlyOwner() {6 require(msg.sender == owner); _;7 }8 function withdraw(uint amount) external {9 balances[msg.sender] -= amount;10 (bool ok, ) = msg.sender.call{value: amount}("");11 require(ok);12 emit Withdrawn(msg.sender, amount);13 }14 function setOwner(address next) external onlyOwner {15 owner = next;16 }17}1State variable:persistent storage4Event: a log off-chaincode can read3Modifier: a reusableprecondition2Function, with itsvisibility5External call: a primaryrisk surfaceonce deployed, the bytecode (usually) can’t change
The primer’s concepts in one toy contract. Its withdraw updates the balance before making the external call, the safe order the reentrancy lesson comes back to. Not production code.
Educational only, not financial or legal advice.