0
# Hardhat Etherscan Plugin
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: @nomiclabs/hardhat-etherscan
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install --save-dev @nomiclabs/hardhat-etherscan`
10
11
## Core Imports
12
13
```typescript
14
import "@nomiclabs/hardhat-etherscan";
15
```
16
17
The plugin extends Hardhat through side effects when imported, adding the `verify` task and configuration options.
18
19
## Basic Usage
20
21
```typescript
22
// hardhat.config.ts
23
import "@nomiclabs/hardhat-etherscan";
24
25
export default {
26
// ... other config
27
etherscan: {
28
apiKey: "YOUR_ETHERSCAN_API_KEY"
29
}
30
};
31
```
32
33
```bash
34
# Verify a deployed contract
35
npx hardhat verify --network mainnet 0x1234567890123456789012345678901234567890 "constructor arg 1" "constructor arg 2"
36
37
# List supported networks
38
npx hardhat verify --list-networks
39
```
40
41
## Architecture
42
43
The plugin integrates with Hardhat's task system and provides:
44
45
- **Task System**: Main `verify` task with multiple specialized subtasks for verification workflow
46
- **Configuration Extension**: Extends Hardhat config with `etherscan` field for API keys and custom chains
47
- **Network Detection**: Automatic detection of block explorer endpoints based on chain ID
48
- **Bytecode Analysis**: Intelligent contract matching using deployed bytecode comparison
49
- **Multi-Network Support**: Built-in support for 20+ blockchain networks and explorers
50
51
## Capabilities
52
53
### Contract Verification
54
55
Core contract verification functionality that submits source code to block explorers for public verification and audit.
56
57
```typescript { .api }
58
// Task: verify
59
interface VerifyTaskArgs {
60
address?: string;
61
constructorArgsParams: string[];
62
constructorArgs?: string;
63
contract?: string;
64
libraries?: string;
65
listNetworks: boolean;
66
noCompile: boolean;
67
}
68
```
69
70
[Contract Verification](./verification.md)
71
72
### Configuration Management
73
74
Configuration system for API keys, custom networks, and verification settings across multiple blockchain networks.
75
76
```typescript { .api }
77
interface EtherscanConfig {
78
apiKey?: string | Record<string, string>;
79
customChains: CustomChain[];
80
}
81
82
interface CustomChain {
83
network: string;
84
chainId: number;
85
urls: EtherscanURLs;
86
}
87
88
interface EtherscanURLs {
89
apiURL: string;
90
browserURL: string;
91
}
92
```
93
94
[Configuration](./configuration.md)
95
96
### Network Support
97
98
Built-in support for major blockchain networks and block explorers, with the ability to add custom networks.
99
100
```typescript { .api }
101
interface EtherscanNetworkEntry {
102
network: string;
103
urls: EtherscanURLs;
104
}
105
106
type ChainConfig = Record<string, EtherscanChainConfig>;
107
```
108
109
[Network Support](./networks.md)
110
111
### Constructor Arguments Processing
112
113
Processing and encoding of constructor arguments for contract verification, supporting both inline arguments and file-based argument modules.
114
115
```typescript { .api }
116
function encodeArguments(
117
abi: any,
118
sourceName: string,
119
contractName: string,
120
constructorArguments: any[]
121
): Promise<string>;
122
```
123
124
[Constructor Arguments](./constructor-arguments.md)
125
126
### Library Management
127
128
Management and linking of Solidity libraries used by contracts during verification, with automatic library address detection.
129
130
```typescript { .api }
131
interface Libraries {
132
[sourceName: string]: {
133
[libraryName: string]: string;
134
};
135
}
136
137
interface LibraryNames {
138
sourceName: string;
139
libName: string;
140
}
141
```
142
143
[Library Management](./libraries.md)
144
145
## Types
146
147
```typescript { .api }
148
interface EtherscanUserConfig {
149
apiKey?: string | Record<string, string>;
150
customChains?: CustomChain[];
151
}
152
153
interface EtherscanChainConfig {
154
chainId: number;
155
urls: EtherscanURLs;
156
}
157
158
interface ContractInformation {
159
compilerInput: CompilerInput;
160
compilerOutput: CompilerOutput;
161
solcVersion: string;
162
sourceName: string;
163
contractName: string;
164
contract: CompilerOutput["contracts"][string][string];
165
libraryLinks: ResolvedLinks;
166
undetectableLibraries: LibraryNames[];
167
}
168
169
interface ResolvedLinks {
170
[sourceName: string]: {
171
[libraryName: string]: string;
172
};
173
}
174
175
// Metadata analysis constants
176
const METADATA_LENGTH_SIZE: 2;
177
const METADATA_PRESENT_SOLC_NOT_FOUND_VERSION_RANGE: "0.4.7 - 0.5.8";
178
const METADATA_ABSENT_VERSION_RANGE: "<0.4.7";
179
```