Hardhat plugin for verifying smart contracts on Etherscan and other block explorers with multi-network support
npx @tessl/cli install tessl/npm-nomiclabs--hardhat-etherscan@3.1.0The @nomiclabs/hardhat-etherscan plugin provides seamless smart contract verification on Etherscan and other block explorers. It intelligently detects contracts, handles constructor arguments, manages library dependencies, and supports multiple blockchain networks with automated verification workflows.
npm install --save-dev @nomiclabs/hardhat-etherscanimport "@nomiclabs/hardhat-etherscan";The plugin extends Hardhat through side effects when imported, adding the verify task and configuration options.
// hardhat.config.ts
import "@nomiclabs/hardhat-etherscan";
export default {
// ... other config
etherscan: {
apiKey: "YOUR_ETHERSCAN_API_KEY"
}
};# Verify a deployed contract
npx hardhat verify --network mainnet 0x1234567890123456789012345678901234567890 "constructor arg 1" "constructor arg 2"
# List supported networks
npx hardhat verify --list-networksThe plugin integrates with Hardhat's task system and provides:
verify task with multiple specialized subtasks for verification workflowetherscan field for API keys and custom chainsCore contract verification functionality that submits source code to block explorers for public verification and audit.
// Task: verify
interface VerifyTaskArgs {
address?: string;
constructorArgsParams: string[];
constructorArgs?: string;
contract?: string;
libraries?: string;
listNetworks: boolean;
noCompile: boolean;
}Configuration system for API keys, custom networks, and verification settings across multiple blockchain networks.
interface EtherscanConfig {
apiKey?: string | Record<string, string>;
customChains: CustomChain[];
}
interface CustomChain {
network: string;
chainId: number;
urls: EtherscanURLs;
}
interface EtherscanURLs {
apiURL: string;
browserURL: string;
}Built-in support for major blockchain networks and block explorers, with the ability to add custom networks.
interface EtherscanNetworkEntry {
network: string;
urls: EtherscanURLs;
}
type ChainConfig = Record<string, EtherscanChainConfig>;Processing and encoding of constructor arguments for contract verification, supporting both inline arguments and file-based argument modules.
function encodeArguments(
abi: any,
sourceName: string,
contractName: string,
constructorArguments: any[]
): Promise<string>;Management and linking of Solidity libraries used by contracts during verification, with automatic library address detection.
interface Libraries {
[sourceName: string]: {
[libraryName: string]: string;
};
}
interface LibraryNames {
sourceName: string;
libName: string;
}interface EtherscanUserConfig {
apiKey?: string | Record<string, string>;
customChains?: CustomChain[];
}
interface EtherscanChainConfig {
chainId: number;
urls: EtherscanURLs;
}
interface ContractInformation {
compilerInput: CompilerInput;
compilerOutput: CompilerOutput;
solcVersion: string;
sourceName: string;
contractName: string;
contract: CompilerOutput["contracts"][string][string];
libraryLinks: ResolvedLinks;
undetectableLibraries: LibraryNames[];
}
interface ResolvedLinks {
[sourceName: string]: {
[libraryName: string]: string;
};
}
// Metadata analysis constants
const METADATA_LENGTH_SIZE: 2;
const METADATA_PRESENT_SOLC_NOT_FOUND_VERSION_RANGE: "0.4.7 - 0.5.8";
const METADATA_ABSENT_VERSION_RANGE: "<0.4.7";