> For the complete documentation index, see [llms.txt](https://scroll-zkp.gitbook.io/scroll-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scroll-zkp.gitbook.io/scroll-guide/developers/verifying-smart-contracts.md).

# Verifying Smart Contracts

{% hint style="danger" %}
**Scroll Alpha Testnet is now deprecated.**

Please visit our new documentation for the Scroll Sepolia Testnet at <https://docs.scroll.io/>
{% endhint %}

After deploying your smart contracts, it's important to verify your code on [our block explorer](https://blockscout.scroll.io/). This can be done in an automated way using your developer tooling or using Blockscout's Web UI.

{% hint style="warning" %}
Our Blockscout instance currently has inconsistent behavior in verifying contracts with Foundry. We're working on a fix, along with other stability improvements. Don't hesitate to come ask for help [on Discord](https://discord.com/channels/853955156100907018/1028102371894624337) though.
{% endhint %}

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

```javascript
...

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.

```solidity
npx hardhat verify --network scrollAlpha <contract address> <space separated constructor parameters>
```

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

```solidity
npx hardhat verify --network scrollAlpha 0xD9880690bd717189cC3Fbe7B9020F27fae7Ac76F 123 456
```

{% hint style="warning" %}
You may receive an error stating `etherscan.apiKey.trim is not a function` . If so, you need to update `@nomiclabs/hardhat-etherscan` to be able to support custom chains. Try running `npm update @nomiclabs/hardhat-etherscan`
{% endhint %}

### Foundry

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

```bash
forge verify-contract <Contract Address> <Space separated params> <Solidity file>:<Contract name> --chain-id 534353 --verifier-url <https://blockscout.scroll.io/api> --verifier blockscout
```

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

```bash
forge verify-contract 0xD9880690bd717189cC3Fbe7B9020F27fae7Ac76F 123 456 src/MyContract.sol:MyContract --chain-id 534353 --verifier-url <https://blockscout.scroll.io/api> --verifier blockscout
```

{% hint style="warning" %}
Please note that certain issues have been reported when executing verifying Smart Contracts from Foundry. In such cases, we recommend trying an alternative method as described on the [foundry issues page](https://github.com/foundry-rs/foundry/issues?q=is%3Aissue+blockscout+is%3Aclosed).
{% endhint %}

### Truffle

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

```solidity
npm install -D truffle-plugin-verify
```

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

```javascript
module.exports = {
  plugins: ['truffle-plugin-verify'],
  networks: {
    scrollAlpha: {
      provider: () =>
        new HDWalletProvider(process.env.PRIVATE_KEY, 'https://alpha-rpc.scroll.io/l2'),
      network_id: '*',
      verify: {
        apiUrl: 'https://blockscout.scroll.io/api',
        apiKey: 'abc',
        explorerUrl: 'https://blockscout.scroll.io/',
      },
    },
    
...
```

After migrating our smart contract, we can verify it.

```solidity
npx truffle run verify MyContract --network scrollAlpha
```

## 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](https://docs.blockscout.com/for-users/verifying-a-smart-contract).

<img src="/files/sCeoihf9pLJLihjghMgl" alt="" data-size="original">


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://scroll-zkp.gitbook.io/scroll-guide/developers/verifying-smart-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
