# Verifying Contracts

Verifying your smart contract's source code on the [block explorer](https://explorer.zircuit.com) allows others to see your contract's code and verify that it operates as intended. The Zircuit block explorer provides two ways of verifying source code:

* automated verification using [Hardhat](https://hardhat.org/getting-started/) or [Foundry](https://book.getfoundry.sh/getting-started/installation.html)
* manual verification through direct upload of Solidity code from your `.sol` files or the compiler artifacts to [Sourcify](https://verify.sourcify.dev/)

### Automated Verification

If you are using Hardhat or Foundry to develop your project, you can use a plug-in to verify the smart contracts:

#### Foundry

Install [Foundry](https://book.getfoundry.sh/getting-started/installation.html) if not already installed, and deploy your smart contracts to Zircuit. Then:

Use the `forge` command to verify the contract:

```bash
forge verify-contract <deployed-contract-address> <source-file>:<contract-name>  \
--chain-id 48900 # or 48898 if deploying to Garfield Testnet
--verifier sourcify \
--verifier-url https://sourcify.dev/server
```

Replace `<deployed-contract-address>`, and `<source-file>:<contract-name>` with your details.

If you need to specify the constructor arguments, use the `--constructor-args` option with the ABI-encoded argument string. You can refer to the `verify-contract` [subcommand documentation](https://book.getfoundry.sh/reference/forge/forge-verify-contract) for more details.

If the command runs successfully, your contract's page on <https://explorer.zircuit.com> will now display the source code and a **Contract source code verified** badge.

#### Hardhat

Before you start, install [Hardhat](https://hardhat.org/getting-started/) if you haven't already, and deploy your smart contracts to Zircuit. Then:

1. Install the Hardhat plug-in:

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

2. Configure Hardhat by adding the plug-in to your `hardhat.config.js`:

```javascript
import { defineConfig } from "hardhat/config";
import hardhatVerify from "@nomicfoundation/hardhat-verify";

export default defineConfig({
  plugins: [hardhatVerify],
  networks: {
    zircuit: {
      url: 'https://mainnet.zircuit.com', // or 'https://garfield-testnet.zircuit.com'
      // ... rest of the network config
    },
  },
  verify: {
    etherscan: {
      enabled: false
    },
    blockscout: {
      enabled: false
    },
    sourcify: {
      enabled: true,
      apiUrl: 'https://sourcify.dev/server',
    }
  },
  // ... rest of the config
});
```

3. Run the verification command from your terminal:

```
npx hardhat verify --network zircuit <deployed-contract-address> [constructor-arguments]
```

Replace `<deployed-contract-address>`, and `[constructor-arguments]` with your specific details.

If the command runs successfully, your contract's page will now display the source code and a **Contract source code verified** badge.

### Manual Verification

You will require the following:

1. Deployed Smart Contract: The contract's Zircuit address
2. Solidity Source Code: The solc artifacts in the standard JSON format, or the exact source code as it was at the time of contract deployment + their metadata.json file(s)
3. Compiler Version: The Solidity compiler version used to compile the deployed contract
4. Constructor Arguments: The contract’s constructor arguments during the deployment, if any

Follow these steps for verification:

1. Navigate to your smart contract on <https://explorer.zircuit.com> (or [https://explorer.garfield-testnet.zircuit.com](https://explorer.garfield-testnet.zircuit.com/)) and use the search bar to find the smart contract for which you would like to verify the source code.
2. On the contract's page, click on the **Contract** tab. Click on the **Verify and Publish** link.
3. On the next screen, select the compiler version used to compile source code, and upload the source code files. Those can be the [standard json input/output files for solc](https://docs.soliditylang.org/en/v0.8.15/using-the-compiler.html#compiler-api), or Solidity and metadata.json file(s). Click **next**.
4. On the next page, enter the constructor argument data types and values. Use the ABI encoded format or the form, and the system will convert them for you. if using the .sol files, you will also need to upload their respective metadata.json files. When finished, upload the source files and click **Verify and Publish**.

If successful, your contract's page will now display the source code and a **Contract Source Code Verified** badge. If the process fails, double-check the compiler version, constructor parameters, and exactness of the source code.
