# 快速开始

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

## 前置条件

* [Node.js](https://nodejs.org/) v18+
* [MetaMask](https://metamask.io/) 浏览器扩展
* 一个带有 devnet SOL 的 Solana 钱包（用于 gas）

## 1. 将 Rome 网络添加到 MetaMask

打开 MetaMask → 设置 → 网络 → 添加网络：

| 字段      | 值                                          |
| ------- | ------------------------------------------ |
| 网络名称    | Rome Devnet                                |
| RPC URL | `https://montispl.devnet.romeprotocol.xyz` |
| 链 ID    | `200002`                                   |
| 货币符号    | `RSOL`                                     |
| 区块浏览器   | —                                          |

## 2. 为你的钱包充值

通过 [充值界面](https://deposit.devnet.romeprotocol.xyz)向你的 Rome EVM 地址存入 devnet SOL。连接你的 Solana 钱包（带有 devnet SOL）和 MetaMask，然后输入要存入的金额。该界面会将 SOL 按 1:1 转换为 RSOL，并将其记入你的 EVM 地址。

## 3. 创建 Hardhat 项目

```bash
mkdir rome-hello && cd rome-hello
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npx hardhat init
```

提示时选择“创建 JavaScript 项目”。

## 4. 为 Rome 配置 Hardhat

编辑 `hardhat.config.js`:

```javascript
require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  solidity: "0.8.28",
  networks: {
    rome_devnet: {
      url: "https://montispl.devnet.romeprotocol.xyz",
      chainId: 200002,
      accounts: [process.env.PRIVATE_KEY],
    },
    rome_local: {
      url: "http://localhost:9090",
      chainId: 1001,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};
```

导出你的 MetaMask 私钥：

```bash
export PRIVATE_KEY="0xYOUR_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.js`:

```javascript
const hre = require("hardhat");

async function main() {
  const HelloRome = await hre.ethers.getContractFactory("HelloRome");
  const hello = await HelloRome.deploy();
  await hello.waitForDeployment();

  const address = await hello.getAddress();
  console.log("HelloRome 已部署到:", address);

  // 调用合约
  const tx = await hello.greet();
  await tx.wait();

  const count = await hello.counter();
  console.log("计数器:", count.toString());

  const greeting = await hello.greeting();
  console.log("问候语:", greeting);
}

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

部署到 Rome devnet：

```bash
npx hardhat run scripts/deploy.js --network rome_devnet
```

预期输出：

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

你的 Solidity 合约现在已在 Solana 上运行。

## 下一步

* [部署 Solidity](/zh/kai-fa-zhe-zhi-nan/deploy-solidity.md) — 使用 Foundry 和 Hardhat 的详细部署指南
* [从 EVM 调用 Solana](/zh/kai-fa-zhe-zhi-nan/call-solana-from-evm.md) — 使用 CPI 从 Solidity 调用 Jupiter、Kamino 以及其他 Solana 程序
* [架构](/zh/ru-men/architecture.md) — 了解 Rome EVM 的底层工作原理

## 常见错误

| 错误         | 原因           | 修复                               |
| ---------- | ------------ | -------------------------------- |
| `资金不足`     | EVM 地址没有余额   | 通过充值界面存入 SOL                     |
| `nonce 过低` | 交易 nonce 不匹配 | 重置 MetaMask 账户（设置 → 高级 → 清除活动记录） |
| `执行被回滚`    | 合约执行失败       | 检查合约逻辑；使用 `eth_call` 进行调试        |
| 连接超时       | RPC 端点不可达    | 验证网络 URL；检查 devnet 是否正在运行        |


---

# Agent Instructions: 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:

```
GET https://docs.rome.builders/zh/ru-men/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
