Verifying Smart Contracts

After deploying your smart contracts, it's important to verify your code on our block explorer. This can be done in an automated way using your developer tooling or using Blockscout's Web UI.

Using Developer Tools

Most smart contract tooling has plugins for verifying your contracts easily on Etherscan. Blockscout supports Etherscan's contract verification APIs, and it's straight forward to use these tools with the Scroll Alpha Testnet.

Hardhat

First, modify hardhat.config.ts to point to Scroll's RPC and blockscout.scroll.io/api. A dummy apyKey value is required, but anything works for its value.

...

const config: HardhatUserConfig = {
  ...
  networks: {
    scrollAlpha: {
      url: 'https://alpha-rpc.scroll.io/l2' || '',
      accounts:
        process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    },
  },
  etherscan: {
    apiKey: {
      scrollAlpha: 'abc',
    },
    customChains: [
      {
        network: 'scrollAlpha',
        chainId: 534353,
        urls: {
          apiURL: 'https://blockscout.scroll.io/api',
          browserURL: 'https://blockscout.scroll.io/',
        },
      },
    ],
  },
}

...

Now you can verify the smart contract by running the following command.

For example, this how a smart contract that receives two uint parameters in the constructor would look like.

Foundry

When using Foundry, the verify-contract helps us verifying contracts.

For example, this what verifying a smart contract that receives two uint parameters in the constructor looks like:

Truffle

To verify contracts with Truffle, first install the truffle-plugin-verify plugin.

Then, enable the plugin and connect Scroll's Alpha Testnet using the RPC URL and Blockscout verification API.

After migrating our smart contract, we can verify it.

Using the Blockscout Web UI

Shorter contracts can be verified using Blockscout's Web UI. To do so, combine all your Solidity code into one single file, including all the imported libraries. Then, lookup the deployed contract on on Blockscout, then visit the "Code" tab and select "Verify & Publish". Follow the instructions to submit your code.

For a more in-depth guide, see Blockscount's official documentation on Verifying a Smart Contract.

Last updated

Was this helpful?