Skip to content
Public template

About

Hardhat-based template for developing Solidity smart contracts

Topics

Resources

Stars

2.0k stars

Watchers

32 watching

Forks

Repository files navigation

Hardhat Template Open in Gitpod Github Actions Hardhat License: MIT

A Hardhat-based template for developing Solidity smart contracts, with sensible defaults.

Getting Started

Click the Use this template button at the top of the page to create a new repository with this repo as the initial state.

Features

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.

Sensible Defaults

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

VSCode Integration

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.

GitHub Actions

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.

Usage

Prerequisites

Use a supported even-numbered Node.js release, at least 22.13.0 (CI uses Node.js 24), and Bun. Install the dependencies:

bun install

Local 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_KEY

Set 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

Compile the smart contracts with Hardhat:

bun run compile

TypeChain

Compile the smart contracts and generate TypeChain bindings:

bun run typechain

Test

Run the tests with Hardhat:

bun run test

Lint Solidity

Lint the Solidity code:

bun run lint:sol

Lint TypeScript

Lint the TypeScript code:

bun run lint:ts

Coverage

Generate the native code coverage report in coverage/html/index.html:

bun run coverage

Report Gas

See the gas usage per unit test and average gas per method call:

bun run test --gas-stats

Clean

Clear the smart contract artifacts, coverage reports and Hardhat cache, then rebuild the contracts and TypeChain bindings:

bun run clean

Deploy

Deploy the contracts to the temporary simulated Hardhat network with hardhat-deploy and Rocketh:

bun run deploy:contracts

Named 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.

Tasks

Deploy Lock

Deploy a new instance of the Lock contract via a task:

bun run task:deployLock --unlock 100 --value 0.1

Withdraw

Withdraw 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.

Syntax Highlighting

If you use VSCode, you can get Solidity syntax highlighting with the hardhat-solidity extension.

Using GitPod

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.

Local development

Start a persistent Hardhat node:

bunx hardhat node

In another terminal, deploy to that node:

bun run deploy:contracts --network localhost

Use --network localhost for subsequent tasks so they connect to the same chain. The default network creates a temporary chain for each command.

License

This project is licensed under MIT.

About

Hardhat-based template for developing Solidity smart contracts

Topics

Resources

Stars

2.0k stars

Watchers

32 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages