🛑 DEPRECATED in place of DeFiFoFum/hardhat-template
Use this as a hardhat/truffle template to start rapid smart contract development using typescript and other mind blowing features.
Truffle Framework and HardHat are both solidity smart contract development frameworks in which developers normally choose one over the other. Hardhat is generally the framework of choice for modern solidity development, but Truffle has a very helpful plugin, truffle-plugin-verify for quickly verifying contracts after deployment. While Hardhat has a tool for this, it still requires much more effort to verify complex projects after deployment.
Because truffle-plugin-verify
uses the Truffle artifacts after deployment, we need to use truffle for deploying and verifying.
Hardhat fills in all of the other needed tools for rapid development including typescript support and broad spectrum of plugins which make testing and UI integration easier.
- Deploy Contracts
- Verify Contracts
- Testing
- Gas Reporting
- Generate Contract Types
- Run Scripts
- UI Integration Support
Configuration
The deploy.config.ts acts at the parent configuration file for the project.
- Setup Solidity compiler options
- Add networks
- Add deployment variables which can be returned based on deployment network
The main configuration file above is processed inside the configuration files of Hardhat and Truffle.
- hardhat.config.ts
- Add Hardhat tasks
- truffle-config.js
- Set
confirmations
- Set
timeoutBlocks
- Set
skipDryRun
- Set
Tests and Scripts: Use typescript to write smart contract tests and scripts.
Integration: Using Typechain and hardhat plugins, smart contract types are generated to integrate with the contracts through ethers.
Use typechain to create typescript declaration files for typed contract interactions.
yarn compile || yarn compile:force
When contracts are compiled, typescript declarations are generated in typechain/.
yarn test
Mocha: This repo uses mocha as the main testing framework
Use vscode-mocha-test-adapter to run individual unit tests.
Make sure to set the vscode option to "mochaExplorer.files"
to "test/**/*.{j,t}s"
more info
Chai: The mocha tests use the chai assertion library.
Use solidity-coverage to generate a smart contract coverage report based on current test suite.
yarn coverage
Use hardhat-gas-reporter to generate a contract function gas/cost estimator.
yarn test:gas
Contracts located in the contracts/ directory will be compiled using the solidity
version in the solidity.config file.
Depending on the need, contracts can be compiled with Hardhat or Truffle:
Hardhat
yarn compile
|| yarn compile --force
Truffle
yarn compile:truffle
|| yarn compile:truffle --all
After defining the network configuration as needed in solidity.config, you can deploy using one of the following commands:
# Deploy locally
yarn testrpc
yarn deploy:dev
# Deploy to specific network
yarn deploy:bsc
yarn deploy:bsc-testnet
yarn deploy:polygon
yarn deploy:polygon-testnet
Configuration
Make sure to provide your network specific API key in a .env
file. See .env.example for examples.
yarn verify:bsc
yarn verify:bsc-testnet
yarn verify:polygon
yarn verify:polygon-testnet
If new contracts are added, the verification scripts need to be updated in package.json
Use hardhat's built in blockchain node to run tests locally.
yarn testrpc
Eslint, prettier and solhint are provided to provide TS and Solidity code linting/fixing.
yarn eslint
yarn eslint:fix
yarn prettier
yarn prettier:fix
yarn solhint
yarn solhint:fix
yarn lint # Run all linters
yarn lint:fix # Run all fixes