> 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/kuai-su-kai-shi/quickstart.md).

# 快速入门

在 5 分钟内将你的第一个 Solidity 合约部署到 Rome。

在 5 分钟内将你的第一个 Solidity 合约部署到 Rome。本指南面向 [**Hadrian**](/zh/wang-luo/hadrian.md)，即公开测试网链。 [Rubicon](/zh/wang-luo/rubicon.md) 是主网链，其中 gas 以真实 USDC 计价；请先在测试链上尝试所有操作。

## 前置条件

* [Node.js](https://nodejs.org/) v22.13+
* [MetaMask](https://metamask.io/) 浏览器扩展
* 一个设置为 **Devnet**，仅当你从 Solana 注资时（步骤 2）。从 Solana 钱包调用合约需要一个能够签署 Solana v1 交易的钱包，相关内容见 [向 Solana 用户开放你的合约](/zh/kai-fa-zhe-zhi-nan/open-to-solana-users.md).

## 1. 将 Hadrian 添加到 MetaMask

手动添加（设置 → 网络 → 添加网络）：

| 字段      | 值                                               |
| ------- | ----------------------------------------------- |
| 网络名称    | Rome Hadrian                                    |
| RPC URL | `https://hadrian.testnet.romeprotocol.xyz/`     |
| 链 ID    | `200010`                                        |
| 货币符号    | `USDC`                                          |
| 区块浏览器   | `https://via-hadrian.testnet.romeprotocol.xyz/` |

## 2. 为你的钱包注资

gas 以该链的 gas 代币支付，在 Hadrian 上即 USDC。在 Hadrian 上，它由 Circle 的 Solana Devnet USDC 支撑（铸币 `4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU`），因此 devnet SOL 不是 gas。Rome 没有水龙头。将 USDC 转入 Hadrian 有两种方式：

**从 Solana** — 从……获取 Solana Devnet USDC [Circle 水龙头](https://faucet.circle.com/) （选择 Solana Devnet），并从……获取少量用于 Solana 手续费的 devnet SOL [Solana 水龙头](https://faucet.solana.com/)，并将你的 Solana 钱包设置为 Devnet。然后使用 [Rome Bridge](/zh/rome-shang-de-ying-yong/bridge-api.md) 将 Hadrian 设为目标并使用其 Solana 路由，把你的 EVM 钱包地址作为收款人；桥接会要求该 EVM 钱包在 Hadrian 上签署一笔领取交易，从而把 USDC 转换为 gas。

**通过从 EVM 链桥接进入** — 从……在 Ethereum Sepolia 上铸造测试 USDC [Circle 水龙头](https://faucet.circle.com/)，然后使用……将其带到 Rome [Rome Bridge](/zh/rome-shang-de-ying-yong/bridge-api.md) （CCTP）。你需要少量 Sepolia ETH 用于源链交易——请参见 [水龙头](/zh/zi-yuan/faucets.md) 每个水龙头。

**需要多少？** 在 Rome 上的一次写入成本比你对 Ethereum 的直觉更高，因为大部分 gas 都用于创建 Solana 账户：一个从未使用过的接收方、一个新的代币账户、一个已部署的合约。使用 `eth_estimateGas`，标准工具也是这样做的，不要硬编码 21,000。该估算包含账户创建，Rome 按交易实际消耗的 gas 收费（在 Hadrian 的测量中从未超过估算），而 SDK 的 `submitRomeTx` 会将估算额外乘以 1.3 作为余量，而这不会带来额外成本，因为只会按实际使用的 gas 收费。至少注入 **0.5 USDC 的 gas**；1 USDC 留出充足余量。以下数字 [JSON-RPC 支持](/zh/can-kao/json-rpc.md) 显示单次写入的成本。

如果在钱包已注资的情况下，Solana 侧存入仍然出现“insufficient SOL”警告，请将你的 Solana 钱包设置为 Testnet Mode / Devnet（参见 [常见问题](/zh/zi-yuan/faq.md)).

## 3. 创建一个 Hardhat 项目

```bash
mkdir rome-hello && cd rome-hello
npx hardhat --init
```

在提示时接受默认值——Hardhat 3、当前目录，以及 TypeScript + Node Test Runner + viem 模板——并让它安装依赖。该模板附带一个示例 `Counter` 合约及其测试；它们不会影响本指南。

## 4. 为 Rome 配置 Hardhat

编辑生成的 `hardhat.config.ts` 并在其中添加 Rome 网络配置 `defineConfig({ ... })`:

```typescript
  networks: {
    hadrian: {
      type: "http",
      chainType: "l1",
      chainId: 200010,
      url: "https://hadrian.testnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
  },
```

`configVariable("PRIVATE_KEY")` 会从环境变量解析，因此导出你的 MetaMask 私钥：

```bash
export PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
```

（对于任何不只是临时使用的密钥，建议使用工具箱自带的加密密钥库： `npx hardhat keystore set PRIVATE_KEY`.)

## 5. 编写合约

创建 `contracts/HelloRome.sol`:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract HelloRome {
    string public greeting = "来自 Solana 的问候！";
    uint256 public counter;

    event Greeted(address indexed sender, uint256 count);

    function greet() external returns (string memory) {
        counter++;
        emit Greeted(msg.sender, counter);
        return greeting;
    }

    function setGreeting(string calldata _greeting) external {
        greeting = _greeting;
    }
}
```

## 6. 部署

创建 `scripts/deploy.ts`:

```typescript
import hardhat from "hardhat";

async function main() {
  const { viem } = await hardhat.network.connect();
  const publicClient = await viem.getPublicClient();

  const hello = await viem.deployContract("HelloRome");
  console.log("HelloRome 部署到：", hello.address);

  const hash = await hello.write.greet();
  await publicClient.waitForTransactionReceipt({ hash });

  console.log("计数器：", (await hello.read.counter()).toString());
  console.log("问候语：", await hello.read.greeting());
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

部署到 Hadrian：

```bash
npx hardhat run scripts/deploy.ts --network hadrian
```

预期输出（你的地址会不同）：

```
HelloRome 部署到： 0x09c437e305eeb698e1776cff23ca16c1bb25aabd
计数器：1
问候语：来自 Solana 的问候！
```

在……中打开已部署地址 [浏览器](https://via-hadrian.testnet.romeprotocol.xyz/) 以查看你的交易背后的 Solana 指令。你的 Solidity 合约现在运行在 Solana 上。

## 接下来

* [部署 Solidity](/zh/kai-fa-zhe-zhi-nan/deploy-solidity.md) — 深入了解 Hardhat 和 Foundry 部署
* [从 EVM 调用 Solana](/zh/kai-fa-zhe-zhi-nan/call-solana-from-evm.md) — 通过 CPI 从 Solidity 调用 Solana 程序
* [架构](/zh/kuai-su-kai-shi/architecture.md) — Rome 如何在 Solana 内执行 EVM

## 常见错误

| 错误         | 原因                            | 解决方法                                                                                    |
| ---------- | ----------------------------- | --------------------------------------------------------------------------------------- |
| `资金不足`     | gas 代币不足，无法覆盖 gas 限额乘以 gas 价格 | 至少注入 0.5 USDC 的 gas（见步骤 2），并使用 [Rome Bridge](/zh/rome-shang-de-ying-yong/bridge-api.md) |
| `nonce 过低` | 交易 nonce 不匹配                  | 重置账户（MetaMask → 设置 → 高级 → 清除活动记录）                                                       |
| `执行回退`     | 合约执行失败                        | 检查合约逻辑；使用 `eth_call` 进行调试                                                               |
| 连接超时       | RPC 无法访问                      | 检查 RPC URL                                                                              |


---

# 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/kuai-su-kai-shi/quickstart.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.
