Basic Program Structure
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 4 of 53.
A contract groups data and functions. Our exercises use a contract named Main. Inside it, the main function contains the statements that Coddy runs.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main() external view {
console.log("Inside main");
}
}The license comment describes the source license. The pragma line states compiler compatibility, and the import supplies the practice console. Keep those prepared lines while you learn.
Braces group the contract and function bodies. A simple statement such as console.log("Inside main"); ends with a semicolon. Closing a function or contract uses a brace, without a semicolon.
The name main is Coddy's practice entry point, not a built-in Solidity entry point. The console is a debugging helper provided by the imported library.
From the next chapter onward, examples show only the relevant statements or declarations. Statements go inside the provided main function; helper functions and state declarations go inside the contract but outside main. The code editor still contains the complete runnable contract.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
Practice on your own: Solidity playground