← all simulations

slide 21 · contracts

Solidity syntax & coding

pragma solidity
contract Counter {
uint256 public n;
function inc()
bytecode

Walk a line by line: pragma, , visibility, modifiers, events.

  1. 1Step through the contract line by line
  2. 2Read what each keyword does
  3. 3Compile it to bytecode
live · 0 players in this room

send coins to another player

10.0000 BTC10.0000 ETH
recipient

waiting for another player to join this room… open this page in a second tab or share the link with the class.

fee 0.0005 · total 0.5005 BTC
live transfers in this room
room ledger · tap a row to replay its steps
  • no transfers yet — be the first to pay a classmate.

Token.sol — click a concept to highlight it

1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.24;
3
4contract Token {
5 string public name = "DemoToken";
6 uint8 public constant decimals = 18;
7 address public immutable owner;
8
9 mapping(address => uint256) private _balances;
10
11 event Transfer(address indexed from, address indexed to, uint256 value);
12
13 error InsufficientBalance(uint256 have, uint256 want);
14
15 modifier onlyOwner() {
16 require(msg.sender == owner, "not owner");
17 _;
18 }
19
20 constructor(uint256 supply) {
21 owner = msg.sender;
22 _balances[msg.sender] = supply;
23 }
24
25 function balanceOf(address a) external view returns (uint256) {
26 return _balances[a];
27 }
28
29 function transfer(address to, uint256 amount) external returns (bool) {
30 uint256 bal = _balances[msg.sender];
31 if (bal < amount) revert InsufficientBalance(bal, amount);
32 _balances[msg.sender] = bal - amount;
33 _balances[to] += amount;
34 emit Transfer(msg.sender, to, amount);
35 return true;
36 }
37
38 function mint(address to, uint256 amount) external onlyOwner {
39 _balances[to] += amount;
40 }
41}

1 / 10 · License & pragma

The SPDX comment declares the license (the compiler warns without it). The pragma pins a compiler version range — ^0.8.24 means 0.8.24 up to but excluding 0.9.0. From 0.8.0 onward, arithmetic reverts on overflow by default.

Concepts

Workflow to remember: write in Remix or Foundry → compile to bytecode + ABI → test → deploy to a testnet (Sepolia) → verify the source on Etherscan so users can read what they are trusting.