Source File Layout

Learn the sections and features of a regular Solidity smart contract source file.

Coding components

We learned about Remix and its basic features by writing a simple test contract. In this lesson, we’ll go through the different sections of the code to understand the components of a Solidity file and what each one does. Let’s begin with the file below:

Press + to interact
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "hardhat/console.sol";
/**
* @title Contact
* @dev Store & retrieve contacts of friends and family
*/
contract Contact {
// contract code goes here.
}
  • Line 1: We define the SPDX identifier.

  • Lines 3–5: We set the ...