|
| 1 | +# Solidity Template |
| 2 | + |
| 3 | +My favourite setup for writing Solidity smart contracts. |
| 4 | + |
| 5 | +- [Hardhat](https://github.com/nomiclabs/hardhat): compile and run the smart contracts on a local development network |
| 6 | +- [TypeChain](https://github.com/ethereum-ts/TypeChain): generate TypeScript types for smart contracts |
| 7 | +- [Ethers](https://github.com/ethers-io/ethers.js/): renowned Ethereum library and wallet implementation |
| 8 | +- [Waffle](https://github.com/EthWorks/Waffle): tooling for writing comprehensive smart contract tests |
| 9 | +- [Solhint](https://github.com/protofire/solhint): linter |
| 10 | +- [Solcover](https://github.com/sc-forks/solidity-coverage): code coverage |
| 11 | +- [Prettier Plugin Solidity](https://github.com/prettier-solidity/prettier-plugin-solidity): code formatter |
| 12 | + |
| 13 | +This is a GitHub template, which means you can reuse it as many times as you want. You can do that by clicking the "Use this |
| 14 | +template" button at the top of the page. |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +### Pre Requisites |
| 19 | + |
| 20 | +Before running any command, make sure to install dependencies: |
| 21 | + |
| 22 | +```sh |
| 23 | +$ yarn install |
| 24 | +``` |
| 25 | + |
| 26 | +### Compile |
| 27 | + |
| 28 | +Compile the smart contracts with Hardhat: |
| 29 | + |
| 30 | +```sh |
| 31 | +$ yarn compile |
| 32 | +``` |
| 33 | + |
| 34 | +### TypeChain |
| 35 | + |
| 36 | +Compile the smart contracts and generate TypeChain artifacts: |
| 37 | + |
| 38 | +```sh |
| 39 | +$ yarn typechain |
| 40 | +``` |
| 41 | + |
| 42 | +### Lint Solidity |
| 43 | + |
| 44 | +Lint the Solidity code: |
| 45 | + |
| 46 | +```sh |
| 47 | +$ yarn lint:sol |
| 48 | +``` |
| 49 | + |
| 50 | +### Lint TypeScript |
| 51 | + |
| 52 | +Lint the TypeScript code: |
| 53 | + |
| 54 | +```sh |
| 55 | +$ yarn lint:ts |
| 56 | +``` |
| 57 | + |
| 58 | +### Test |
| 59 | + |
| 60 | +Run the Mocha tests: |
| 61 | + |
| 62 | +```sh |
| 63 | +$ yarn test |
| 64 | +``` |
| 65 | + |
| 66 | +### Coverage |
| 67 | + |
| 68 | +Generate the code coverage report: |
| 69 | + |
| 70 | +```sh |
| 71 | +$ yarn coverage |
| 72 | +``` |
| 73 | + |
| 74 | +### Report Gas |
| 75 | + |
| 76 | +See the gas usage per unit test and average gas per method call: |
| 77 | + |
| 78 | +```sh |
| 79 | +$ REPORT_GAS=true yarn test |
| 80 | +``` |
| 81 | + |
| 82 | +### Clean |
| 83 | + |
| 84 | +Delete the smart contract artifacts, the coverage reports and the Hardhat cache: |
| 85 | + |
| 86 | +```sh |
| 87 | +$ yarn clean |
| 88 | +``` |
| 89 | + |
| 90 | +### Deploy |
| 91 | + |
| 92 | +Deploy the contracts to Hardhat Network: |
| 93 | + |
| 94 | +```sh |
| 95 | +$ yarn deploy |
| 96 | +``` |
| 97 | + |
| 98 | +Deploy the contracts to a specific network, such as the Ropsten testnet: |
| 99 | + |
| 100 | +```sh |
| 101 | +$ yarn deploy:network ropsten |
| 102 | +``` |
| 103 | + |
| 104 | +## Syntax Highlighting |
| 105 | + |
| 106 | +If you use VSCode, you can enjoy syntax highlighting for your Solidity code via the |
| 107 | +[vscode-solidity](https://github.com/juanfranblanco/vscode-solidity) extension. The recommended approach to set the |
| 108 | +compiler version is to add the following fields to your VSCode user settings: |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "solidity.compileUsingRemoteVersion": "v0.8.4+commit.c7e474f2", |
| 113 | + "solidity.defaultCompiler": "remote" |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +Where of course `v0.8.4+commit.c7e474f2` can be replaced with any other version. |
0 commit comments