Skip to main content

Foundry Verify

Currently, when verifying contracts on Kaiascan using Foundry, only flattened contract files are supported.
Ensure that your contract is flattened before proceeding with the verification process.
To flatten the contract, run the following command (replace with your actual contract file):

forge flatten src/Counter.sol > Flattened.sol

After flattening the contract, to verify using Foundry, run the following command:


Mainnet

forge verify-contract --verifier-url https://mainnet-api.kaiascan.io/forge-verify-flatten \
--chain-id 8217 --compiler-version {COMPILER_VERSION} \
{CONTRACT_ADDRESS} Flattened.sol:{CONTRACT_NAME} --retries 1

Kairos

forge verify-contract --verifier-url https://kairos-api.kaiascan.io/forge-verify-flatten \
--chain-id 1001 --compiler-version {COMPILER_VERSION} \
{CONTRACT_ADDRESS} Flattened.sol:{CONTRACT_NAME} --retries 1

Option Descriptions

  • {COMPILER_VERSION}: The Solidity compiler version (e.g., 0.8.28).
  • {CONTRACT_ADDRESS}: The address of the contract to verify.
  • {CONTRACT_NAME}: The name of the contract to verify (e.g., Counter).
  • [--retries N] (Optional): Number of retry attempts if verification fails (default: 5, but 1 is recommended).
  • [--via-ir] (Optional): Required if you deployed the contract with viaIR enabled. Either add --via-ir to the command or set via_ir = true in your foundry.toml.
  • [--libraries] (Optional): Required if your contract uses libraries that are compiled and deployed separately (linked libraries). Provide their deployed addresses by adding this option.
    • Specify libraries in the following format: --libraries {FILE_PATH}:{LIBRARY_NAME}:{LIBRARY_ADDRESS}
    • You can include multiple libraries by repeating this option. For example:
      --libraries Flattened.sol:Lib1:0x1234... \
      --libraries Flattened.sol:Lib2:0x5678...

Additional Resources