← all simulations

slide 22 · contracts

Smart contracts

call inc()
contract
storage
n = 1

Deploy a , call its functions, and watch and events change.

  1. 1Deploy the contract
  2. 2Call its functions
  3. 3Watch storage and events change
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.
Deployed
no
count (storage)
0
Total gas used
0
msg.sender
owner

Counter.sol

1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.24;
3
4contract Counter {
5 address public owner;
6 uint256 public count;
7
8 event Incremented(address by, uint256 newCount);
9
10 constructor() { owner = msg.sender; }
11
12 function increment() public {
13 count += 1;
14 emit Incremented(msg.sender, count);
15 }
16
17 function reset() public {
18 require(msg.sender == owner, "not owner");
19 count = 0;
20 }
21}

A is just code plus living at an . It has no owner process, cannot run by itself, and only executes when a transaction calls it.

Interact

Emitted events (the contract's log output)

waiting…

Transaction log

waiting…

Three things to take away: writes dominate cost; every state change is re-executed and verified by every ; and events are cheap logs that front-ends read, but contracts themselves cannot read events back.