Verifying Smart Contracts

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

Using Developer Tools

Most smart contract tooling has plugins for verifying your contracts easily on Etherscan.

Hardhat

Modify hardhat.config.ts to point to Scroll’s RPC and block explorer API.

For example, the config for Scroll Sepolia will look like this:

...

const config: HardhatUserConfig = {
  ...
  networks: {
    scrollSepolia: {
      url: 'https://sepolia-rpc.scroll.io' || '',
      accounts:
        process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    },
  },
  etherscan: {
    apiKey: {
      scrollSepolia: <YOUR API KEY>,
    },
    customChains: [
      {
        network: 'scrollSepolia',
        chainId: 534351,
        urls: {
          apiURL: 'https://api-sepolia.scrollscan.com/api',
          browserURL: 'https://sepolia.scrollscan.com/',
        },
      },
    ],
  },
}

...

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

npx hardhat verify --network scrollSepolia <contract address> <space separated constructor parameters>

For example, this is how a smart contract that receives two uint parameters in the constructor should look:

npx hardhat verify --network scrollSepolia 0xD9880690bd717189cC3Fbe7B9020F27fae7Ac76F 123 456

Foundry

When using Foundry, the verify-contract command helps automate the process of verifying contracts. If your contract has constructor arguments, you can specify these in ABI-encoded form with the --constructor-args option. For example, if your constructor takes two uint256 variables:

 --constructor-args $(cast abi-encode "constructor(uint256,uint256)" 0 7)

Refer to the Foundry documentation for further options you can specify.

forge verify-contract <contract address> <contract name> \
  --verifier-url https://api-sepolia.scrollscan.com/api \
  --etherscan-api-key <your Scrollscan API key> \
  --constructor-args <your constructor arguments>

What's Next

Stay up-to-date on the latest Scroll Developer news
Roadmap updates, virtual and live events, ecosystem opportunities and more
Thank you for subscribing!

Resources

Follow Us