Verifying Contracts

Verifying your smart contract's source code on the block explorer 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:

  • manual verification through direct upload of Solidity code from your .sol files or the compiler artifacts, or

  • automated verification using Hardhat or Foundry

Manual Verification

You will require the following:

  1. Deployed Smart Contract: The contract's Zircuit address

  2. Solidity Source Code: The exact source code as it was at the time of contract deployment, or the solc artifacts in the standard JSON format

  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

  5. Optimization Settings: The Solidity optimization runs count, if applicable

Follow these steps for verification:

  1. Navigate to your smart contract on https://explorer.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 a single Solidity file, multiple Solidity files, or the standard json input/output files for solc. 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 specify the compiler optimizer settings. 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, optimization settings, constructor parameters, and exactness of the source code.

Automated Verification

If you are using Hardhat or Foundry to develop your project, you can use a plug-in to verify the smart contracts on Zircuit’s block explorer. You will first need to obtain an authentication token for the block explorer:

  1. Click on API keys in the top right corner

  2. Connect you wallet and click Sign in

  3. Generate an API key by clicking on Create new key. Each address can create up to 3 API keys. Record the API key for the configuration below.

Hardhat

Before you start, install Hardhat if you haven't already, and deploy your smart contracts to Zircuit. Then:

  1. Install the Hardhat plug-in:

npm install --save-dev @nomiclabs/hardhat-etherscan

  1. Obtain an API key for https://explorer.zircuit.com/ by clicking the "API Keys" link in the top menu and following the instructions. You will need to connect your wallet to authenticate yourself. Every address can hold up to 3 valid API keys at a time.

  2. Configure Hardhat by adding the plug-in to your hardhat.config.js and add your API key:

require('@nomiclabs/hardhat-etherscan');

module.exports = {
  networks: {
    zircuit: {
      // ... rest of the network config
    },
  },
  
  etherscan: {
    apiKey: {
      zircuit: 'YOUR API KEY FROM STEP 2'
    }, 
    customChains: [
      {
        network: 'zircuit',
        chainId: 48900,
        urls: {
          apiURL: 'https://explorer.zircuit.com/api/contractVerifyHardhat',
          browserURL: 'https://explorer.zircuit.com',
        },
      }
    ]
  }
  
  // ... rest of the config
}

For Zircuit Testnet, use chainId: 48999, apiURL: 'https://explorer.testnet.zircuit.com/api/contractVerifyHardhat' and browserURL: 'https://explorer.testnet.zircuit.com/'.

  1. Run the verification command from your terminal:

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

Replace <network-name>, <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.

Foundry

Install Foundry if not already installed, and deploy your smart contracts to Zircuit. Then:

  1. Obtain an API key for https://explorer.zircuit.com/ by clicking the "API Keys" link in the top menu and following the instructions. You will need to connect your wallet to authenticate yourself. Every address can hold up to 3 valid API keys at a time.

  2. Use the forge command to verify the contract:

forge verify-contract --verifier-url https://explorer.zircuit.com/api/contractVerifyHardhat <deployed-contract-address> <source-file>:<contract-name> --root . --etherscan-api-key <ZIRCUIT_API_KEY>

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

Remember to use the Zircuit Testnet values, if you're deploying onto Zircuit Testnet.

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 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.

Last updated