Naming conventions in Solidity (and other style guides)
A simple to follow guide to the main naming conventions and other style guides for Solidity language that you should know
Table of Contents for Naming conventions in Solidity (and other style guides)
How you write your Solidity code is really up to you. But if you follow the common naming conventions and other style guides it will look neater, be easier to read and look more professional.
This is normally quite important… but with solidity smart contracts appearing publicly (if you share the source code & verify them on etherscan) it is even more important.
Contract names naming convention in Solidity
Contract names should be PascalCase (also known as CapsWords)
Contracts should also match their filename. If a file contains multiple contracts (which itself is not recommended), the filename should match the main/core contract.
Library names naming convention in Solidity
Library names should follow the same convention as contract names - PascalCase.
Libraries should also match their filename.
Struct naming conventions in Solidity
Structs should also be in PascalCase (CapsWords)
You might notice a trend here, but event names should be in PascalCase (CapsWords)
Function names naming convention in Solidity
This should be in camelCase (also known as
Function parameters naming convention in Solidity
These should also be in camelCase (also known as
Should be in camelCase (
Constants should be in all caps with underscores
Modifier names naming conventions in Solidity
These should be in camelCase such as
Enums naming convention in Solidity
Enums should also be in PascalCase
Avoiding name collisions (avoiding variable name shadowing) in Solidity
Sometimes you have two variables (often one is a function param, one is state) with the same name. To avoid name collisions it is recommended to append a underscore.
Ordering of functions
There is a common ordering of functions that you should follow.
- receive function
- fallback function
Within those groups,
pure functions should be listed last.
Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!
📙 Solidity Auditing online quiz
Learn how to audit smart contracts by looking at some example code and trying to find the bugs
⛽ Solidity Gas Optimizations Guide
How to optimize and reduce gas usage in your smart contracts in Solidity
🧪 Guide to testing with Foundry
Guide to adding testing for your Solidity contracts, using the Foundry and Forge tools
📌 Guide to UTXO
UTXO and the UTXO set (used by blockchains such as Bitcoin) explained
📐 Solidity Assembly Guide
Introduction guide to using assembly in your Solidity smart contracts
📦 Ethereum EOF format explained
Information explaining what the upcoming Ethereum EOF format is all about