{"id":22975860,"url":"https://github.com/clemlak/solidity-style-guide","last_synced_at":"2026-01-28T00:07:55.161Z","repository":{"id":267787213,"uuid":"902351424","full_name":"clemlak/solidity-style-guide","owner":"clemlak","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-14T07:41:39.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T22:49:49.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clemlak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-12T11:56:41.000Z","updated_at":"2025-01-14T07:41:42.000Z","dependencies_parsed_at":"2024-12-12T13:19:56.993Z","dependency_job_id":"73450878-bfdc-40df-ab89-cdee02d4146d","html_url":"https://github.com/clemlak/solidity-style-guide","commit_stats":null,"previous_names":["clemlak/solidity-style-guide"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemlak%2Fsolidity-style-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemlak%2Fsolidity-style-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemlak%2Fsolidity-style-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemlak%2Fsolidity-style-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clemlak","download_url":"https://codeload.github.com/clemlak/solidity-style-guide/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246777833,"owners_count":20832032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T00:39:55.223Z","updated_at":"2026-01-28T00:07:50.142Z","avatar_url":"https://github.com/clemlak.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solidity Style Guide\n\n## Introduction\n\nThis is my personal attempt to write a cool style guide for [Solidity](https://soliditylang.org/), all the recommendations that you will read in this guide are purely personal and opinionated, have fun reading!\n\n## Definitions\n\n### Prefer \"free definitions\" when possible\n\nVariables, functions and events can be defined outside of a `contract` or a `library`, this makes them easily accessible and reusable in other places.\n\n### Follow naming conventions\n\nNaming conventions for variables where defined to quickly understand what they are used for.\n\n```solidity\n// Constants should be in uppercase\nuint256 constant MAX_SUPPLY = 1e25;\n\n// Variables should be in camelCase\nuint256 totalSupply = 1e24;\n\n// Functions should be in camelCase\nfunction totalSupply() public view returns (uint256) {\n  return totalSupply;\n}\n\n// Events should be in PascalCase\nevent Transfer(address indexed from, address indexed to, uint256 value);\n\n// Structs should be in PascalCase\nstruct Token {\n  uint256 totalSupply;\n}\n\n// Enums should be in PascalCase\nenum UserRole { None, Sender, Recipient }\n\n// Modifiers should be in camelCase\nmodifier onlyOwner() {\n  // ...\n  _;\n}\n\n// Errors should be in PascalCase\nerror OnlyOwner();\n\n// Interfaces should be in PascalCase\ninterface IRouter {\n  // ...\n}\n\n// Libraries should be in PascalCase\nlibrary MathLibrary {\n  // ...\n}\n\n// Contracts should be in PascalCase\ncontract Token {\n  // ...\n}\n```\n\n## Imports\n\n### Always use named imports\n\nUsing named imports is cleaner and helps quickly figuring out where imports come from.\n\n```solidity\n// This is bad\nimport \"Foo.sol\";\n\n// This is good\nimport { IFoo } from \"Fool.sol\";\n```\n\n### Highlight module imports using a special character\n\nModule imports can be highlighted using a special character, this makes it easier to distinguish them from other imports.\n\n```solidity\nimport { IFoo } from \"@foo/IFool.sol\";\n```\n\n### Use absolute paths for imports\n\nRelative paths require some brain power to figure out where the file is located, using absolute paths is cleaner and easier to understand.\n\n```solidity\n// This is bad\nimport { IFoo } from \"../../interfaces/IFoo.sol\";\n\n// This is good\nimport { IFoo } from \"src/interfaces/IFoo.sol\";\n```\n\n### Order imports\n\nImports should be ordered in the following way:\n\n1. Modules or libraries (external packages)\n2. Local files\n\n```solidity\nimport { IFoo } from \"@foo/IFoo.sol\";\nimport { IBar } from \"src/interfaces/IBar.sol\";\n```\n\n## Errors\n\n### Use custom revert errors with require\n\n`require` now accepts custom revert errors, this is a great improvement as strings are expensive to store onchain.\n\n```solidity\n// This is bad\nrequire(msg.sender == owner, \"Only owner can call this function\");\n\n// This is good\nrequire(msg.sender == owner, OnlyOwner());\n```\n\n### Use explicit error names\n\nError names should be clear enough to explain what went wrong.\n\n```solidity\n// This is bad\nerror WrongAddress();\n\n// This is good\nerror OnlyOwner();\n```\n\n### Use error parameters to provide details\n\nErrors might be reused multiple times in the same function, using parameters will help understand what went wrong.\n\n```solidity\n// Let's say we have users with different roles\nenum UserRole { None, Sender, Recipient }\n\n// And we revert if the user has the wrong role\nerror WrongUserRole(address user, UserRole expected, UserRole actual);\n\n// This function reuses the same error twice, providing details helps understand where the error comes from\nfunction transfer(address from, address to) public {\n  require(getRole[from] == UserRole.Sender, WrongUserRole(from, UserRole.Sender, getRole[from]));\n  require(getRole[to] == UserRole.Recipient, WrongUserRole(to, UserRole.Recipient, getRole[to]));\n}\n```\n\n## Comments\n\n### Use NatSpec\n\nUse `///` for single line comments, and `/** ... */` for multi-line comments.\n\n```solidity\n/// @notice This is a single line comment\n\n/**\n * @notice This is a multi-line comment, you can write\n * as much as you want here.\n */\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclemlak%2Fsolidity-style-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclemlak%2Fsolidity-style-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclemlak%2Fsolidity-style-guide/lists"}