{"id":20629911,"url":"https://github.com/tradmod/smard-contracts","last_synced_at":"2026-06-06T15:02:15.310Z","repository":{"id":126804181,"uuid":"547307214","full_name":"TradMod/Smard-Contracts","owner":"TradMod","description":"Best Practices \u0026 Techniques to make Smart Contracts, \"Smard Contracts\" (Smart + Hard)","archived":false,"fork":false,"pushed_at":"2022-10-12T13:36:01.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T07:07:07.974Z","etag":null,"topics":["blockchain","gas-optimization","security","smardcontracts","smart-contracts","solidity","solidity-contracts","web3security"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"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/TradMod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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}},"created_at":"2022-10-07T13:19:51.000Z","updated_at":"2023-01-25T07:51:49.000Z","dependencies_parsed_at":"2023-06-25T20:31:56.199Z","dependency_job_id":null,"html_url":"https://github.com/TradMod/Smard-Contracts","commit_stats":null,"previous_names":["shaheenrehman/smard-contracts","tradmod/smard-contracts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradMod%2FSmard-Contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradMod%2FSmard-Contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradMod%2FSmard-Contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TradMod%2FSmard-Contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TradMod","download_url":"https://codeload.github.com/TradMod/Smard-Contracts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242583258,"owners_count":20153413,"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":["blockchain","gas-optimization","security","smardcontracts","smart-contracts","solidity","solidity-contracts","web3security"],"created_at":"2024-11-16T14:06:24.050Z","updated_at":"2025-03-08T17:24:11.658Z","avatar_url":"https://github.com/TradMod.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gas Optimizations:\n\n## I. Use `Custom Errors` instead of `Require` Statements\n\nThe benefit of using [Custom Errors](https://blog.soliditylang.org/2021/04/21/custom-errors/)  is that they significantly reduce gas costs especially deployment costs because unlike `require`, `Custom Errors` do not store a dynamic `string` of Error Message to revert when an operation fails.\n\n**Examlple**: Execution Cost: 232904\n```solidity\ncontract Ownable {\n  \n    address public owner = msg.sender;\n\n    // `require` Not Optimized:\n    function newOwner(address _newOwner) public {\n        require(owner == msg.sender, \"Only Owner Allowed\");\n        owner = _newOwner;\n    }\n}\n```\n**Examlple**: Execution Cost: 232904\n```solidity\nerror Only_Owner_Allowed(); //Custom errors are defined using the error statement\n\ncontract Ownable_SmardWay {\n  \n    address public owner = msg.sender;\n\n    // `Custom Error` Gas Optimized:\n    function newOwner_SmardWay(address _newOwner) public {\n        if(owner != msg.sender) { revert Only_Owner_Allowed(); }\n        owner = _newOwner;\n    }\n}\n```\nReferences: https://tinyurl.com/3yaj4u8n \u0026 https://tinyurl.com/2k3wv67m\n\n\n## II. Use `++i` instead `i++` inside loops\n\n`++i` returns the incremented value, `i++` returns the non-incremented value, which costs a little bit extra gas.\n\n**Examlple**: Execution Cost: 182005\n```solidity\ncontract PrimeCheck {\n    function primeChecker(uint n) public pure returns (bool) {\n        for (uint i = 2; i \u003c n; i++) {\n            if (n % i == 0) {\n                return true;\n            }\n        }\n        return false;\n    }\n}\n```\n**Examlple**: Execution Cost: 181573\n```solidity\ncontract PrimeCheck_SmardWay {\n    function primeChecker_SmardWay(uint n) public pure returns (bool) {\n        for (uint i = 2; i \u003c n; ++i) {\n            if (n % i == 0) {\n                return true;\n            }\n        }\n        return false;\n    }\n}\n```\nReferences: https://tinyurl.com/mr4b4jcd \u0026 https://tinyurl.com/mr2xtn2r ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradmod%2Fsmard-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftradmod%2Fsmard-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradmod%2Fsmard-contracts/lists"}