Track 4 · Solidity foundations · lesson 2
Your first contract
9 min
Now you change something. One thing.
Nudge
Show me the approach
Show me the code
Explain the solution
If it went red, read the message under the editor before doing anything else. The compiler's own wording is on the first line; the plain-English version is underneath it.
What just happened when you pressed Run
Four separate things, in order:
- Compiled. Solidity became EVM bytecode — the low-level instructions the machine actually understands.
- Deployed. That bytecode was sent as a transaction with no recipient, which is how a contract is created. It got an address.
- Called. The test called
greeting()at that address. - Checked. The returned value was compared against what the test expects.
This is exactly the cycle you will run against a real network in track 6. Same steps, same tools, and there it costs money.
Notice that deployment reported a gas figure. Storing a string permanently is one of the more expensive things a contract can do — the longer your greeting, the more deployment costs.
That is not a quirk of this playground. It is the pricing from track 1, applied to code you just wrote.
Predict
You deploy this contract twice, unchanged. Do you get one contract or two?
Check
Why does `string public greeting` need no getter written by hand?
public storage is not private dataOptional
Marking a variable private stops other contracts reading it. It does not
hide anything from people.
Every storage slot of every contract is readable by anyone with a node — the
data is right there in the state. private is a compile-time visibility rule,
not encryption.
Contracts have been drained because someone stored a secret in a private
variable and assumed that meant secret. Never put anything on-chain you would
not publish.
Worth remembering
- Run = compile, deploy, call, check — the same cycle you'll use on a real network.
- Deployment is a transaction with no recipient; the contract gets its own address.
- The same bytecode deployed twice gives two independent contracts with separate state.
- `private` hides data from other contracts, never from people. Nothing on-chain is secret.