Installation Guide
solidity-coverage
is designed to be used as a development dependency in a Hardhat project.
Requirements
- Hardhat: Version
2.11.0
or higher.
Steps
-
Install the package:
Navigate to your project's root directory and run the following command to add
solidity-coverage
to yourdevDependencies
:yarn add solidity-coverage --dev
Or using npm:
npm install solidity-coverage --save-dev
-
Add the plugin to your Hardhat configuration:
You need to load the plugin in your
hardhat.config.js
orhardhat.config.ts
file.For JavaScript (
hardhat.config.js
):require('solidity-coverage'); module.exports = { solidity: "0.8.24", // ... rest of your config };
For TypeScript (
hardhat.config.ts
):import 'solidity-coverage'; import { HardhatUserConfig } from "hardhat/config"; const config: HardhatUserConfig = { solidity: "0.8.24", // ... rest of your config }; export default config;
Important Note for Older Users
Versions of solidity-coverage
from 0.7.0
onwards are designed as plugins for development frameworks like Hardhat. It is no longer a standalone shell command.
If you attempt to run it directly from the command line, you will see the following message:
⚠️ solidity-coverage >= 0.7.0 is no longer a shell command. ⚠️
=============================================================
Instead, you should use the plugin produced for your development stack
(like Hardhat) or design a custom workflow using the package API
> See https://github.com/sc-forks/solidity-coverage for help with configuration.
Thanks! - sc-forks
You should now use the command provided by the Hardhat plugin, as described in the Quick Start guide.