> 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-ru-men/quickstart.md).

# 快速开始

在 5 分钟内在 Rome 上部署你的第一个 Solidity 合约。本指南面向 **Martius**，即公共测试网链；相同步骤也适用于 [Hadrian](/zh/wang-luo/hadrian.md) （devnet），只需替换网络值即可。

## 前提条件

* [Node.js](https://nodejs.org/) v22.13+
* [MetaMask](https://metamask.io/) 浏览器扩展
* 将一个 Solana 钱包（例如 Phantom）设置为 **Devnet**

## 1. 将 Martius 添加到 MetaMask

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

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

## 2. 为钱包充值

Gas 费用以该链的 SPL gas 代币支付（Martius 上为 USDC）。获取它有两种方式：

**从 Solana 获取** — 从 [Solana 水龙头](https://faucet.solana.com/) 获取 devnet SOL（将你的 Solana 钱包设置为 Devnet），然后打开 [Rome App](https://app.testnet.romeprotocol.xyz)，连接两个钱包，并将其兑换为 gas 代币。

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

**需要多少？** 在 Rome 上部署合约会产生 Solana 侧的账户成本，因此 gas 估算会明显高于 Ethereum 的直觉——快速入门合约估算约为 2000 万 gas，成本约为 **0.2 USDC** 即可部署，而钱包会在前端预检查大约两倍的估算值。至少充值 **0.5 USDC 的 gas**；1 USDC 会更宽裕。

如果 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` 并在 `defineConfig({ ... })`:

```typescript
  中添加 Rome 网络：
    martius: {
      type: "http",
      chainType: "l1",
      chainId: 121214,
      url: "https://martius.testnet.romeprotocol.xyz/",
      accounts: [configVariable("PRIVATE_KEY")],
    },
    rome_local: {
      type: "http",
      chainType: "l1",
      chainId: 1001,
      url: "http://localhost:9090",
      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;
});
```

部署到 Martius：

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

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

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

在 [区块浏览器](https://via-martius.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-ru-men/architecture.md) — Rome 如何在 Solana 内执行 EVM

## 常见错误

| 错误         | 原因                              | 修复                                                      |
| ---------- | ------------------------------- | ------------------------------------------------------- |
| `资金不足`     | gas 代币不足——钱包会预先检查约 2 倍的 gas 估算值 | 通过 [Rome App](https://app.testnet.romeprotocol.xyz) 或桥接 |
| `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 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/kuai-su-ru-men/quickstart.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.
