# How to Verify Smart Contracts

A contract source code could be verify after successfully deployed to BounceBit network , At the moment , to verify the source code ,it supports BounceBit explorer(bbscan.io) and hardhat verify plugin.

### Verify via bbscan.io

The simplest way to verify your source code is via the bbscan.io UI. This process does not require any programming skills.

#### A Step-by-step Tutorial

**Step 1.** Head to bbscan.io, select the network for the contract to verify (support both for Testnet and Mainnet):

<figure><img src="https://files.readme.io/32111da-1280X1280.PNG" alt=""><figcaption></figcaption></figure>

<br>

**Step 2.** Navigate to the 'Verify Contract' page through the submenu of Blockchain tab on the menu bar.

<figure><img src="https://files.readme.io/70a4577-1280X1280_1.PNG" alt=""><figcaption></figcaption></figure>

<br>

**Step 3.** Insert the contract Address and upload metadata.json file, then click the verify contract button at bottom of the page. The verification process may fail if there are any mismatches between the smart contract and the upload files.

<figure><img src="https://files.readme.io/8b2d69c-download.png" alt=""><figcaption></figcaption></figure>

<br>

**Step 4.** You will then be able to view the verification results. The outcome can either be a success or a failure. The verification process may fail if there are any mismatches between the smart contract and the uploaded files.

<figure><img src="https://files.readme.io/50c6f6c-image.png" alt=""><figcaption></figcaption></figure>

<br>

**Step 5.** Verified contract details could be viewed by clicking the View the Contract, or navigate to the contract detail page by searching the contract address.

<figure><img src="https://files.readme.io/2afc0fc-image_1.png" alt=""><figcaption></figcaption></figure>

\ <br>

### Verify via Hardhat verify plugin

To verify contract with hardhat verify plugin, in short, all steps are:

1. Setup config.
2. Flatten contract (skip if there's only one solidity file with no external dependencies).
3. Verify contract by verify plugin.

**Step 1. Setup config**

First, install the plugin:

Shell

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

And add the following statement to your `hardhat.config.js`:

JavaScript

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

Then, add the following networks, etherscan and sourcify configs to your `hardhat.config.js` file:

JavaScript

```javascript
module.exports = {
  networks: {
    bbtestnet: {
      chainId: 6000,
      url: "https://fullnode-testnet.bouncebitapi.com"
    },
    bbmainnet: {
      chainId: 6001,
      url: "https://fullnode-mainnet.bouncebitapi.com/"
    }
  },
  etherscan: {
    enabled: false 
  },
  sourcify: {
    enabled: true,
    apiUrl: "http://api.bbscan.io/sourcify/server"
  }
};
```

**Step 2. Flatten contract**

If the contract contains more than one file, or it imports external dependencies, Hardhat comes with a built-in flatten task that lets you combine the source code of multiple Solidity files so the contract could be verify by hardhat-verify plugin.

Shell

```shell
#all the Solidity files in your project will be combined
npx hardhat flatten > contracts/flattened.sol 

#or, specifc a path to the contract file to flatten(the file which contains compile target):
npx hardhat flatten contracts/Foo.sol > contracts/flattened.sol
```

The flattened contract need to be successful compiled in your contract project by hardhat. Then we are ready for the next step.

**Step3. Verify contract**

Run the command:

Shell

```shell
npx hardhat verify --network bbtestnet --contract contracts/flattened.sol:Foo <0xTheContractAddress>
```

Run `npx hardhat help verify` more details about verify plugin

The verification process takes seconds to minutes. If contract is successfully verified, you should see :

```
Successfully verified contract Token on Sourcify.
```

Done!
