Claude Skills Guide

Claude Code for Hardhat Plugins Workflow

Hardhat is the go-to development environment for Ethereum developers, and its plugin ecosystem is one of its strongest features. Whether you’re deploying contracts, running tests, or verifying source code on Etherscan, Hardhat plugins automate repetitive tasks. Claude Code can help you discover, configure, debug, and even build custom Hardhat plugins faster than ever.

This guide shows you how to integrate Claude Code into your Hardhat workflow for maximum productivity.

Setting Up Hardhat with Claude Code

Before diving into plugin workflows, ensure your Hardhat project is ready for Claude Code assistance. Initialize a new project if needed:

npx hardhat init my-hardhat-project
cd my-hardhat-project

When working with Claude Code in a Hardhat project, provide context about your setup. Tell Claude which plugins you’re using by sharing your hardhat.config.js or hardhat.config.ts file. This helps Claude understand your environment and provide relevant suggestions.

For example, you might say:

“I’m working on a Hardhat project with hardhat-deploy and hardhat-etherscan plugins. Help me set up automated contract verification.”

Claude Code will then reference your configuration and guide you through the setup process.

Common Hardhat Plugins and How Claude Code Helps

Hardhat-Etherscan for Contract Verification

The hardhat-etherscan plugin automates source code verification on Etherscan. Here’s a typical workflow where Claude Code assists:

  1. Configuration: Add your Etherscan API key to hardhat.config.js
  2. Verification: Run npx hardhat verify --network mainnet DEPLOYED_ADDRESS

Claude Code can help you write deployment scripts that automatically verify contracts after deployment:

// deploy.js - Example with automatic verification
async function main() {
  const contract = await deploy("MyContract", {
    from: deployer,
    args: [constructorArg1, constructorArg2],
    log: true,
  });

  // Only verify on mainnet
  if (network.config.chainId === 1) {
    await run("verify:verify", {
      address: contract.address,
      constructorArguments: [constructorArg1, constructorArg2],
    });
  }
}

Ask Claude Code to generate this pattern for you, or explain how to structure your deployment files for automatic verification across networks.

Hardhat-Gas-Reporter for Cost Optimization

The hardhat-gas-reporter plugin tracks gas usage across contract function calls. After installation:

npm install hardhat-gas-reporter --save-dev

Add it to your hardhat.config.js:

gasReporter: {
  enabled: true,
  currency: "USD",
  coinmarketcap: process.env.COINMARKETCAP_API_KEY,
  token: "ETH",
  gasPriceApi: "https://api.etherscan.io/api?module=proxy&action=eth_gasPrice",
}

When you run tests with npx hardhat test, you’ll see gas reports. Claude Code can help you interpret these reports, identify functions with unexpectedly high gas costs, and suggest optimization strategies.

Hardhat-Coverage for Test Coverage

Test coverage is critical for smart contract security. The hardhat-coverage plugin integrates with your existing test suite:

npm install --save-dev solidity-coverage

Run coverage with:

npx hardhat coverage

Claude Code can help you analyze coverage reports, identify untested code paths, and generate additional test cases to improve coverage.

Building Custom Hardhat Plugins

When existing plugins don’t meet your needs, you can build custom Hardhat plugins. Claude Code is excellent for this task.

Plugin Structure

A basic Hardhat plugin follows this structure:

// plugins/custom-hardhat-plugin/index.js
import { extendConfig } from "hardhat/config";
import { task } from "hardhat/config";

extendConfig((config, userConfig) => {
  // Extend the Hardhat configuration
});

task("my-custom-task", "Description of what the task does")
  .addParam("param1", "Description of parameter")
  .setAction(async (taskArgs, hre) => {
    // Your task logic here
    console.log(`Running with param1: ${taskArgs.param1}`);
  });

Ask Claude Code for Help

When building custom plugins, describe what you need:

“Create a Hardhat plugin that deploys a contract to multiple networks in parallel and saves deployment addresses to a JSON file.”

Claude Code can generate the plugin structure, implement the parallel deployment logic, and handle error cases.

Testing Hardhat Plugins

Proper testing ensures your plugins work correctly. Hardhat provides a testing environment through hardhat-runtime-environment.

const { expect } = require("chai");

describe("Custom Plugin", function () {
  it("should execute custom task", async function () {
    const result = await hre.run("my-custom-task", {
      param1: "test-value",
    });
    expect(result).to.equal("expected-result");
  });
});

Claude Code can help you write comprehensive tests for your plugins, including edge cases and error conditions.

Debugging Hardhat Issues

When Hardhat tasks fail, debugging can be challenging. Here’s how Claude Code helps:

  1. Share error messages: Paste the full error output
  2. Provide context: Show your configuration and relevant code
  3. Ask specific questions: “Why is my etherscan verification failing with ‘Already Verified’?”

Example debugging session:

“I’m getting ‘Transaction reverted without a reason string’ when running my deployment script. Here’s my contract code and the relevant deployment line.”

Claude Code can help you identify common issues like gas estimation failures, constructor argument mismatches, and network configuration problems.

Automating Repetitive Tasks

Many Hardhat workflows involve repetitive steps. Claude Code can help you create task chains or scripts.

For example, a typical workflow might be:

  1. Compile contracts: npx hardhat compile
  2. Run tests: npx hardhat test
  3. Deploy to testnet: npx hardhat run scripts/deploy.js --network sepolia
  4. Verify on Etherscan: npx hardhat verify --network sepolia ADDRESS

Claude Code can combine these into a single script or create a custom Hardhat task:

task("full-deploy", "Compile, test, deploy, and verify")
  .addOptionalParam("network", "Network to deploy to", "sepolia")
  .setAction(async (taskArgs, hre) => {
    await run("compile");
    await run("test");
    const { address } = await run("deploy", { network: taskArgs.network });
    await run("verify", { address, network: taskArgs.network });
  });

Best Practices for Claude Code with Hardhat

  1. Share your configuration: Always share your hardhat.config.js for relevant context
  2. Specify network details: Mention which networks you’re working with (mainnet, testnets, local)
  3. Include plugin versions: Some plugins have breaking changes between versions
  4. Use .claude.md files: Add Hardhat-specific instructions to your project

Create a .claude.md file in your project root:

# Project Context
- This is a Hardhat project with hardhat-deploy and hardhat-etherscan
- Contracts are in /contracts
- Deployment scripts are in /deploy
- Use npm for package management

# Common Tasks
- Deploy: npx hardhat deploy --network $NETWORK
- Test: npx hardhat test
- Verify: npx hardhat verify --network $NETWORK $ADDRESS

This ensures Claude Code always has context about your Hardhat setup.

Conclusion

Claude Code significantly enhances your Hardhat development workflow. From configuring popular plugins like etherscan and gas-reporter to building custom plugins and debugging issues, Claude Code serves as an intelligent assistant throughout the process. By sharing your project configuration and following the practices outlined in this guide, you can automate repetitive tasks, write better tests, and deploy more reliable smart contracts.

Start by adding your Hardhat configuration to Claude Code’s context, then iterate on your workflow from there.

Built by theluckystrike — More at zovo.one