Source File Layout
Learn the sections and features of a regular Solidity smart contract source file.
We'll cover the following...
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.0pragma 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 Solidity version and import Hardhat’s
console.sol
library to log information and errors.Lines 11–13: We define our smart contract.
SPDX license identifier
This component should be the first thing in our smart contract code file, written in the form of a comment.
Note: The SPDX License List contains commonly found licenses and exceptions used in ...