Verify a smart contract on Monad using Foundry
Contents4 sections
Once your contract is deployed to a live network, the next step is to verify its source code on the block explorer.
Verifying a contract means uploading its source code, along with the settings used to compile the code, to a repository (typically maintained by a block explorer). This allows anyone to compile it and compare the generated bytecode with what is deployed on chain. Doing this is extremely important in an open platform like Monad.
In this guide we'll explain how to do this using Foundry v1.8 or later with the Monad execution environment enabled.
This guide assumes you have Foundry v1.8.0 or later installed and network = "monad" configured in foundry.toml. See the installation and configuration instructions if you haven't set it up yet.
Mainnet
Foundry Monad template (Recommended)
The foundry-monad template is configured for testnet by default. To use mainnet, update your foundry.toml file:
- Change
eth-rpc-url="https://testnet-rpc.monad.xyz"to your mainnet RPC URL - Change
chain_id = 10143to143
If you are using foundry-monad template, you can use the commands below based on your preferred block explorer:
MonadVision
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-mainnet
Attempting to verify on Sourcify. Pass the --etherscan-api-key <API_KEY> to verify on Etherscan, or use the --verifier flag to verify on another provider.
Submitting verification for [Counter] "0x8fEc29BdEd7A618ab6E3CD945456A79163995769".
Contract successfully verified
Now check the contract on MonadVision.
Monadscan
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-mainnet
Submitting verification for [src/Counter.sol:Counter] 0x8fEc29BdEd7A618ab6E3CD945456A79163995769.
Submitted contract for verification:
Response: `OK`
GUID: `fhxxx4wsub68jce24ejvhe68fqabgtpmpzheqpdqvencgph1za`
URL: https://monadscan.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending...; waiting 15 seconds before trying again (7 tries remaining)
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
Now check the contract on Monadscan.
Default Foundry Project
1. Update foundry.toml with Monad Configuration
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
metadata = true
metadata_hash = "none" # disable ipfs
use_literal_content = true # use source code
# Monad Configuration
eth-rpc-url="https://rpc.monad.xyz"
chain_id = 143
2. Verify the contract using one of the following block explorers:
MonadVision
If you are using MonadVision, you can use this guide. In particular, the Verify Contract page provides a convenient way to verify your contract.
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-mainnet
Attempting to verify on Sourcify. Pass the --etherscan-api-key <API_KEY> to verify on Etherscan, or use the --verifier flag to verify on another provider.
Submitting verification for [Counter] "0x8fEc29BdEd7A618ab6E3CD945456A79163995769".
Contract successfully verified
Now check the contract on MonadVision.
Monadscan
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-mainnet
Submitting verification for [src/Counter.sol:Counter] 0x8fEc29BdEd7A618ab6E3CD945456A79163995769.
Submitted contract for verification:
Response: `OK`
GUID: `fhxxx4wsub68jce24ejvhe68fqabgtpmpzheqpdqvencgph1za`
URL: https://monadscan.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending...; waiting 15 seconds before trying again (7 tries remaining)
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
Now check the contract on Monadscan.
Testnet
Foundry Monad template (Recommended)
If you are using foundry-monad template, you can use the commands below based on your preferred block explorer:
MonadVision
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 10143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 10143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-testnet
Attempting to verify on Sourcify. Pass the --etherscan-api-key <API_KEY> to verify on Etherscan, or use the --verifier flag to verify on another provider.
Submitting verification for [Counter] "0x8fEc29BdEd7A618ab6E3CD945456A79163995769".
Contract successfully verified
Now check the contract on MonadVision.
Monadscan
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 10143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 10143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-testnet
Submitting verification for [src/Counter.sol:Counter] 0x8fEc29BdEd7A618ab6E3CD945456A79163995769.
Submitted contract for verification:
Response: `OK`
GUID: `fhxxx4wsub68jce24ejvhe68fqabgtpmpzheqpdqvencgph1za`
URL: https://testnet.monadscan.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending...; waiting 15 seconds before trying again (7 tries remaining)
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
Now check the contract on Monadscan.
Default Foundry Project
If you use foundry-monad you can skip the configuration step
1. Update foundry.toml with Monad Configuration
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
metadata = true
metadata_hash = "none" # disable ipfs
use_literal_content = true # use source code
# Monad Configuration
eth-rpc-url="https://testnet-rpc.monad.xyz"
chain_id = 10143
2. Verify the contract using one of the following block explorers:
MonadVision
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 10143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 10143 \
--verifier sourcify \
--verifier-url https://sourcify-api-monad.blockvision.org/
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-testnet
Attempting to verify on Sourcify. Pass the --etherscan-api-key <API_KEY> to verify on Etherscan, or use the --verifier flag to verify on another provider.
Submitting verification for [Counter] "0x8fEc29BdEd7A618ab6E3CD945456A79163995769".
Contract successfully verified
Now check the contract on MonadVision.
Monadscan
forge verify-contract \
<contract_address> \
<contract_name> \
--chain 10143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
Example:
forge verify-contract \
0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
Counter \
--chain 10143 \
--verifier etherscan \
--etherscan-api-key YourApiKeyToken \
--watch
On successful verification of smart contract, you should get a similar output in your terminal:
Start verifying contract `0x8fEc29BdEd7A618ab6E3CD945456A79163995769` deployed on monad-testnet
Submitting verification for [src/Counter.sol:Counter] 0x8fEc29BdEd7A618ab6E3CD945456A79163995769.
Submitted contract for verification:
Response: `OK`
GUID: `fhxxx4wsub68jce24ejvhe68fqabgtpmpzheqpdqvencgph1za`
URL: https://testnet.monadvision.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending...; waiting 15 seconds before trying again (7 tries remaining)
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
Now check the contract on Monadscan.