freecoding.school100% FREE · NO SIGNUP
Ledger LandISSUE #30 of 90

solidity · types · functions · modifiers

BlockyVSDouble-Spend Dan
Blocky saysSolidity has value types, functions with visibility, modifiers, and events.

Core pieces: types (uint, address, bool, mapping, struct); function visibility (public, external, internal, private); modifiers (reusable pre-checks like onlyOwner); and events (logs the outside world can subscribe to). payable functions can receive ETH. Getting visibility and access checks right is the heart of contract security.

Power-ups you unlock

Double-Spend Dan attacks — common mistakes

Boss battleAdd an onlyOwner modifier and an event to the counter contract.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>modifier onlyOwner(){ require(msg.sender==owner); _; }
event Incremented(uint newCount);
function inc() public onlyOwner { count++; emit Incremented(count); }</pre></body></html>
▶ Open the interactive comic issue
‹ Solidity · The Contract LanguageSolidity · Storage Vs Memory Vs Calldata ›