Skill 2.1.1

Describe the structure of a Solidity source file and contract

Key Concepts

A Solidity file begins with an SPDX licence identifier comment, such as // SPDX-License-Identifier: MIT, followed by a version pragma such as pragma solidity ^0.8.28;. The caret allows any 0.8.x compiler from 0.8.28 upwards; a range such as >=0.8.20 <0.9.0 or an exact version can be used instead. import statements bring in other files, such as OpenZeppelin contracts.

A contract is similar to a class. It contains state variables stored permanently on chain, functions, modifiers, events, errors, struct and enum type definitions and an optional constructor. A file can contain several contracts, interfaces and libraries, and each deployable contract compiles to its own bytecode and ABI.