Solidity Basics: Your First Lines of Code — Plain-language primer
Know how a Solidity file is structured.
Starter kitSolidity files are small agreements: a SPDX line for licensing, a pragma line to lock the compiler version, and one or more contracts that hold state and functions. Think of it like a typed, on-chain class with very explicit visibility.
ShapeEvery contract declares state variables (live on-chain), functions (public or private entry points), and events (lightweight logs). The way you set visibility and data locations is as important as the logic itself.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Hello {
string private greeting;
constructor(string memory _greet) {
greeting = _greet;
}
function say() external view returns (string memory) {
return greeting;
}
}
Mental modelYou are writing code that strangers will call. Defaults can betray you: public state creates free getters, public functions expose ABI methods, and forgetting a visibility modifier can open footguns. Get the skeleton right before you add business logic.