Your First 90 DaysAcademy
First Contact · What a Contract Even Is · Week 1 · Checkpoint 1

Your First Contract

By the end you will have read a complete, real smart contract, every line, pragma to closing brace, and understood exactly what each one does. Not a toy diagram of a contract. The contract.

12 steps~25 min3 nodes for your map
01 · The whole machine

You have heard that smart contracts move real money, and you have probably nodded along without ever seeing one. Here is one. Twenty four lines, complete, on the board right now. There is no hidden file and no part two. By the end of this lesson you will have read all of it.

Think of it as a piggy bank with rules instead of a lock. A glass pig, bolted to a public square, its rules engraved on the front. Anyone can read the engraving; the pig itself enforces it. Reading the engraving is this lesson.

02 · The paperwork

Start at the very top. The first line is a note to humans: it names the license this text is published under. The machine ignores it entirely. It begins with two slashes, and everything after two slashes is a comment: words for readers, never instructions.

The second line is a note to the compiler. Solidity has dialects, and this line names which one the text is written in: version 0.8.20 or compatible. The keyword is pragma. Neither line does anything on chain. The paperwork is done.

03 · The box

Line 4 opens the box. Function first: a program that lives at its own address on the chain and follows its own text, nothing more and nothing less. The name Solidity gives that: a contract. Ours is called PiggyBank.

The opening brace starts a box with two kinds of contents: things the pig remembers, and things the pig can do. Everything until the closing brace on line 24 lives inside. The engraving on the glass starts here.

04 · What it remembers

Two things the pig remembers. An address is the type for an account's identity: a wallet, or another contract. A uint256 is the type for a whole number. So the pig remembers a who and a how much, and names them owner and goal.

Variables that live in the contract's permanent memory have a name: state variables. And the word public means anyone may read them. That is all it means. It grants no one the right to change them. Glass, remember: everyone sees in, nobody reaches in.

05 · The birth certificate

This block is the birth certificate. Function first: code that runs exactly once, the moment the contract is deployed, and then never again. The name: the constructor. Ana deploys the pig and passes a goal along with it.

Line 9 stores a special value: always, in any function, whoever is calling right now. Its name is msg.sender. Line 10 stores the goal Ana passed in. Now, before the reveal: Ana deploys with a goal of 5 ETH. Who is owner?

Ana deploys the PiggyBank with a goal of 5 ETH. The constructor runs. Who is owner?
your balance2,400
BANK_DBowner: the bank
you2,400
what the app is actually showing you
BANK_DBowner: the bank
you2,400their pen
you hold a claim. they hold the pen.
your digital life
BANK · you2,400the bank ✍
INSTAGRAM · you2.1M followersMeta ✍
STEAM · you134 gamesValve ✍
AIRLINE · you58,200 milesthe airline ✍
four tables. zero pens that are yours.
BANK_DBowner: the bank
you2,400
DENIED
try both pens
PLATFORM_DBowner: the platform
her · 8 years2,000,000 followers
one automated decision away
BANK_DB · you · 2,400intentcompetencecontinuity
your row stands on all three
FTX_DBowner: FTX
you5 BTC
the backing vault●●●●●
the row stayed. the backing did not.
CARD_DBowner: your bank ✍
TV you never bought−1,100
fraud reversal+1,100
someone holds the pen, so someone can fix it
?_DBowner: nobody
youstill yours?
?
can a table exist that nobody owns?
?
?_DBowner: ̶n̶o̶b̶o̶d̶y̶
you100
no owner, no pen, no trust?
keeper 1
you100
keeper 2
you100
keeper 3
you100
keeper 4
you100
keeper 5
you100
no THE copy, only copies.
keeper 2
you100
keeper 3
you100
keeper 4
you100
keeper 5
you100
your copy
you100
five copies. one of them is yours.
one attacker
one attacker, ten thousand faces.
real machinesburned wattsnext page, sealed
writing costs watts. faking voters buys nothing.
cost paid OUTSIDE: hardware and power
proof of work, burn energy to vote.
page 1you · 100page 2you · 100page 3you · 100page 4you · 100
rewrite one line, break every lock after it.
office lunchtrusted keeperconsensusfive keepers, real cost
the price buys trustlessness. the office already has trust.
?
ownerless ledger
you?
a key, not a login?
nobody owns the table. so who owns your row?
contractstatefunctions

Three new nodes on your map

contract · state · functions · +10 Lynx