Migrate with an AI agent
If you use an AI coding agent, our Hardhat 2 to Hardhat 3 migration skill allows it to perform a structured migration of your project.
Install the skill
Section titled “Install the skill”Install the skill in your project:
npx skills add nomicfoundation/hardhat-skills --skill migrate-hardhat2-to-hardhat3pnpm dlx skills add nomicfoundation/hardhat-skills --skill migrate-hardhat2-to-hardhat3yarn dlx skills add nomicfoundation/hardhat-skills --skill migrate-hardhat2-to-hardhat3This launches an interactive CLI that will walk you through installing the migration skill for your agent. For instance, you can choose to install into your current project (rather than globally) and specifically for Claude, which writes the skill files into .claude/skills/ at the repository root.
Run the migration
Section titled “Run the migration”Open your project in your coding agent and ask it to migrate to Hardhat 3, for example:
Migrate this project from Hardhat 2 to Hardhat 3 using the Hardhat migration skill.
For Claude you can invoke the migration as a command with:
/migrate-hardhat2-to-hardhat3The agent will use the skill to start a campaign to migrate the repo to Hardhat 3. The migration will proceed step by step, pausing for review after each:
- Project setup —
tsconfig.jsonfor ESM and thepackage.jsonHardhat 2 to Hardhat 3 dependency swap. - Config — rewrite
hardhat.config.tsto the declarativedefineConfig(plugins, networks, tasks, solidity, verify etc). - Solidity tests — migrate
.t.solfiles to Hardhat 3 conventions. - Source files — convert
.ts/.jssources CJS to ESM and update Hardhat 2 APIs to Hardhat 3 (plus TypeChain import fixes). - Test fix-up — get the TypeScript test suite passing under Hardhat 3.
- Script validation — run and fix the
package.jsonscripts you select.
Review the result
Section titled “Review the result”The skill automates the migration, but you should still review the changes and verify your core development workflows are correct, for example:
npx hardhat buildnpx hardhat testFurther manual migration may be necessary for additional workflows e.g. CI, deployment, specialist scripts etc.