> 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).

# 验证合约

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

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

## 验证器端点

| 环境      | 验证器 URL                                   |
| ------- | ----------------------------------------- |
| 测试网和开发网 | `https://verify.testnet.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",
    },
  },
});
```

```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>
```

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

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

## 说明

* 验证只需要你合约的已部署字节码 + 你提交的源码和编译器设置——与任何 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
