Hardhat development boilerplate that enables to:
- Deploy to multiple networks
- Run tests with
hardhat-chai-matchers
against local and test networks - Analyze coverage and gas ussage of our contracts
- Verify contracts source code on etherscan
- Use typescript on contract instances
- Solidity
- Hardhat
- hardhat-deploy
- hardhat-toolbox
- hardhat-ethers
- hardhat-etherscan
- hardhat-chai-matchers
- hardhat-network-helpers
- solidity-gas-reporter
- typechain
- solidity-coverage
- Openzeppelin Contracts
- Typescript
.
├── contracts/
├── deploy/
├── deployments
├── tasks
├── typechain-types
├── utils
├── test
├── hardhat.config.ts
├── helper-hardhat-config.ts
- contracts: where contracts are placed
- deploy:
hardhat-deploy
scripts to deploy to localhost, testnet and mainnet. The scripts also verifies contract source code toetherscan
- deployment: information about old deploys and ABI, generated by
hardhat-deploy
- tasks: hardhat tasks to interact with the example contracts after its deployed to a network
- typechain-types: types definitions for each contract generated by
typechain
- utils: verify sourcecode against
etherscan
- test: unit and staging tests.
- hardhat.config.ts: hardhat configuration file. Currenlty supports
ethereum
andpolygon
networks configuration. - helper-hardhat-config.ts: helper file containing information per network, like # of confirmations, Chainlink smart contract addresses and subscriptions.
- Copy
.env.example
to.env
- Fullfil the following properties:
GOERLI_URL=[INFURA OR ALCHEMY RPC URL]
MUAMBAI_URL=[INFURA OR ALCHEMY RPC URL] // Optional: for polygon deployment
PRIVATE_KEY=[DEPLOYER_PRIVATE_KEY]
PRIVATE_KEY_2=[ANOTHER_ACCOUNT_PRIVATE_KEY] // Optional
REPORT_GAS=true
ETHERSCAN_API_KEY=[YOUR_ETHERSCAN_API_KEY]
VERIFY_CONTRACT=false
COINMARKETCAP_API_KEY=[YOUR_COINMARKETCAP_API_KEY] // Optional: only needed by hardhat-gas-reporter.
yarn install
(we recommend using yarn over npm because resolves theethers
dependency correctly when usinghardhat-deploy
)
- Deploy to localhost
yarn run deploy
- Deploy to ethereum testnet
yarn run deploy-goerli
- Deploy to polygon testnet
yarn run deploy-muambai
Tests are separated between unit
and staging
tests.
unit
tests are for testing contracts public API on hardhat network; meanwhile staging
tests are for running on testnet. The staging example provided also deploys the contract on each test suite execution.
- Unit:
yarn run test
- Staging:
yarn run test-staging
- Coverage:
yarn run coverage
This boilerplate uses typechain
capabilties to prevent errors and ensure correct behaviour, therefore types should be generated:
yarn run types
yarn run format
yarn run lint
Boilerplate comes with some example tasks:
-
Get balance of an address:
npx hardhat balance-of --tokenaddress 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --network localhost
-
Transfer tokens:
npx hardhat transfer --tokenaddress 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --account 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --amount 0.1 --network localhost
-
Pledge a campaign:
npx hardhat pledge --goal 1 --campaign-id 5 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost
-
Refund a campaign:
npx hardhat refund --campaign-id 1 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost
-
Cancel a campaign:
npx hardhat cancel --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --campaign-id 1
-
Claim funds:
npx hardhat claim --campaign-id 2 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost
-
Launch a campaign:
npx hardhat launch --goal 10 --start 1668864785 --end 1668864966 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost
-
Account allowance:
npx hardhat allowance --amount 100 --tokenaddress 0x5FbDB2315678afecb367f032d93F642f64180aa3 --account 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost
In order to run them, a contract deploy must be done. Open two consoles and:
- Run
yarn hardhat node
on first one - Run
yarn hardhat deploy --network localhost
on the second one
You can execute tasks on the second terminal and see the transactions on the first one.
Each PR made to gitflow standard branches will execute the unit tests using Github Actions.
Configuration can be found at .github/workflows/tests.yml
- Install slither
yarn run slither
Contributions are always welcome. Please open a PR or an issue.