|
4 | 4 |
|
5 | 5 | [Hardhat](https://hardhat.org) plugin to verify the source of code of deployed contracts.
|
6 | 6 |
|
| 7 | +1. [What](#what) |
| 8 | +2. [Installation](#installation) |
| 9 | +3. [Tasks](#tasks) |
| 10 | +4. [Environment extensions](#environment-extensions) |
| 11 | +5. [Usage](#usage) |
| 12 | + 1. [Complex arguments](#complex-arguments) |
| 13 | + 2. [Libraries with undetectable addresses](#libraries-with-undetectable-addresses) |
| 14 | + 3. [Multiple API keys and alternative block explorers](#multiple-api-keys-and-alternative-block-explorers) |
| 15 | + 4. [Adding support for other networks](#adding-support-for-other-networks) |
| 16 | + 5. [Using programmatically](#using-programmatically) |
| 17 | + 1. [Providing libraries from a script or task](#providing-libraries-from-a-script-or-task) |
| 18 | + 2. [Advanced Usage: Using the Etherscan class from another plugin](#advanced-usage-using-the-etherscan-class-from-another-plugin) |
| 19 | +6. [How it works](#how-it-works) |
| 20 | +7. [Known limitations](#known-limitations) |
| 21 | + |
7 | 22 | ## What
|
8 | 23 |
|
9 | 24 | This plugin helps you verify the source code for your Solidity contracts. At the moment, it supports [Etherscan](https://etherscan.io)-based explorers and explorers compatible with its API like [Blockscout](https://www.blockscout.com/).
|
@@ -208,6 +223,45 @@ hre.run("verify:verify", {
|
208 | 223 | }
|
209 | 224 | ```
|
210 | 225 |
|
| 226 | +#### Advanced Usage: Using the Etherscan class from another plugin |
| 227 | +
|
| 228 | +The Etherscan class used for contract verification can be imported from the plugin, allowing its direct usage: |
| 229 | +
|
| 230 | +```js |
| 231 | +import { Etherscan } from "@nomicfoundation/hardhat-verify/etherscan"; |
| 232 | + |
| 233 | +const instance = new Etherscan( |
| 234 | + "abc123def123", // Etherscan API key |
| 235 | + "https://api.etherscan.io/api", // Etherscan API URL |
| 236 | + "https://etherscan.io" // Etherscan browser URL |
| 237 | +); |
| 238 | + |
| 239 | +if (!instance.isVerified("0x123abc...")) { |
| 240 | + const { message: guid } = await instance.verify( |
| 241 | + // Contract address |
| 242 | + "0x123abc...", |
| 243 | + // Contract source code |
| 244 | + '{"language":"Solidity","sources":{"contracts/Sample.sol":{"content":"// SPDX-Lic..."}},"settings":{ ... }}', |
| 245 | + // Contract name |
| 246 | + "contracts/Sample.sol:MyContract", |
| 247 | + // Compiler version |
| 248 | + "v0.8.19+commit.7dd6d404", |
| 249 | + // Encoded constructor arguments |
| 250 | + "0000000000000000000000000000000000000000000000000000000000000032" |
| 251 | + ); |
| 252 | + |
| 253 | + await sleep(1000); |
| 254 | + const verificationStatus = await instance.getVerificationStatus(guid); |
| 255 | + |
| 256 | + if (verificationStatus.isSuccess()) { |
| 257 | + const contractURL = instance.getContractUrl("0x123abc..."); |
| 258 | + console.log( |
| 259 | + `Successfully verified contract "MyContract" on Etherscan: ${contractURL}` |
| 260 | + ); |
| 261 | + } |
| 262 | +} |
| 263 | +``` |
| 264 | +
|
211 | 265 | ## How it works
|
212 | 266 |
|
213 | 267 | The plugin works by fetching the bytecode in the given address and using it to check which contract in your project corresponds to it. Besides that, some sanity checks are performed locally to make sure that the verification won't fail.
|
|
0 commit comments