> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/zh/kai-fa-zhe-zhi-nan/verify-contracts.md).

# 验证合约

通过托管的 Sourcify 服务在 Rome 上验证 Solidity 合约源码——标准的 forge verify-contract 和 hardhat-verify 流程，以及 Via 浏览器上的徽章。

Rome 提供一个托管的 [Sourcify](https://sourcify.dev) 验证服务。一旦您验证了合约，其源码和 ABI 就会变得可公开复现，并会显示一个 **✓ 源码已验证** 徽章，出现在 Rome 区块浏览器（Via）上。

验证可与标准的 `forge verify-contract` 和 `hardhat-verify` 流程配合使用——您只需将它们指向 Rome 的验证器。

## 验证器端点

| 环境          | 验证器 URL                                   |
| ----------- | ----------------------------------------- |
| 测试网与开发网     | `https://verify.testnet.romeprotocol.xyz` |
| 主网（Rubicon） | `https://verify.mainnet.romeprotocol.xyz` |

一个共享实例可服务于所有 Rome 测试网/开发网链——您只需使用标准的 `--chain-id` 标志来选择链。

## Foundry

部署后（参见 [部署 Solidity 合约](/zh/kai-fa-zhe-zhi-nan/deploy-solidity.md)):

```bash
forge verify-contract <CONTRACT_ADDRESS> src/MyContract.sol:MyContract \\
  --verifier sourcify \\
  --verifier-url https://verify.testnet.romeprotocol.xyz/ \\
  --chain-id <YOUR_CHAIN_ID> \\
  --compiler-version 0.8.20
```

如果构造函数接收参数，请将其一并传入，以便字节码匹配：

```bash
  --constructor-args $(cast abi-encode "constructor(uint256)" 42)
```

您也可以在部署时通过以下方式进行验证： `forge create … --verify` 或 `forge script … --verify` （Foundry 会从 `--rpc-url`).

## Hardhat

`hardhat-verify` 随 Hardhat 3 工具箱附带。请在 `hardhat.config.ts` 中将其 Sourcify 提供程序指向 Rome 的验证器，并运行 `hardhat verify`:

```typescript
export default defineConfig({
  // …plugins, solidity, networks…
  verify: {
    etherscan: { enabled: false },
    blockscout: { enabled: false },
    sourcify: {
      enabled: true,
      apiUrl: "https://verify.testnet.romeprotocol.xyz",   // Rubicon 主网："https://verify.mainnet.romeprotocol.xyz"
    },
  },
});
```

```bash
npx hardhat verify --network <your-network> <CONTRACT_ADDRESS> [constructor args…]
```

成功后，验证器会链接已发布的源码，例如 `https://verify.testnet.romeprotocol.xyz/repo-ui/<CHAIN_ID>/<ADDRESS>`.

## 检查验证状态

区块浏览器会从验证器的 API 读取验证状态。您可以直接查询：

```bash
curl https://verify.testnet.romeprotocol.xyz/v2/contract/<CHAIN_ID>/<ADDRESS>
```

已验证的合约会返回一个 `match` 字段：

* **`exact_match`** — 字节码 *和* 元数据哈希匹配（完全、"完整" 匹配）。
* **`match`** — 字节码匹配；元数据略有不同（仍然是真实、已验证的匹配）。
* `404` / `null` — 未验证。

## 说明

* 验证只需要您提交的合约已部署字节码 + 源码和编译器设置——与任何 EVM 链上的输入相同。
* 新的 Rome 链会自动接入验证器；如果您部署到一条新链上，而验证暂时还找不到它，请稍等片刻或与我们联系。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rome.builders/zh/kai-fa-zhe-zhi-nan/verify-contracts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
