Skip to main content

Foundry Verify

Kaiascan supports two methods for verifying contracts with Foundry: Standard JSON and Flattened.

Recommended

Standard JSON verification is the recommended method. It preserves the original multi-file project structure and handles complex projects (e.g., contracts with libraries or imports) more reliably than flattening.


You can verify contracts directly using the Standard JSON input format without needing to flatten your source files. This is the preferred approach as it supports multi-file projects and preserves the original contract structure.

Mainnet

forge verify-contract --verifier-url https://mainnet-api.kaiascan.io/forge-verify \
--chain-id 8217 \
{CONTRACT_ADDRESS} src/{CONTRACT_FILE}.sol:{CONTRACT_NAME} \
--retries 1

Kairos

forge verify-contract --verifier-url https://kairos-api.kaiascan.io/forge-verify \
--chain-id 1001 \
{CONTRACT_ADDRESS} src/{CONTRACT_FILE}.sol:{CONTRACT_NAME} \
--retries 1

Option Descriptions

  • {CONTRACT_ADDRESS}: The address of the deployed contract.
  • {CONTRACT_FILE}: The Solidity source file name (e.g., Counter).
  • {CONTRACT_NAME}: The name of the contract to verify (e.g., Counter).
  • [--constructor-args] (Optional): The ABI-encoded constructor arguments used when deploying the contract.
    • Single address argument: pass the raw address directly (e.g., 0x55CC196858E370B2b33B5B03e3312EdBFcBd9897)
    • Multiple or complex arguments: use cast abi-encode to generate the encoded value
      # Example: constructor(address _addr, string memory _text)
      cast abi-encode "constructor(address,string)" 0x55CC...9897 "Hello"
      Then pass the output to --constructor-args
  • [--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 src/libs/Lib1.sol:Lib1:0x1234... \
      --libraries src/libs/Lib2.sol:Lib2:0x5678...

Flattened Verification

If you prefer to use flattened contract files, you can flatten your contract before verifying.
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).
  • [--constructor-args] (Optional): The ABI-encoded constructor arguments used when deploying the contract.
    • Single address argument: pass the raw address directly (e.g., 0x55CC196858E370B2b33B5B03e3312EdBFcBd9897)
    • Multiple or complex arguments: use cast abi-encode to generate the encoded value
      # Example: constructor(address _addr, string memory _text)
      cast abi-encode "constructor(address,string)" 0x55CC...9897 "Hello"
      Then pass the output to --constructor-args
  • [--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...

Troubleshooting

If you encounter any issues during the verification process, please contact us through our support page with details about the error.

Contact Support for Contract Verification Issues


Additional Resources