Solidity Smart Contract Convention X

Nhan Cao
3 min readMar 14, 2022

Just a convention to make a good-looking contract. :3
Feel free to apply it.

STRUCTURE

- src
/active: For working contracts
/interfaces: Contains all contract interface type
/libraries: Contains all library type
/utils: Contains all utility type
XXXToken.sol: ERC20 token, ...
XXXContract.sol: Your contract implementation
/archived: For reference, sample contract, etc
/stash: Temporary contract storage. This contract can be moved to `active` for deployment

FORMAT & LINT

  • Format standard
"prettier": "^2.4.0",
"prettier-plugin-solidity": "^1.0.0-beta.18",
  • Lint
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5"
  • Verify before commit
// package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "./node_modules/.bin/solhint -f table 'src/active/**/*.sol' -w 0",
"format": "./node_modules/.bin/prettier --write 'src/active/**/*.sol'",
"prepare": "husky install"
},
"devDependencies": {
....
"husky": "^7.0.2",
"prettier": "^2.4.0",
"prettier-plugin-solidity": "^1.0.0-beta.18",
"pretty-quick": "^3.1.1",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5"
}


// .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged && npm run lint

--

--