Foundry
To verify your Foundry contracts, you can use Foundry's
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.
Verify your smart contract​
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.
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
forge verify-contract --etherscan-api-key LINEASCAN_API_KEY --verifier-url https://api.lineascan.build/api CONTRACT_ADDRESS path_to_contract:contract_name --watch
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:
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
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
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 or the mainnet block explorer and pasting in the deployed contract address.
Using .env
and foundry.toml
to store etherscan 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.
LINEASCAN_API_KEY=YOUR_LINEASCAN_API_KEY
Then, run:
source .env
Finally, modify foundry.toml
to include the Etherscan configurations:
[etherscan]
linea-sepolia = { key = "${LINEASCAN_API_KEY}", url = "https://api-sepolia.lineascan.build/api" }
linea-mainnet = { key = "${LINEASCAN_API_KEY}", url = "https://api.lineascan.build/api" }
Then, to verify your smart contracts, you can simply run:
- Mainnet
- Testnet
forge verify-contract --chain linea-mainnet YOUR_CONTRACT_ADDRESS path_to_contract:contract_name --watch
forge verify-contract --chain linea-sepolia YOUR_CONTRACT_ADDRESS path_to_contract:contract_name --watch
contracts using the
forge verify-contract
command and the
Forge deployment instructions. :::