Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Verify a smart contract

Verification uploads your contract's source code to the block explorer and proves it compiles to the deployed bytecode. Once verified, users can read state, call functions, and audit the source on Stablescan without re-hosting your code. This guide walks through verifying a Foundry-deployed contract on Stable.

Stablescan runs on Etherscan's multichain (V2) API, so verification and every other explorer API call go to https://api.etherscan.io/v2/api with a chainid parameter:

NetworkChain IDVerifier URL
Stable testnet2201https://api.etherscan.io/v2/api?chainid=2201
Stable mainnet988https://api.etherscan.io/v2/api?chainid=988

Prerequisites

  • A contract already deployed on Stable testnet or mainnet. If you haven't deployed yet, see Deploy a smart contract.
  • Foundry installed (forge available in your PATH). Run foundryup if --verifier custom is not recognized.
  • The deployed contract address from your forge create output.
  • An Etherscan API key from https://etherscan.io/myapikey. One key covers every chain on the V2 API, including both Stable networks.

1. Confirm the deployed address

Make sure you have the Deployed to address from your earlier deployment. From the Deploy a smart contract flow, this was the value printed after forge create.

cast code 0xDeployedContractAddress --rpc-url https://rpc.testnet.stable.xyz | head -c 20
0x6080604052600436...

A non-empty bytecode confirms the contract is deployed at that address.

2. Export your API key

Foundry and curl both read the key from your shell, so export it once.

export ETHERSCAN_API_KEY=YourApiKey
 
curl "https://api.etherscan.io/v2/api?chainid=2201&module=account&action=balance&address=0xDeployedContractAddress&tag=latest&apikey=$ETHERSCAN_API_KEY"
{"status":"1","message":"OK","result":"0"}

A "status":"1" response confirms the key works against Stable testnet. If you get Missing/Invalid API Key, the key is unset or not yet active.

3. Run forge verify-contract

Point Foundry at the Etherscan V2 endpoint for chain 2201.

forge verify-contract \
  0xDeployedContractAddress \
  src/Counter.sol:Counter \
  --chain-id 2201 \
  --verifier custom \
  --verifier-url "https://api.etherscan.io/v2/api?chainid=2201" \
  --verifier-api-key $ETHERSCAN_API_KEY \
  --watch
Start verifying contract `0xDeployedContractAddress` deployed on 2201

Submitting verification for [src/Counter.sol:Counter] 0xDeployedContractAddress.
Submitted contract for verification:
        Response: `OK`
        GUID: `abc123...`
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified

--watch blocks until verification finishes so you don't have to poll. On mainnet, swap the chain ID to 988 and the verifier URL to https://api.etherscan.io/v2/api?chainid=988.

4. Confirm verification on Stablescan

Open the contract page on the explorer.

https://testnet.stablescan.xyz/address/0xDeployedContractAddress

The Contract tab should now show source code, a green "Verified" badge, and the full ABI. Users can read state under Read Contract and send transactions under Write Contract.

Troubleshooting

  • "Invalid API URL endpoint": you're calling the explorer host directly. Replace https://testnet.stablescan.xyz/api with https://api.etherscan.io/v2/api?chainid=2201.
  • "Missing/Invalid API Key": ETHERSCAN_API_KEY is unset in the current shell, or the key was just created and isn't active yet. Re-run the curl check in step 2.
  • "Bytecode does not match": your source compiles to different bytecode than what's deployed. Most often caused by mismatched Solidity version or optimizer settings. Pass --compiler-version and --optimizer-runs explicitly to match your foundry.toml.
  • "GUID not found": the verifier hasn't registered your submission yet. Re-run with --watch or manually check the URL printed in the response.
  • Contract uses libraries: add --libraries src/Lib.sol:Lib:0xDeployedLibAddress for each linked library.

Next recommended