> 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 合约](https://docs.rome.builders/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`).

## 推断链 ID）

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

```typescript
export default defineConfig({
  // …插件、solidity、网络…
  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` — 未验证。

## 注意事项

* 在 Rome 验证器上完成验证的合约，会在 Rome Via（区块浏览器）中显示其合约名称。
* 对于可升级代理，除了代理合约，也要验证其实现合约。
* 验证只需要合约已部署的字节码，以及你提交的源代码和编译器设置——这与任何 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.
