Building with Solidity

2. Building the Container

Identify the core components of a Solidity file, including metadata and state variables.

Prerequisites

Smart Contract Anatomy 🏗️

Smart contracts are more than just code; they are self-executing logic that runs exactly as written.

At the very top, we use an SPDX-License-Identifier so tools can identify the legal license, and a pragma to tell the compiler which version to use.

TO REMEMBER

Think of a contract like a class in Java or Python. It is a container for data and logic.

Inside, we store State Variables permanently on the blockchain. Changing these variables updates the contract’s memory, which costs gas.

Solidity has special data types:

  • uint256: For positive numbers like balances.

  • address: For wallet or contract locations.

  • mapping: A key/value store, perfect for associating a wallet with its data.

Almost there! You can also use a Struct to group related data, like a user profile with a name and a wallet address.