# Verify a contract

## Get Started <a href="#get-started" id="get-started"></a>

### **1) Install Hardhat** <a href="#id-1-install-hardhat" id="id-1-install-hardhat"></a>

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** <a href="#id-2-create-a-project" id="id-2-create-a-project"></a>

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 <a href="#id-3-install-plugin" id="id-3-install-plugin"></a>

Install the [hardhat-verify plugin](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify) (requires **v3.0.0+).**

**npm**

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

**yarn**

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

### 4) Add plugin reference to config file <a href="#id-4-add-plugin-reference-to-config-file" id="id-4-add-plugin-reference-to-config-file"></a>

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 Custom Networks <a href="#config-file-and-unsupported-networks" id="config-file-and-unsupported-networks"></a>

Your basic [Hardhat config file](https://hardhat.org/config/) (`hardhat.config.js` or `hardhat.config.ts`) will be setup to support Conla Testnet.&#x20;

You have to specify the explorer details under a `customChains` object. It includes:

* `chainID` - 11118
* `apiURL` - <https://explorer.conla.com/api>
* `browserURL` - <https://explorer.conla.com/>

```
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: {
    conla-testnet: {
      url: 'https://rpc.testnet.conla.com',
      accounts: [PRIVATE_KEY],
    },
  },
  etherscan: {
    apiKey: {
      // Is not required. Can be any non-empty string
      sepolia: "abc"
    },
    customChains: [
      {
        network: "conla-testnet",
        chainId: 11118,
        urls: {
          apiURL: "https://explorer.conla.com/api",
          browserURL: "https://explorer.conla.com/",
        }
      }
    ]
  },
  sourcify: {
    enabled: false
  }
};

export default config;
```

## Deploy and Verify <a href="#deploy-and-verify" id="deploy-and-verify"></a>

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

#### Deploy <a href="#deploy" id="deploy"></a>

{% code fullWidth="false" %}

```
D:\hard_hat>npx hardhat ignition deploy ./ignition/modules/Lock.ts --network conla-testnet
✔ Confirm deploy to network conla-testnet (11118)? … yes
Compiled 1 Solidity file successfully (evm target: paris).
Hardhat Ignition 🚀

Deploying [ LockModule ]

Batch #1
  Executed LockModule#Lock

[ LockModule ] successfully deployed 🚀

Deployed Addresses

LockModule#Lock - 0x15447991b46862f6cF9a5dB358a923f768a9Fadb
```

{% endcode %}

#### Verify <a href="#verify" id="verify"></a>

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

```
npx hardhat verify --network conla-testnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
```

Example.

```
D:\hard_hat>npx hardhat verify --network conla-testnet 0x15447991b46862f6cF9a5dB358a923f768a9Fadb 1234
Successfully submitted source code for contract
contracts/Lock.sol:Lock at 0x15447991b46862f6cF9a5dB358a923f768a9Fadb
for verification on the block explorer. Waiting for verification result...

Successfully verified contract Lock on the block explorer.
https://explorer.conla.com/address/0x15447991b46862f6cF9a5dB358a923f768a9Fadb#code
```

Note the verify task may not be listed in the available tasks lists at `npx hardhat --help` but should work as expected.

If not, check you have the minimum required version of the nomiclabs-hardhat-etherscan plugin (v3.0.0+) installed

#### Automatically verified contracts <a href="#automatically-verified-contracts" id="automatically-verified-contracts"></a>

Sometimes the contract may be automatically verified via [Ethereum Bytecode Database](https://docs.blockscout.com/about/features/ethereum-bytecode-database-microservice#solution-ethereum-bytecode-database-blockscout-ebd) service. In that case you may see the following response:

```
The contract 0x15447991b46862f6cF9a5dB358a923f768a9Fadb has already been verified on Etherscan.
https://explorer.conla.com/address/0x15447991b46862f6cF9a5dB358a923f768a9Fadb#code
```

In that case, you may try to enforce using `--force` flag\*.

It prevents Hardhat to check if the contract is already verified, and force it to send verification request anyway. Notice, that it is helpful only if the contract was automatically verified **partially**. That way, a new verification sources would be saved. If the contract was **fully** verified already, that just returns an error.

```
npx hardhat verify --network conla-testnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1" --force
```

* The flag is available starting from `@nomicfoundation/hardhat-verify@2.0.7`

## Confirm Verification on Conla Explorer <a href="#confirm-verification-on-blockscout" id="confirm-verification-on-blockscout"></a>

Go to [Conla Explorer](https://explorer.conla.com/) and paste the contract address into the search bar.

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

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

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

If your screen size is limited, you may need to click the 3 dots to view and click through to the contract.

<figure><img src="https://docs.blockscout.com/~gitbook/image?url=https%3A%2F%2F1077666658-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-Lq1XoWGmy8zggj_u2fM%252Fuploads%252F0NquohoqStfhA8OJXrH5%252Fverify-contract-3.png%3Falt%3Dmedia%26token%3D1a84ab85-630f-4bd7-9de9-611ce5c8f3fb&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=49301ad3&#x26;sv=1" alt=""><figcaption></figcaption></figure>

Scroll down to see and interact with the contract code.

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


---

# 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.conla.com/developers/dapp/verify-a-contract.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.
