Skip to main content

Verifying a Smart Contract

After successfully deploying your smart contract, it is highly recommended that you verify its source code on Gate Layer's block explorer, GateScan. Verification not only enhances the transparency and trustworthiness of your project but also allows users and developers to interact with your contract directly from the explorer's UI.

Since GateScan is built on Blockscout, it is compatible with Etherscan's contract verification APIs. This allows you to easily automate the verification process using popular development frameworks like Hardhat or Foundry.


1. Verifying with Development Frameworks

Verifying with Hardhat

To automatically verify your contract with Hardhat, you need to install the hardhat-etherscan plugin and add the relevant etherscan configuration to your hardhat.config.js file.

  1. Install the plugin (If you used @nomicfoundation/hardhat-toolbox when initializing your project, this plugin is already included, and you can skip this step):

    npm install --save-dev @nomiclabs/hardhat-etherscan
  2. Configure hardhat.config.js: Add the etherscan field at the same level as your networks configuration.

    require("@nomicfoundation/hardhat-toolbox");
    require("dotenv").config();

    /** @type import('hardhat/config').HardhatUserConfig */
    module.exports = {
    solidity: "0.8.9",
    networks: {
    gatelayer_testnet: {
    url: process.env.GATELAYER_TESTNET_RPC_URL || "",
    accounts:
    process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    chainId: 10087,
    },
    // Mainnet Configuration (once available)
    /*
    gatelayer_mainnet: {
    url: process.env.GATELAYER_MAINNET_RPC_URL || "",
    accounts:
    process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    chainId: <MAINNET_CHAIN_ID>, // TBD
    },
    */
    },
    etherscan: {
    // The apiKey field is required, but you can use any string for GateScan
    apiKey: {
    gatelayer_testnet: 'any-api-key-string',
    // gatelayer_mainnet: 'any-api-key-string' // Uncomment once mainnet is live
    },
    customChains: [
    {
    network: "gatelayer_testnet",
    chainId: 10087,
    urls: {
    // The API endpoint for GateScan
    apiURL: "http://gatescan.org/gatelayer-testnet/api",
    // The browser URL for GateScan
    browserURL: "http://gatescan.org/gatelayer-testnet/"
    }
    },
    /*
    {
    network: "gatelayer_mainnet",
    chainId: <MAINNET_CHAIN_ID>, // TBD
    urls: {
    apiURL: "<MAINNET_API_URL>", // TBD
    browserURL: "<MAINNET_BROWSER_URL>" // TBD
    }
    }
    */
    ]
    },
    };
  3. Run the verification command: After deploying your contract, use the following command to verify it. Replace CONTRACT_ADDRESS with the actual address of your deployed contract and append any constructor arguments if applicable.

    # Example: Verifying the Greeter contract
    npx hardhat verify --network gatelayer_testnet CONTRACT_ADDRESS "Hello, Gate Layer!"

    Upon success, you will see a link to the verified contract in your terminal.

Verifying with Foundry

If you are using Foundry, you can verify your contract using the forge verify-contract command.

forge verify-contract <CONTRACT_ADDRESS> <CONTRACT_NAME> \
--chain-id 10087 \
--verifier-url http://gatescan.org/gatelayer-testnet/api \
--verifier blockscout
  • Replace <CONTRACT_ADDRESS> with your contract's address.
  • Replace <CONTRACT_NAME> with your contract's name (e.g., Greeter).

2. Verifying Manually via the GateScan Frontend

If you prefer a manual approach, you can also verify your contract directly on the GateScan explorer.

  1. Visit GateScan and navigate to your contract's address page.
  2. Find and click the Verify & Publish button under the Contract tab.

GateScan supports several source code formats, with the most common being:

  • Solidity (Flattened Source Code): This involves combining ("flattening") all your Solidity source files and their dependencies into a single file for upload. You can generate this file using the npx hardhat flatten or forge flatten commands.
  • Solidity (Standard JSON Input): Upload the standard JSON input file generated by the solc compiler. Remix IDE and Hardhat also generate these files in the artifacts/build-info/ directory during compilation.
  • Solidity (Multi-part files): Upload multiple .sol source files separately, ensuring that all import paths are correct.

When uploading, make sure that the Compiler Version and Optimization Settings you select exactly match the settings used during deployment.

Last updated on 2025/09/12