{"id":19539109,"url":"https://github.com/0xcert/solidity-style-guide","last_synced_at":"2025-06-30T17:34:48.642Z","repository":{"id":140712829,"uuid":"164307481","full_name":"0xcert/solidity-style-guide","owner":"0xcert","description":"Solidity style guide","archived":false,"fork":false,"pushed_at":"2019-02-01T11:22:38.000Z","size":16,"stargazers_count":19,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-26T16:45:28.525Z","etag":null,"topics":["ethereum","smart-contract","solidity","styleguide"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xcert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"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":"2019-01-06T13:00:48.000Z","updated_at":"2025-03-29T08:46:53.000Z","dependencies_parsed_at":"2023-09-29T06:23:07.823Z","dependency_job_id":null,"html_url":"https://github.com/0xcert/solidity-style-guide","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/0xcert/solidity-style-guide","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xcert%2Fsolidity-style-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xcert%2Fsolidity-style-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xcert%2Fsolidity-style-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xcert%2Fsolidity-style-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xcert","download_url":"https://codeload.github.com/0xcert/solidity-style-guide/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xcert%2Fsolidity-style-guide/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262819462,"owners_count":23369481,"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":["ethereum","smart-contract","solidity","styleguide"],"created_at":"2024-11-11T02:38:12.444Z","updated_at":"2025-06-30T17:34:48.632Z","avatar_url":"https://github.com/0xcert.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 0xcert Solidity Style Guide\n\n## Introduction\n\nThis guide is based on the Solidity style guide that can be found here:\nhttps://github.com/ethereum/solidity/blob/v0.5.1/docs/style-guide.rst. It mostly follows the guide\nline but with slight changes and more specific restrictions. \n\nThis guide is intended to provide coding conventions for writing solidity code.\nThis guide should be thought of as an evolving document that will change over\ntime as useful conventions are found and old conventions are rendered obsolete.\n\n## Code Layout\n\n### Indentation\n\nUse 2 spaces per indentation level.\n\n### Tabs or Spaces\n\nSpaces are the preferred indentation method.\n\nMixing tabs and spaces must be avoided.\n\n### Multiple contracts in the same file\n\nEach smart contract should be in its own file.\n\n### Maximum Line Length\n\nMaximum line length is 100 characters.\n\n### Function Calls\n\nYes\n\n    thisFunctionCallIsReallyLong(\n      longArgument1,\n      longArgument2,\n      longArgument3\n    );\n\n    shortFunctionCall(arg1);\n\nNo\n\n    thisFunctionCallIsReallyLong(longArgument1,\n                                  longArgument2,\n                                  longArgument3\n    );\n    \n    thisFunctionCallIsReallyLong(longArgument1,\n        longArgument2,\n        longArgument3\n    );\n    \n    thisFunctionCallIsReallyLong(\n        longArgument1, longArgument2,\n        longArgument3\n    );\n    \n    thisFunctionCallIsReallyLong(\n    longArgument1,\n    longArgument2,\n    longArgument3\n    );\n    \n    thisFunctionCallIsReallyLong(\n        longArgument1,\n        longArgument2,\n        longArgument3);\n\n#### Assignment Statements\n\nYes\n\n    thisIsALongNestedMapping[being][set][to_some_value] = someFunction(\n      argument1,\n      argument2,\n      argument3,\n      argument4\n    );\n\nNo\n\n    thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1,\n                                                                       argument2,\n                                                                       argument3,\n                                                                       argument4);\n\n#### Event Definitions and Event Emitters\n\nYes\n\n    event ShortOneArg(\n      address _sender\n    );\n    \n    event LongAndLotsOfArgs(\n      address _sender,\n      address _recipient,\n      uint256 _publicKey,\n      uint256 _amount,\n      bytes32[] _options\n    );\n    \n    emit LongAndLotsOfArgs(\n      sender,\n      recipient,\n      publicKey,\n      amount,\n      options\n    );\n\n    emit ShortOneArg(sender);\n\nNo\n\n    event ShortOneArg(address _sender);\n    \n    event LongAndLotsOfArgs(address _sender,\n                            address _recipient,\n                            uint256 _publicKey,\n                            uint256 _amount,\n                            bytes32[] _options);\n    \n    emit LongAndLotsOfArgs(sender,\n                      recipient,\n                      publicKey,\n                      amount,\n                      options);\n\n### Source File Encoding\n\nUTF-8 or ASCII encoding is preferred.\n\n### Imports\n\nImport statements must always be placed at the top of the file.\n\n### Code Ordering\n\nFunctions and declarations must be grouped according to their visibility and ordered:\n\n- constructor\n- fallback function (if exists)\n- external\n- public\n- internal\n- private\n\nWithin a grouping, place the `view` and `pure` functions last.\n\nYes\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    contract A\n    {\n      using SafeMath for uint256;\n    \n      uint256 someVariable;\n    \n      event SomeEvent(\n        uint256 _arg1\n      );\n    \n      modifier SomeModifier(\n        uint256 _arg1\n      )\n      {\n        // some check\n        _;\n      }\n    \n      constructor() \n        public \n      {\n          // ...\n      }\n    \n      function() \n        external \n      {\n          // ...\n      }\n    \n      // External functions\n      // ...\n    \n      // External functions that are view\n      // ...\n    \n      // External functions that are pure\n      // ...\n    \n      // Public functions\n      // ...\n    \n      // Internal functions\n      // ...\n    \n      // Private functions\n      // ...\n    }\n\nNo\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    contract A\n    {\n    \n      // External functions\n      // ...\n    \n      function() \n        external \n      {\n          // ...\n      }\n    \n      // Private functions\n      // ...\n    \n      // Public functions\n      // ...\n    \n      constructor()\n        public \n      {\n          // ...\n      }\n    \n      // Internal functions\n      // ...\n    }\n\n### Whitespace in Expressions\n\nAvoid extraneous whitespace in the following  situations:\n\nYes\n\n    spam(ham[1], Coin({ name: \"ham\" }));\n\nNo\n\n    spam( ham[ 1 ], Coin( { name: \"ham\" } ) );\n\nMore than one space around an assignment or other operator to align with\n  another:\n\nYes\n\n    x = 1;\n    y = 2;\n    long_variable = 3;\n\nNo\n\n    x             = 1;\n    y             = 2;\n    long_variable = 3;\n\n\nControl Structures\n\nYes\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    contract Coin \n    {\n      struct Bank \n      {\n        address owner;\n        uint balance;\n      }\n    }\n\nNo\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    contract Coin {\n      struct Bank {\n        address owner;\n        uint balance;\n      }\n    }\n\nThe same recommendations apply to the control structures `if`, `else`, `while`,\nand `for`.\n\nAdditionally there must be a single space between the control structures\n`if`, `while`, and `for` and the parenthetic block representing the\nconditional, as well as a single space between the conditional parenthetic\nblock and the opening brace.\n\nYes\n\n    if (...) \n    {\n      ...\n    }\n\nNo\n\n    if (...) {\n      ...\n    }\n    \n    while(...){\n    }\n    \n    for (...) {\n      ...;}\n\nFor control structures whose body contains a single statement, omitting the\nbraces is NOT ok in any condition.\n\nYes\n\n    if (x \u003c 10) \n    {\n      x += 1;\n    }\n\nNo\n\n    if (x \u003c 10)\n      x += 1;\n\n    if (x \u003c 10)\n      someArray.push(Coin({\n        name: 'spam',\n        value: 42\n      }));\n\nFor `if` blocks which have an `else` or `else if` clause, the `else` must be\nplaced on the same line as the `if`'s closing brace. This is an exception compared\nto the rules of other block-like structures.\n\nYes\n\n    if (x \u003c 3) \n    {\n      x += 1;\n    } \n    else if (x \u003e 7) \n    {\n      x -= 1;\n    } \n    else \n    {\n      x = 5;\n    }\n\n    if (x \u003c 3) \n    {\n      x += 1;\n    }\n    else \n    {\n      x -= 1;\n    }\n   \nNo\n\n    if (x \u003c 3) {\n      x += 1;\n    } else {\n      x -= 1;\n    }\n\n    if (x \u003c 3)\n      x += 1;\n    else\n      x -= 1;\n\n### Function Declaration\n\nFor every function declarations, it is recommended to drop each argument onto\nit's own line at the same indentation level as the function body.  The closing\nparenthesis and opening bracket must be placed on their own line as well at\nthe same indentation level as the function declaration.\n\nYes\n\n    function thisFunctionHasNoArguments()\n      public\n    {\n      doSomething();\n    }\n    \n    function thisFunctionHasAnArgument(\n      address _a\n    )\n      public\n    {\n      doSomething();\n    }\n    \n    function thisFunctionHasLotsOfArguments(\n      address _a,\n      address _b,\n      address _c,\n      address _d,\n      address _e,\n      address _f\n    )\n      public\n    {\n      doSomething();\n    }\n\nNo\n\n    function thisFunctionHasNoArguments() public\n    {\n      doSomething();\n    }\n    \n    function thisFunctionHasAnArgument(address _a) public {\n      doSomething();\n    }\n    \n    function thisFunctionHasLotsOfArguments(address _a, address _b, address _c,\n        address _d, address _e, address _f) public {\n        doSomething();\n    }\n    \n    function thisFunctionHasLotsOfArguments(address _a,\n                                            address _b,\n                                            address _c,\n                                            address _d,\n                                            address _e,\n                                            address _f) public {\n        doSomething();\n    }\n    \n    function thisFunctionHasLotsOfArguments(\n        address _a,\n        address _b,\n        address _c,\n        address _d,\n        address _e,\n        address _f) public {\n        doSomething();\n    }\n\nIf a function declaration has modifiers, then each modifier must be\ndropped to its own line.\n\nYes\n\n    function thisFunctionNameIsReallyLong(\n      address _x,\n      address _y,\n      address _z\n    )\n      public\n      onlyowner\n      priced\n      returns (address)\n    {\n        doSomething();\n    }\n    \n    function thisFunctionNameIsReallyLong(\n      address _x,\n      address _y,\n      address _z,\n    )\n      public\n      onlyowner\n      priced\n      returns (address)\n    {\n      doSomething();\n    }\n\nNo\n\n    function thisFunctionNameIsReallyLong(address _x, address _y, address _z)\n                                          public\n                                          onlyowner\n                                          priced\n                                          returns (address) {\n        doSomething();\n    }\n    \n    function thisFunctionNameIsReallyLong(address _x, address _y, address _z)\n        public onlyowner priced returns (address)\n    {\n        doSomething();\n    }\n    \n    function thisFunctionNameIsReallyLong(address _x, address _y, address _z)\n        public\n        onlyowner\n        priced\n        returns (address) {\n        doSomething();\n    }\n\nMultiline output parameters and return statements must follow the same style.\n\nYes\n\n    function thisFunctionNameIsReallyLong(\n      address _a,\n      address _b,\n      address _c\n    )\n      public\n      returns (\n        address someAddressName,\n        uint256 LongArgument,\n        uint256 Argument\n      )\n    {\n      doSomething()\n    \n      return (\n        veryLongReturnArg1,\n        veryLongReturnArg2,\n        veryLongReturnArg3\n      );\n    }\n\nNo\n\n    function thisFunctionNameIsReallyLong(\n        address _a,\n        address _b,\n        address _c\n    )\n        public\n        returns (address someAddressName,\n                 uint256 LongArgument,\n                 uint256 Argument)\n    {\n        doSomething()\n    \n        return (veryLongReturnArg1,\n                veryLongReturnArg1,\n                veryLongReturnArg1);\n    }\n\nFor constructor functions on inherited contracts whose bases require arguments,\nit is recommended to drop the base constructors onto new lines in the same\nmanner as modifiers.\n\nYes\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    // Base contracts just to make this compile\n    contract B {\n    \n      constructor(\n        uint\n      ) \n        public \n      {\n      }\n    \n    }\n    \n    contract C {\n    \n      constructor(\n        uint,\n        uint\n      ) \n        public\n      {\n      }\n    \n    }\n    \n    contract D {\n    \n      constructor(\n        uint\n      )\n        public\n      {\n      }\n    \n    }\n    \n    contract A is\n      B,\n      C,\n      D \n    {\n      uint x;\n    \n      constructor(\n        uint _param1,\n        uint _param2,\n        uint _param3,\n        uint _param4,\n        uint _param5\n      )\n        B(_param1)\n        C(_param2, _param3)\n        D(_param4)\n        public\n      {\n        // do something with param5\n        x = _param5;\n      }\n    }\n\nNo\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    // Base contracts just to make this compile\n    contract B {\n        constructor(uint) public {\n        }\n    }\n    contract C {\n        constructor(uint, uint) public {\n        }\n    }\n    contract D {\n        constructor(uint) public {\n        }\n    }\n    \n    contract A is B, C, D {\n        uint x;\n    \n        constructor(uint _param1, uint _param2, uint _param3, uint _param4, uint _param5)\n        B(_param1)\n        C(_param2, _param3)\n        D(_param4)\n        public\n        {\n            x = _param5;\n        }\n    }\n    \n    contract X is B, C, D {\n        uint x;\n    \n        constructor(uint _param1, uint _param2, uint _param3, uint _param4, uint _param5)\n            B(_param1)\n            C(_param2, _param3)\n            D(_param4)\n            public {\n            x = _param5;\n        }\n\n### Mappings\n\nIn variable declarations, do not separate the keyword `mapping` from its\ntype by a space. Do not separate any nested `mapping` keyword from its type by\nwhitespace.\n\nYes\n\n    mapping(uint =\u003e uint) map;\n    mapping(address =\u003e bool) registeredAddresses;\n    mapping(uint =\u003e mapping(bool =\u003e Data[])) public data;\n    mapping(uint =\u003e mapping(uint =\u003e s)) data;\n\nNo\n\n    mapping (uint =\u003e uint) map;\n    mapping( address =\u003e bool ) registeredAddresses;\n    mapping (uint =\u003e mapping (bool =\u003e Data[])) public data;\n    mapping(uint =\u003e mapping (uint =\u003e s)) data;\n\n### Variable Declarations\n\nDeclarations of array variables must not have a space between the type and\nthe brackets.\n\nYes\n\n    uint[] x;\n\nNo\n\n    uint [] x;\n    \n###  Other Recommendations\n\n* Strings must be quoted with double-quotes instead of single-quotes.\n\nYes\n\n    str = \"foo\";\n    str = \"Hamlet says, 'To be or not to be...'\";\n\nNo\n\n    str = 'bar';\n    str = '\"Be yourself; everyone else is already taken.\" -Oscar Wilde';\n\n* Surround operators with a single space on either side.\n\nYes\n\n    x = 3;\n    x = 100 / 10;\n    x += 3 + 4;\n    x |= y \u0026\u0026 z;\n\nNo\n\n    x=3;\n    x = 100/10;\n    x += 3+4;\n    x |= y\u0026\u0026z;\n\n* Operators with a higher priority than others can exclude surrounding\n  whitespace in order to denote precedence.  This is meant to allow for\n  improved readability for complex statement. You should always use the same\n  amount of whitespace on either side of an operator:\n\nYes\n\n    x = 2**3 + 5;\n    x = 2*y + 3*z;\n    x = (a+b) * (a-b);\n\nNo\n\n    x = 2** 3 + 5;\n    x = y+z;\n    x +=1;\n\n## Order of Layout\n\nLayout contract elements in the following order:\n\n1. Pragma statements\n2. Import statements\n3. Interfaces\n4. Libraries\n5. Contract\n\nInside each contract, library or interface, use the following order:\n\n1. Library declarations (`using` statements)\n2. Constant variables\n3. Type declarations\n4. State variables\n5. Events\n6. Modifiers\n7. Functions\n\n## Naming Styles\n\nTo avoid confusion, the following names will be used to refer to different\nnaming styles.\n\n* `b` (single lowercase letter)\n* `B` (single uppercase letter)\n* `lowercase`\n* `lower_case_with_underscores`\n* `UPPERCASE`\n* `UPPER_CASE_WITH_UNDERSCORES`\n* `CapitalizedWords` (or CapWords)\n* `mixedCase` (differs from CapitalizedWords by initial lowercase character!)\n* `Capitalized_Words_With_Underscores`\n* `_underscoreMixedCase` \n\nWhen using initialisms in CapWords, capitalize all the letters of the initialisms. Thus HTTPServerError is better than HttpServerError. When using initialisms is mixedCase, capitalize all the letters of the initialisms, except keep the first one lower case if it is the beginning of the name. Thus xmlHTTPRequest is better than XMLHTTPRequest.\n\n### Names to Avoid\n\n* `l` - Lowercase letter el\n* `O` - Uppercase letter oh\n* `I` - Uppercase letter eye\n\nNever use any of these for single letter variable names.  They are often\nindistinguishable from the numerals one and zero.\n\n### Contract and Library Names\n\n* Contracts and libraries must be named using the CapWords style. Examples: `SimpleToken`, `SmartBank`, `CertificateHashRepository`, `Player`, `Congress`, `Owned`.\n\nAs shown in the example below, if the contract name is `Congress` and the library name is `Owned`, then their associated filenames should be `congress.sol` and `owned.sol`.\n\nYes\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    // owned.sol\n    contract Owned \n    {\n      address public owner;\n    \n      constructor()\n        public \n      {\n        owner = msg.sender;\n      }\n    \n      modifier onlyOwner\n      {\n        require(msg.sender == owner);\n        _;\n      }\n    \n      function transferOwnership(\n        address _newOwner\n      ) \n        public \n        onlyOwner\n      {\n        owner = _newOwner;\n      }\n    }\n    \n    // congress.sol\n    import \"./Owned.sol\";\n    \n    contract Congress is \n      Owned,\n      TokenRecipient\n    {\n      //...\n    }\n\nNo\n\n    pragma solidity \u003e=0.4.0 \u003c0.6.0;\n    \n    // owned.sol\n    contract owned \n    {\n      address public owner;\n    \n      constructor()\n        public \n      {\n        owner = msg.sender;\n      }\n    \n      modifier onlyOwner\n      {\n        require(msg.sender == owner);\n        _;\n      }\n    \n      function transferOwnership(\n        address _newOwner\n      ) \n        public\n        onlyOwner\n      {\n        owner = _newOwner;\n      }\n    }\n    \n    // Congress.sol\n    import \"./owned.sol\";\n    \n    contract Congress is\n      owned,\n      tokenRecipient \n    {\n      //...\n    }\n\n### Struct Names\n\nStructs must be named using the CapWords style. Examples: `MyCoin`, `Position`, `PositionXY`.\n\n### Event Names\n\nEvents must be named using the CapWords style. Examples: `Deposit`, `Transfer`, `Approval`, `BeforeTransfer`, `AfterTransfer`.\n\n### Function Names\n\nFunctions other than constructors must use mixedCase. Examples: `getBalance`, `transfer`, `verifyOwner`, `addMember`, `changeOwner`.\nIf a function is `private` or `internal` function should use _underscoreMixedCase. Examples: `_calculateBalance` , `_doTransfer`. \n\n### Function Argument Names\n\nFunction arguments must use _underscoreMixedCase. Examples: `_initialSupply`, `_account`, `_recipientAddress`, `_senderAddress`, `_newOwner`.\n\nWhen writing library functions that operate on a custom struct, the struct\nshould be the first argument and should always be named `self`.\n\n### Local and State Variable Names\n\nUse mixedCase. Examples: `totalSupply`, `remainingSupply`, `balancesOf`, `creatorAddress`, `isPreSale`, `tokenExchangeRate`.\n\n### Constants\n\nConstants must be named with all capital letters with underscores separating\nwords. Examples: `MAX_BLOCKS`, `TOKEN_NAME`, `TOKEN_TICKER`, `CONTRACT_VERSION`.\n\n### Modifier Names\n\nUse mixedCase. Examples: `onlyBy`, `onlyAfter`, `onlyDuringThePreSale`.\n\n### Enums\n\nEnums, in the style of simple type declarations, must be named using the CapWords style. Examples: `TokenGroup`, `Frame`, `HashStyle`, `CharacterLocation`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xcert%2Fsolidity-style-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xcert%2Fsolidity-style-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xcert%2Fsolidity-style-guide/lists"}