<!-- Canonical: https://docs.linea.build/network/how-to/verify-smart-contract/foundry -->

> For the complete Linea documentation index, see [llms.txt](/llms.txt).
> Agents can fetch this page as Markdown at [https://docs.linea.build/network/how-to/verify-smart-contract/foundry.md](https://docs.linea.build/network/how-to/verify-smart-contract/foundry.md).

# Foundry

To verify your Foundry contracts, you can use Foundry's [`verify-contract`](https://book.getfoundry.sh/reference/forge/forge-verify-contract) to verify contracts on Lineascan.

You'll need to get a Lineascan (Linea instance of Etherscan) API key by creating an account at [https://lineascan.build/myapikey](https://lineascan.build/myapikey).

## Verify your smart contract

note

These instructions verify using the Linea instance of Etherscan, which currently doesn't support Yul. If you would like to verify using Blockscout, please use the [Blockscout API URL for the required network](/network/build/block-explorers).

### Verify a contract that has already been deployed

If you want to verify a contract that has already been deployed, you can use the following commands:

-   Mainnet
-   Testnet

```bash
forge verify-contract --etherscan-api-key LINEASCAN_API_KEY --verifier-url https://api.lineascan.build/api CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

```bash
forge verify-contract --etherscan-api-key LINEASCAN_API_KEY --verifier-url https://api-sepolia.lineascan.build/api CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

You should see something a little like this:

```bash
Start verifying contract 0x8de6e9b6c774c8b7aba587ed84e5ad0a45837b16 deployed on mainnet

Submitting verification for [src/Counter.sol:Counter] "0x8dE6e9b6c774c8B7AbA587ED84E5AD0A45837b16".
Submitted contract for verification:
        Response: OK
        GUID: `ynnfyvwcqev9i5xr1urdqt9kdwx4zkurvpu7rgh2ywmyp22dpy`
        URL:
        https://etherscan.io/address/0x8de6e9b6c774c8b7aba587ed84e5ad0a45837b16
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
```

### Verify a contract upon creation

If you want to verify a contract as it is being deployed for the first time, you can use the following commands:

-   Mainnet
-   Testnet

```bash
forge create --rpc-url https://linea.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY --verify --verifier-url https://api.lineascan.build/api --etherscan-api-key LINEASCAN_API_KEY
```

```bash
forge create --rpc-url https://linea-sepolia.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY --verify --verifier-url https://api-sepolia.lineascan.build/api --etherscan-api-key LINEASCAN_API_KEY
```

You can check that it was verified correctly by navigating to the [testnet block explorer](https://sepolia.lineascan.build/) or the [mainnet block explorer](https://lineascan.build/) and pasting in the deployed contract address.

## Using `.env` and `foundry.toml` to store Lineascan information

If you don't want to paste your keys inline and have multiple Etherscan API keys to manage, you can use the `.env` and `foundry.toml` files to set up custom configurations.

These steps assume you stored your secret keys in a `.env` file. which you can read more about [in the Foundry deployment instructions](/network/how-to/deploy-smart-contract/foundry#deploy-a-smart-contract-using-a-env-file).

```bash
LINEASCAN_API_KEY=YOUR_LINEASCAN_API_KEY
```

Then, run:

```bash
source .env
```

Finally, modify `foundry.toml` to include the Etherscan configurations:

```bash
[etherscan]
linea-sepolia = { key = "${LINEASCAN_API_KEY}", chain = 59141, url = "https://api-sepolia.lineascan.build/api" }
linea-mainnet = { key = "${LINEASCAN_API_KEY}", chain = 59144, url = "https://api.lineascan.build/api" }
```

Then, to verify your smart contracts, you can simply run:

-   Mainnet
-   Testnet

```bash
forge verify-contract --chain linea-mainnet YOUR_CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

```bash
forge verify-contract --chain linea-sepolia YOUR_CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

info

Learn more about different configurations for verifying your smart contracts using the [`forge verify-contract`](https://book.getfoundry.sh/reference/forge/forge-verify-contract#forge-verify-contract) command and the [Forge deployment instructions](https://book.getfoundry.sh/forge/deploying).
