Verify a smart contract on Monad using Foundry
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.
- Foundry Monad template (Recommended)
- Default Foundry Project
If you are using foundry-monad
template, you can use the commands below based on your preferred block explorer:
- MonadExplorer
- Monadscan
- Socialscan
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-testnetAttempting 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 MonadExplorer.
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/0x8fec29bded7a618ab6e3cd945456a79163995769Contract 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.
forge verify-contract \ <contract_address> \ <contract_name> \ --chain 10143 \ --watch \ --etherscan-api-key <your_api_key> \ --verifier-url https://api.socialscan.io/monad-testnet/v1/explorer/command_api/contract \ --verifier etherscan
Example:
forge verify-contract \ 0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \ Counter \ --chain 10143 \ --watch \ --etherscan-api-key test \ --verifier-url https://api.socialscan.io/monad-testnet/v1/explorer/command_api/contract \ --verifier etherscan
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: `Contract successfully verified` GUID: `33588004868f0677a3c23734da00fc42895a63542f61b1ed0dbfd2eb6893d7f4` URL: https://api.socialscan.io/monad-testnet/v1/explorer/command_api/address/0x8fec29bded7a618ab6e3cd945456a79163995769Contract verification status:Response: `OK`Details: `Pass - Verified`Contract successfully verified
Now check the contract on Socialscan.
If you use foundry-monad
you can skip the configuration step
1. Update foundry.toml
with Monad Configuration
1234567891011
[profile.default]src = "src"out = "out"libs = ["lib"]metadata = truemetadata_hash = "none" # disable ipfsuse_literal_content = true # use source code# Monad Configurationeth-rpc-url="https://testnet-rpc.monad.xyz"chain_id = 10143
2. Verify the contract using one of the following block explorers:
- MonadExplorer
- Monadscan
- Socialscan
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-testnetAttempting 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 MonadExplorer.
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.monadexplorer.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769Contract 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.
forge verify-contract \ <contract_address> \ <contract_name> \ --chain 10143 \ --watch \ --etherscan-api-key <your_api_key> \ --verifier-url https://api.socialscan.io/monad-testnet/v1/explorer/command_api/contract \ --verifier etherscan
Example:
forge verify-contract \ 0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \ Counter \ --chain 10143 \ --watch \ --etherscan-api-key test \ --verifier-url https://api.socialscan.io/monad-testnet/v1/explorer/command_api/contract \ --verifier etherscan
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: `Contract successfully verified` GUID: `33588004868f0677a3c23734da00fc42895a63542f61b1ed0dbfd2eb6893d7f4` URL: https://testnet.monadexplorer.com/address/0x8fec29bded7a618ab6e3cd945456a79163995769Contract verification status:Response: `OK`Details: `Pass - Verified`Contract successfully verified
Now check the contract on Socialscan.