or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdconstructor-arguments.mdindex.mdlibraries.mdnetworks.mdverification.md
tile.json

tessl/npm-nomiclabs--hardhat-etherscan

Hardhat plugin for verifying smart contracts on Etherscan and other block explorers with multi-network support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nomiclabs/hardhat-etherscan@3.1.x

To install, run

npx @tessl/cli install tessl/npm-nomiclabs--hardhat-etherscan@3.1.0

index.mddocs/

Hardhat Etherscan Plugin

The @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.

Package Information

  • Package Name: @nomiclabs/hardhat-etherscan
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev @nomiclabs/hardhat-etherscan

Core Imports

import "@nomiclabs/hardhat-etherscan";

The plugin extends Hardhat through side effects when imported, adding the verify task and configuration options.

Basic Usage

// 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-networks

Architecture

The plugin integrates with Hardhat's task system and provides:

  • Task System: Main verify task with multiple specialized subtasks for verification workflow
  • Configuration Extension: Extends Hardhat config with etherscan field for API keys and custom chains
  • Network Detection: Automatic detection of block explorer endpoints based on chain ID
  • Bytecode Analysis: Intelligent contract matching using deployed bytecode comparison
  • Multi-Network Support: Built-in support for 20+ blockchain networks and explorers

Capabilities

Contract Verification

Core 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;
}

Contract Verification

Configuration Management

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;
}

Configuration

Network Support

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>;

Network Support

Constructor Arguments Processing

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>;

Constructor Arguments

Library Management

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;
}

Library Management

Types

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";