乐闻世界logo
搜索文章和话题

What are the common Hardhat plugins and their uses?

2月21日 15:58

Hardhat's plugin system greatly extends its functionality. Here are common plugins and their uses:

Core Plugins:

  1. @nomicfoundation/hardhat-toolbox

    • Integrates multiple commonly used plugins
    • Includes Ethers.js, Chai, Waffle, Etherscan, Hardhat Ignition, etc.
    • Suitable for quickly starting projects
  2. hardhat-gas-reporter

    • Generates gas usage reports
    • Helps optimize contract gas consumption
    • Supports displaying gas costs in multiple currencies
  3. @nomiclabs/hardhat-etherscan

    • Automatically verifies contracts on Etherscan
    • Supports multi-network verification
    • Simplifies contract verification process
  4. hardhat-abi-exporter

    • Exports contract ABIs to JSON files
    • Facilitates frontend integration
    • Supports custom export formats

Development Helper Plugins:

  1. hardhat-contract-sizer

    • Analyzes contract size
    • Detects if exceeding 24KB limit
    • Helps optimize contract code
  2. hardhat-deploy

    • Provides advanced deployment features
    • Supports contract upgrades
    • Saves deployment history
  3. hardhat-ethers

    • Provides Ethers.js integration
    • Enhanced contract interaction
    • Type-safe contract calls

Security Plugins:

  1. hardhat-ethcan

    • Security vulnerability detection
    • Common attack pattern recognition
    • Code quality checking
  2. hardhat-spdx-license-checker

    • Checks SPDX license identifiers
    • Ensures compliance
    • Automatically adds licenses

Installation and Usage:

javascript
// Install plugin npm install --save-dev hardhat-gas-reporter // Import in hardhat.config.js require("hardhat-gas-reporter"); // Configure plugin gasReporter: { enabled: true, currency: "USD" }

Plugin Development: Hardhat supports custom plugin development, which can extend tasks, environments, configurations, and other features to meet specific project needs.

标签:Hardhat