> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Foundry 在 Monad 上验证智能合约

一旦您的合约部署到线上网络，下一步就是在区块浏览器上验证其源代码。

验证合约意味着将其源代码以及编译该代码时使用的设置上传到一个仓库
（通常由区块浏览器维护）。这样任何人都可以编译它并将生成的
字节码与链上部署的进行比较。在像 Monad 这样的开放平台上，这样做极其重要。

在本指南中，我们将解释如何使用 [Foundry](https://docs.monad.xyz/zh/tooling-and-infra/toolkits/foundry.md) v1.8 或更高版本，并启用 Monad 执行环境来完成此操作。

> [!TIP]
>
> 本指南假设您已安装 Foundry v1.8.0 或更高版本，并在 `foundry.toml` 中配置了 `network = "monad"`。如果尚未设置，请参见[安装与配置说明](https://docs.monad.xyz/zh/tooling-and-infra/toolkits/foundry.md#installation)。

> [tab] 主网
>
> > [tab] Foundry Monad 模板（推荐）
> >
> > > [!NOTE]
> > >
> > > [`foundry-monad`](https://github.com/monad-developers/foundry-monad) 模板默认为测试网配置。要使用主网，请更新您的 `foundry.toml` 文件：
> > >
> > > * 将 `eth-rpc-url="https://testnet-rpc.monad.xyz"` 改为您的主网 RPC URL
> > > * 将 `chain_id = 10143` 改为 `143`
> >
> > 如果您使用 [`foundry-monad`](https://github.com/monad-developers/foundry-monad) 模板，可以根据您首选的区块浏览器使用以下命令：
> >
> > > [tab] MonadVision
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 MonadVision 上查看合约。
> >
> > > [tab] Monadscan
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 Monadscan 上查看合约。
>
> > [tab] 默认 Foundry 项目
> >
> > ## 1. 使用 Monad 配置更新 `foundry.toml`
> >
> > ```toml lines title="foundry.toml" theme={null}
> > [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. 使用以下区块浏览器之一验证合约：
> >
> > > [tab] MonadVision
> > >
> > > > [!NOTE]
> > > >
> > > > 如果您使用 MonadVision，可以使用
> > > > [本指南](https://docs.blockvision.org/reference/verify-smart-contract-on-monad-explorer#/)。
> > > > 特别是，[Verify Contract](https://monadvision.com/verify-contract)
> > > > 页面提供了一种便捷的合约验证方式。
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 MonadVision 上查看合约。
> >
> > > [tab] Monadscan
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 Monadscan 上查看合约。

> [tab] 测试网
>
> > [tab] Foundry Monad 模板（推荐）
> >
> > 如果您使用 [`foundry-monad`](https://github.com/monad-developers/foundry-monad) 模板，可以根据您首选的区块浏览器使用以下命令：
> >
> > > [tab] MonadVision
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 10143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 10143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 [MonadVision](https://testnet.monadvision.com/) 上查看合约。
> >
> > > [tab] Monadscan
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 10143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 10143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 [Monadscan](https://testnet.monadscan.com/) 上查看合约。
>
> > [tab] 默认 Foundry 项目
> >
> > > [!TIP]
> > >
> > > 如果您使用 [`foundry-monad`](https://github.com/monad-developers/foundry-monad)，可以跳过配置步骤
> >
> > ## 1. 使用 Monad 配置更新 `foundry.toml`
> >
> > ```toml lines title="foundry.toml" theme={null}
> > [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. 使用以下区块浏览器之一验证合约：
> >
> > > [tab] MonadVision
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 10143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 10143 \
> > >     --verifier sourcify \
> > >     --verifier-url https://sourcify-api-monad.blockvision.org/
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 [MonadVision](https://testnet.monadvision.com/) 上查看合约。
> >
> > > [tab] Monadscan
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     <contract_address> \
> > >     <contract_name> \
> > >     --chain 10143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > **示例：**
> > >
> > > ```sh theme={null}
> > > forge verify-contract \
> > >     0x8fEc29BdEd7A618ab6E3CD945456A79163995769 \
> > >     Counter \
> > >     --chain 10143 \
> > >     --verifier etherscan \
> > >     --etherscan-api-key YourApiKeyToken \
> > >     --watch
> > > ```
> > >
> > > 智能合约验证成功后，您应该在终端中看到类似如下的输出：
> > >
> > > ```sh theme={null}
> > > 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
> > > ```
> > >
> > > 现在到 [Monadscan](https://testnet.monadscan.com/) 上查看合约。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.