A Hardhat-based template for developing Solidity smart contracts, with sensible defaults.
- Hardhat: compile, run and test smart contracts
- TypeChain: generate TypeScript bindings for smart contracts
- Ethers: renowned Ethereum library and wallet implementation
- Solhint: code linter
- Hardhat coverage: native code coverage
- Prettier Plugin Solidity: code formatter
Click the Use this template button at the top of the page to
create a new repository with this repo as the initial state.
This template builds upon the frameworks and libraries mentioned above, so for details about their specific features, please consult their respective documentations.
For example, for Hardhat, you can refer to the Hardhat Tutorial and the Hardhat Docs. You might be in particular interested in reading the Testing Contracts section.
This template comes with sensible default configurations in the following files:
├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── eslint.config.mjs
├── hardhat.config.ts
└── rocketh/config.ts
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic Foundation's Solidity extension.
This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
request made to the main branch.
Note that by default, the CI uses test values for MNEMONIC and INFURA_API_KEY. If you want to use your own values,
you can set them as GitHub secrets.
For more information on how to set up GitHub secrets, check out the docs.
You can edit the CI script in .github/workflows/ci.yml.
Use a supported even-numbered Node.js release, at least 22.13.0 (CI uses Node.js 24), and Bun. Install the dependencies:
bun installLocal compilation, tests and simulated deployments work without credentials. The local network uses Hardhat's public
test mnemonic by default. Set MNEMONIC to use different local accounts.
For remote networks, provide MNEMONIC and, for Infura-backed networks, INFURA_API_KEY through environment variables
or the Hardhat keystore. For example:
bunx hardhat keystore set MNEMONIC
bunx hardhat keystore set INFURA_API_KEYSet ETHERSCAN_API_KEY when verifying contracts. Configuration variables resolve only when the selected operation needs
them.
See AGENTS.md for contributor guidance and toolchain constraints.
Compile the smart contracts with Hardhat:
bun run compileCompile the smart contracts and generate TypeChain bindings:
bun run typechainRun the tests with Hardhat:
bun run testLint the Solidity code:
bun run lint:solLint the TypeScript code:
bun run lint:tsGenerate the native code coverage report in coverage/html/index.html:
bun run coverageSee the gas usage per unit test and average gas per method call:
bun run test --gas-statsClear the smart contract artifacts, coverage reports and Hardhat cache, then rebuild the contracts and TypeChain bindings:
bun run cleanDeploy the contracts to the temporary simulated Hardhat network with hardhat-deploy and Rocketh:
bun run deploy:contractsNamed accounts and deployment extensions live in rocketh/config.ts. Deployment scripts live in deploy/. To persist
contracts on a running local node or deploy remotely, pass --network localhost or the configured network name.
Deploy a new instance of the Lock contract via a task:
bun run task:deployLock --unlock 100 --value 0.1Withdraw from a deployed Lock after its unlock time:
bun run task:withdraw --network localhost --account 0 --address <lock-address>Omit --address to use the saved Lock deployment for the selected network.
If you use VSCode, you can get Solidity syntax highlighting with the hardhat-solidity extension.
GitPod is an open-source developer platform for remote development.
To view the coverage report generated by bun run coverage, just click Go Live from the status bar to turn the server
on/off.
Start a persistent Hardhat node:
bunx hardhat nodeIn another terminal, deploy to that node:
bun run deploy:contracts --network localhostUse --network localhost for subsequent tasks so they connect to the same chain. The default network creates a
temporary chain for each command.
This project is licensed under MIT.