[Solidity] About the contract clause

This section describes the contract clause, which is a fundamental part of Solidity.

What is contract anyway?

As you know, contract refers to "smart contract".

A smart contract is a program that describes "a contract that automatically executes a process on the blockchain".

When called by a user, the process described in the contract is automatically executed.

Grammar of contract

Detailed grammar in contract is also noted.

Match contract name and file name

It is recommended that the contract name match the file name due to Solidity's style guidelines.

SampleContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SampleContract {
}

Use CapWords style for naming contract

Under the style guidelines, it is recommended that the CapWords style (capitalize the first letter of each word) be used for naming contracts.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SampleContract {
}

Multiple contracts can be defined on a single source file.

You can define not only one but also multiple contract clauses on a single source file.

However, due to coding conventions, we often use a one-file, one-contract operation.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SampleContract1 {
}


contract SampleContract2 {
}


contract SampleContract3 {
}

Two blank lines between contract definitions

For style guidelines, it is recommended that there be two blank lines between contract definitions.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SampleContract1 {
}


contract SampleContract2 {
}

We reviewed again the contract clause, which is a must when writing Solidity code. Although many of the contents may have been familiar to you, we hope you learned something new.

タイトルとURLをコピーしました