https://github.com/chaineasy/hh-template
https://github.com/chaineasy/hh-template
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/chaineasy/hh-template
- Owner: ChainEasy
- License: gpl-3.0
- Created: 2023-08-16T19:06:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-16T16:08:09.000Z (over 1 year ago)
- Last Synced: 2025-01-09T03:45:17.315Z (5 months ago)
- Language: TypeScript
- Size: 951 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hardhat Template - _by [DeFiFoFum](https://github.com/defifofum)_
[](https://github.com/DeFiFoFum/hardhat-template/actions/workflows/lint-test.yml)
[](./docs/)
[](https://www.gnu.org/licenses/gpl-3.0)Solidity Smart Contract development template using modern Web3 frameworks/tools including Hardhat, Typechain and more.
## Features
- Contract Support
- [OpenZeppelin Contracts](https://docs.openzeppelin.com/contracts/): Trusted smart contract standards
- [Openzeppelin Contracts Upgradeable](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable): Upgradeable smart contract support
- Typescript
- [Typechain](https://www.npmjs.com/package/typechain): Generate smart contract typings for Ethers during
- Docs
- [Hardhat Docgen](https://www.npmjs.com/package/hardhat-docgen): Generate a static documentation site from NatSpec comments automatically on compilation with Hardhat.
compilation.
- Testing
- [VS-Code Mocha Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter): Use Mocha Test Explorer to easily choose which tests to run. (Smart Contracts must be manually compiled between updates.)
- Debug Solidity unit tests with [VS-Code debugger](https://code.visualstudio.com/docs/editor/debugging)
- [solidity-coverage](https://www.npmjs.com/package/solidity-coverage): Generate a coverage report by running `yarn test:coverage`
- [hardhat-gas-reporter](https://www.npmjs.com/package/hardhat-gas-reporter): Check the gas costs of running test transactions with `yarn test:gas`
- _these tests run slower than `yarn test`_
- [hardhat-contract-sizer](https://www.npmjs.com/package/hardhat-contract-sizer): Check the size of the contracts being developed with `yarn size`
- **Fork Testing**: This repo has support for forking networks and running tests against the forked network. Update [hardhat-fork.config.ts](./hardhat-fork.config.ts) with the network you want to fork and run `yarn test:fork` to run tests against the forked network with the tests in [test-fork](./test-fork).
- TX Simulations
- [Tenderly Simulation API](https://docs.tenderly.co/simulations-and-forks/simulation-api): This repo has support for sending TX data to the simulator API for debugging and simulation.
- Linting
- [Prettier](https://prettier.io/): Most popular opinionated code formatter.
- [Prettier Config](https://prettier.io/docs/en/configuration.html)
- [Prettier Solidity plugin](https://www.npmjs.com/package/prettier-plugin-solidity): A Prettier plugin for automatically formatting your Solidity code.
- [Solhint](https://www.npmjs.com/package/solhint): Open source project for linting Solidity code. This project provides both Security and Style Guide validations.
- [solhint.config.ts](./solhint.config.js) is full featured and support Solidity style guide recommendations.
- [Hardhat Contract Sizer](https://www.npmjs.com/package/hardhat-contract-sizer)
- [Build/Publish as NPM Package](#buildpublish-as-npm-package): This repo is setup to build important files into a publishable NPM package. (See below for more info)## Deployment and Verification
This project uses special tasks, adapted from Balancer protocol, to deploy and verify contracts which provides methods for saving custom outputs and easily verifying contracts as well as compartmentalizing different types of deployments.
### Configuration
- Copy [.env.example](./.env.example) and rename to `.env`
- Provide the necessary `env` variables before deployment/verification
- `_MNEMONIC` for deployments
- `_API_KEY` for verifications
- [hardhat.config.ts](./hardhat.config.ts): Can be configured with additional networks if needed
- [hardhat/types.ts](./hardhat/types.ts): Holds network typings which can be updated with more networks.
- Configure Deployment Variables for each network in [deploy.config.ts](./scripts/deploy/deploy.config.ts).
- Ensure Etherscan API Keys are configured in [hardhat.config.ts](./hardhat.config.ts) under `etherscan`.## Deployment & Verification
1. Create a deployment script in [scripts/deploy](./scripts/deploy/). (Use [deployLock](./scripts/deploy/deployLock.ts) as a template.)
2. Use [DeployManager](./scripts/deploy/DeployManager.ts) to deploy contracts to easily deploy, verify and save the output to the [deployments](./deployments/) directory.
3. Run a deployment with `npx hardhat run ./scripts/deploy/deployLock.ts --network `
4. Etherscan-like API key should be stored in [hardhat.config.ts](./hardhat.config.ts) under `etherscan` and the [DeployManager](./scripts/deploy/DeployManager.ts) can use that to verify contracts after deployment.## Linting
This project uses Prettier, an opinionated code formatter, to keep code styles consistent. This project has additional plugins for Solidity support as well.
- `yarn lint`: Check Solidity files & TS/JS files
- `yarn lint:fix`: Fix Solidity files & TS/JS files### Linting Solidity Code
- [prettier.config.js](./prettier.config.js): Provide config settings for Solidity under `overrides`.
- [.solhint.json](./.solhint.json): Provide config settings for `solhint`.- `yarn lint:sol`: Check Solidity files
- `yarn lint:sol:fix`: Fix Solidity files## Build/Publish as NPM Package
1. Currently this repo uses `tsc` to build files to `dist/`.
2. Files are cherry picked in [package.json](./package.json) under `files` as there are a lot of support files included in this repo._Consider including only what is needed._
```json
"files": [
"dist/index.js",
"dist/index.d.ts",
"dist/src/**/*",
"dist/typechain-types/**/*",
// "dist/artifacts/**/*"
],
```## Gotchas
1. Put single quotes around globs in `package.json`:
- `"lint:ts": "prettier --check './{scripts,tasks,src,hardhat,test}/**/*.ts'"`