Solidity Coding Standards

Jeffrey Scholz
RareSkills
Published in
7 min readOct 17, 2023

--

The purpose of this article is not to rehash the official Solidity Style Guide, which you should read. Rather, it is to document the common deviations from the style guide that come up in code reviews or audits. Some of the items here are not in the style guide, but are common stylistic Solidity developer mistakes.

First two lines

1. Include SPDX-License-Identifier

Of course your code will compile without it, but you’ll get a warning, so just make the warning go away.

2. Fix the solidity pragma unless writing a library

You’ve probably seen pragmas such as the following:

pragma solidity ^0.8.0;

and

pragma solidity 0.8.21;

Which one should you use and when? If you are the one compiling and deploying the contract, you know the version of Solidity you are compiling with so for the sake of clarity, you should fix the Solidity version to the compiler you are using.

On the other hand, if you are creating a library for other people to extend, such as what OpenZeppelin and Solady do, you should not fix the pragma because you don’t know which compiler version the end user will be using.

Imports

3. Explicitly set the library version in the import statement

--

--