Hardhat etherscan verification
Skill Solonnikov/agent-skills/skills/hardhat-etherscan-verification
Public collection of agent skills — reusable capabilities, prompts, and workflows for Claude Code and other agentic coding tools.
npx -y skills add Solonnikov/agent-skills --skill hardhat-etherscan-verificationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Verifies a deployed Solidity contract on Etherscan (or any Etherscan-compatible explorer) via Hardhat's hardhat-verify plugin, with a manual Etherscan V2 API fallback for cases where the plugin fails. Use when a contract deploy needs verification, when automated verify fails with ABI/constructor/linking errors, or when a contract is flattened or uses custom compiler settings.
SKILL.md
4.4 KB, as published. Nobody here has run it
Hardhat Etherscan Verification
Verify deployed contracts on Etherscan-compatible explorers. Handles the common case with the built-in plugin, and the painful edge cases via direct V2 API submission.
When to use
- After deploying a contract and needing it verified on Etherscan, BaseScan, Arbiscan, PolygonScan, Optimism Etherscan, etc.
- When
npx hardhat verifyfails with obscure errors (constructor mismatch, bytecode mismatch, compiler version). - For contracts you flattened before deploy (
hardhat flatten), which the standard plugin handles poorly. - For custom chains not in the built-in Hardhat config.
Before you start
Collect:
- Deployed contract address and the chain it's on.
- Constructor arguments — the exact values passed when deploying.
- Compiler version and optimizer settings used at deploy time. These must match bit-for-bit what you're submitting.
- API key for the explorer (Etherscan, BaseScan, PolygonScan, etc.). Get one at the explorer's
my/apikeypage. - Source files — either the full
contracts/tree, or a single flattened file.
Workflow — automated path (hardhat-verify plugin)
- Install and configure:
npm i -D @nomicfoundation/hardhat-verify, import inhardhat.config.ts, add API keys per chain. - Run:
npx hardhat verify --network <net> <ADDRESS> "<arg1>" "<arg2>". - If it succeeds, you're done. Most of the time, it does.
See automated-verify.md for config and common flags.
Workflow — manual fallback (V2 API)
When the plugin fails, drop to the Etherscan V2 API directly. Use when:
- Plugin returns "bytecode does not match" despite correct compiler settings.
- Contract was deployed from a flattened source.
- Contract uses libraries or linked references that confuse the plugin.
- Explorer is a custom/new chain not supported by the plugin.
- Flatten source (
npx hardhat flatten) — produces a single.solwith all imports inlined. - Strip duplicate
SPDX-License-Identifierandpragmalines that flatten emits (they break V2 parsing). - ABI-encode constructor args with
cast abi-encodeor an equivalent. - POST to
https://api.etherscan.io/v2/api?chainid=<CHAIN>withaction=verifysourcecode, the flattened source, compiler version, optimizer runs, and encoded args. - Poll
action=checkverifystatuswith the returned GUID every ~15 seconds until success or failure.
See manual-v2-api.md for the full POST body, field reference, and a TypeScript script.
Non-negotiable rules
- Compiler version match is exact.
0.8.24≠0.8.25.optimizer=true, runs=200≠optimizer=true, runs=1000. The deploy config and the verify submission must match down to each byte of metadata. - Constructor args are the #1 cause of "bytecode mismatch." Print the exact values you deployed with and pass them identically. ABI-encode with the contract's constructor signature, not a guess.
- Pin the explorer URL per chain.
api.etherscan.iois Ethereum mainnet/Sepolia.api.basescan.org,api.arbiscan.io,api.polygonscan.comare separate hosts — using the wrong one returns "OK" but never verifies. - Never commit your explorer API key. Use
.env; include a.env.examplewith the var name. - Don't re-flatten between deploy and verify. If you flattened before deploy, verify the exact flattened file you deployed from. Re-flattening produces slightly different output (comment ordering, whitespace) and fails the match.
References
- Automated verify (plugin path) —
@nomicfoundation/hardhat-verifyconfig, per-chain API keys, common flags and flags-that-lie. - Manual V2 API fallback — field-by-field walk-through of the POST body, a TypeScript submission script, and the polling loop.
- Troubleshooting — "bytecode mismatch" decoded, constructor arg gotchas, library linking, chain-specific weirdness.