Virtual TestNets are live! ⚡️ Test and stage dapps on real-time production data.
Get started →

All Products

Virtual TestNets
Frameworks
Foundry

Verify Contracts with Foundry

You can deploy smart contracts written in Solidity to a Virtual TestNet using Foundry. For debugging purposes, it’s recommended to verify smart contracts as you deploy them.

Foundry verification uses Tenderly’s Etherscan-compliant verification API through --verifier-url:

   $TENDERLY_VIRTUAL_TESTNET_RPC/verify/etherscan

For extensive instructions on how to verify contracts using Foundry, see the following guide:

⚠️

By default, contracts verified on a TestNet are private. But depending on the visibility setting of the Public Explorer, the code may be visible externally. Before verifying a contract, check if the Public Explorer option is enabled and how you’ve set the verification visibility.

Enable verification

Append the unknown_chain configuration to foundry.toml, containing the following information:

  • key - Tenderly Access Token.
  • chain - the chain ID.
  • url - verifier URL, you get from RPC URL by appending /verify/etherscan.
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
 
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
 
[etherscan]
#                   Paste TENDERLY_ACCESS_KEY    Chain ID        Verifier URL: ${TENDERLY_VIRTUAL_TESTNET_RPC}/verify/etherscan
unknown_chain = { key = "${TENDERLY_ACCESS_KEY}", chain = 73571, url = "${TENDERLY_VIRTUAL_TESTNET_RPC_URL}/verify/etherscan" }

Deploy and verify contracts

To verify contracts during deployment, run forge create with --verify and --verifier-url flags as follows:

Fund the deployer address using the unlimited faucet before running the deployment script.

## pate to your TestNet RPC URL
TENDERLY_ACCESS_KEY=... # paste your access key here
TENDERLY_VIRTUAL_TESTNET_RPC=... # Virtual TestNet RPC URL
TENDERLY_VERIFIER_URL=$TENDERLY_VIRTUAL_TESTNET_RPC/verify/etherscan
 
PRIVATE_KEY=... # the deployer private key - if needed
 
forge create Counter \
--private-key $PRIVATE_KEY  \
--rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC \
--etherscan-api-key $TENDERLY_ACCESS_KEY \
--broadcast \
--verify \
--verifier-url $TENDERLY_VERIFIER_URL

Verify existing contracts

To verify a contract that’s already deployed, use the forge verify-contract command:

COUNTER_ADDRESS=0x...
## pate to your TestNet RPC URL
TENDERLY_ACCESS_KEY=... # paste your access key here
TENDERLY_VIRTUAL_TESTNET_RPC=... # Virtual TestNet RPC URL
TENDERLY_VERIFIER_URL=$TENDERLY_VIRTUAL_TESTNET_RPC/verify/etherscan
 
forge verify-contract $COUNTER_ADDRESS  \
Counter \
--etherscan-api-key $TENDERLY_ACCESS_KEY \
--verifier-url $TENDERLY_VERIFIER_URL \
--watch