# Hardhat Verification Plugin

[Hardhat ](https://hardhat.org/)is a full-featured development environment for contract compilation, deployment and verification. The [hardhat-verify plugin](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify) supports contract verification on Quaiscan.

## Get Started

### **1) Install Hardhat**

If you are starting from scratch, create an npm project by going to an empty folder, running `npm init`, and following the instructions. Recommend npm 7 or higher.

Once your project is ready:

**npm instructions**

```
npm install --save-dev hardhat
```

**yarn instructions**

```
yarn add --dev hardhat
```

### **2) Create a project**

Run `npx hardhat` in your project folder and follow the instructions to create ([more info here](https://hardhat.org/getting-started/#quick-start)).

### 3) Install plugin

Install the [hardhat-verify plugin](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify)

**npm**

```
npm install --save-dev @nomicfoundation/hardhat-verify
```

**yarn**

```
yarn add --dev @nomicfoundation/hardhat-verify
```

### 4) Add plugin reference to config file

Add the following statement to your `hardhat.config.js`.

```
require("@nomicfoundation/hardhat-verify");
```

If using TypeScript, add this to your `hardhat.config.ts.` [More info on using typescript with hardhat available here](https://hardhat.org/guides/typescript.html#typescript-support).

```
import "@nomicfoundation/hardhat-verify";
```

## Config File

Your basic [Hardhat config file](https://hardhat.org/config/) (`hardhat.config.js` or `hardhat.config.ts`) will be setup to support the network you are working on. In this example we use the Optimism Sepolia test network and a `.js` file.

Here we add an RPC url without an API key, however some value is still required. You can use any arbitrary string. [More info](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#multiple-api-keys-and-alternative-block-explorers).

If you prefer, you can migrate to [hardhat-toolbox](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-toolbox) to use a plugin bundle.

In order to use Quaiscan explorer for the verification, you have to specify the explorer details under a `customChains` object. It includes:

* `chainID` - Quai Network ChainID
* `apiURL` - Quaiscan API URL
* `browserURL` - Quaiscan Web URL

For example, here we added Quaiscan api endpoints for Quai Network to the config file. Note the network name in `customChains` must match the network name in the `apiKey` object.

```typescript
import { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'
import '@nomicfoundation/hardhat-verify'

const PRIVATE_KEY = vars.get('PRIVATE_KEY')

const config: HardhatUserConfig = {
	solidity: '0.8.24',
	networks: {
		'quai': {
			url: 'https://rpc.dev.quai.network',
			accounts: [PRIVATE_KEY],
		},
	},
	etherscan: {
		apiKey: {
			// Is not required by quaiscan. Can be any non-empty string
			'quai': 'abc',
		},
		customChains: [
			{
				network: 'quai',
				chainId: 9000,
				urls: {
					apiURL: 'https://quaiscan.io/api/v2',
					browserURL: 'https://quaiscan.io/',
				},
			},
		],
	},
	sourcify: {
		enabled: false,
	},
}

export default config
```

## Deploy and Verify

For deployment we will use [Hardhat Ignition](https://hardhat.org/ignition/docs/getting-started#overview) - built-in Hardhat deployment system.

### Deploy

```
> npx hardhat ignition deploy ./ignition/modules/Lock.ts --network quai
✔ Confirm deploy to network quai (9000)? … yes
Compiled 1 Solidity file successfully (evm target: istanbul).
Hardhat Ignition 🚀

Deploying [ LockModule ]

Batch #1
  Executed LockModule#Lock

[ LockModule ] successfully deployed 🚀

Deployed Addresses

LockModule#Lock - 0x00126b33e425f99ce962ACB91752DB41F302EFEA
```

### Verify

The plugin requires you to include constructor arguments with the verify task and ensures that they correspond to expected ABI signature. However, Quaiscan ignores those arguments, so you may specify any values that correspond to the ABI.

```
npx hardhat verify --network <network> DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
```

Optimism Sepolia example.

```
> npx hardhat verify --network quai 0x00126b33e425f99ce962ACB91752DB41F302EFEA 1234
Successfully submitted source code for contract
contracts/Lock.sol:Lock at 0x00126b33e425f99ce962ACB91752DB41F302EFEA
for verification on the block explorer. Waiting for verification result...

Successfully verified contract Lock on the block explorer.
https://quaiscan.io/address/0x00126b33e425f99ce962ACB91752DB41F302EFEA#code
```

## Confirm Verification on Quaiscan

Go to your Quaiscan instance and paste the contract address into the search bar.

<figure><img src="/files/5VDwEi6C2jLYgCXXHbTs" alt=""><figcaption></figcaption></figure>

Scroll down to see verified status. A green checkmark ✅ means the contract is verified.

<figure><img src="/files/aFks4enNkySb3TQk6fyL" alt=""><figcaption></figcaption></figure>

Scroll down to see and interact with the contract code.

<figure><img src="/files/NMwbjY3IKtRRA6OBheiK" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/LTUqcEK8vrsEO5xeIjyB" alt=""><figcaption></figcaption></figure>

## Resources

{% hint style="info" %}
Learn more about plugin configs, troubleshooting etc. at <https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.quaiscan.io/developer-support/smart-contract-verification/hardhat-verification-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
