> 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/vi/bat-dau-1/quickstart.md).

# Bắt đầu nhanh

Triển khai hợp đồng Solidity đầu tiên của bạn trên Rome trong chưa đầy 5 phút.

Triển khai hợp đồng Solidity đầu tiên của bạn trên Rome trong chưa đầy 5 phút. Hướng dẫn này nhắm tới [**Hadrian**](https://docs.rome.builders/vi/mang/hadrian.md), chuỗi testnet công khai. [Rubicon](https://docs.rome.builders/vi/mang/rubicon.md) là chuỗi mainnet, nơi gas là USDC thật; hãy thử mọi thứ trên một chuỗi thử nghiệm trước.

## Điều kiện tiên quyết

* [Node.js](https://nodejs.org/) v22.13+
* [MetaMask](https://metamask.io/) tiện ích mở rộng trình duyệt
* Một ví Solana được đặt thành **Devnet**, chỉ khi bạn nạp từ Solana (bước 2). Việc gọi hợp đồng từ ví Solana cần một ví ký các giao dịch Solana v1, điều này được đề cập trong [Mở hợp đồng của bạn cho người dùng Solana](https://docs.rome.builders/vi/huong-dan-cho-nha-phat-trien/open-to-solana-users.md).

## 1. Thêm Hadrian vào MetaMask

Thêm thủ công (Cài đặt → Mạng → Thêm mạng):

| Trường              | Giá trị                                         |
| ------------------- | ----------------------------------------------- |
| Tên mạng            | Rome Hadrian                                    |
| URL RPC             | `https://hadrian.testnet.romeprotocol.xyz/`     |
| ID chuỗi            | `200010`                                        |
| Ký hiệu tiền tệ     | `USDC`                                          |
| Trình khám phá khối | `https://via-hadrian.testnet.romeprotocol.xyz/` |

## 2. Nạp tiền vào ví của bạn

Gas được thanh toán bằng token gas của chuỗi, là USDC trên Hadrian. Trên Hadrian, nó được bảo chứng bởi USDC Solana Devnet của Circle (mint `4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU`), vì vậy SOL devnet không phải là gas. Không có faucet của Rome. Có hai cách để đưa USDC lên Hadrian:

**Từ Solana** — nhận Solana Devnet USDC từ [faucet Circle](https://faucet.circle.com/) (chọn Solana Devnet) và một ít SOL devnet để trả phí Solana từ [faucet Solana](https://faucet.solana.com/), với ví Solana của bạn được đặt thành Devnet. Sau đó dùng [Cầu Rome](https://docs.rome.builders/vi/ung-dung-tren-rome/bridge-api.md) với Hadrian làm đích và tuyến Solana của nó, với địa chỉ ví EVM của bạn làm người nhận; cầu nối yêu cầu ví EVM đó ký một giao dịch nhận trên Hadrian, biến USDC thành gas.

**Bằng cách cầu nối vào từ một chuỗi EVM** — đúc USDC thử nghiệm trên Ethereum Sepolia từ [faucet Circle](https://faucet.circle.com/), rồi chuyển nó sang Rome bằng [Cầu Rome](https://docs.rome.builders/vi/ung-dung-tren-rome/bridge-api.md) (CCTP). Bạn sẽ cần một ít Sepolia ETH cho giao dịch ở phía nguồn — xem [Vòi cấp tiền](https://docs.rome.builders/vi/tai-nguyen/faucets.md) cho từng faucet.

**Bao nhiêu?** Một thao tác ghi trên Rome tốn hơn những gì trực giác về Ethereum gợi ý, vì phần lớn gas của nó được dùng để tạo các tài khoản Solana: một người nhận chưa từng được dùng, một tài khoản token mới, một hợp đồng đã triển khai. Dùng `eth_estimateGas`, điều mà các công cụ tiêu chuẩn thực hiện, và đừng bao giờ mã hóa cứng 21.000. Ước tính đã bao gồm việc tạo tài khoản, Rome tính phí theo lượng gas mà giao dịch thực sự dùng (trong các phép đo trên Hadrian, điều đó không bao giờ vượt quá ước tính), và mức của SDK `submitRomeTx` nới ước tính lên 1,3 lần như một khoảng dự phòng, điều này không tốn thêm gì vì chỉ gas đã dùng mới bị tính phí. Hãy nạp ít nhất **0,5 USDC gas**; 1 USDC để lại khoảng dư thoải mái. [Hỗ trợ JSON-RPC](https://docs.rome.builders/vi/tai-lieu-tham-khao/json-rpc.md) cho thấy từng thao tác ghi tốn bao nhiêu.

Nếu một khoản nạp ở phía Solana thất bại với cảnh báo "insufficient SOL" dù ví đã được nạp tiền, hãy đặt ví Solana của bạn sang Chế độ Testnet / Devnet (xem [Câu hỏi thường gặp](https://docs.rome.builders/vi/tai-nguyen/faq.md)).

## 3. Tạo một dự án Hardhat

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

Chấp nhận các giá trị mặc định khi được hỏi — Hardhat 3, thư mục hiện tại, và mẫu TypeScript + Node Test Runner + viem — rồi để nó cài đặt các phụ thuộc. Mẫu này đi kèm một ví dụ `Counter` hợp đồng kèm các bài kiểm thử; chúng không ảnh hưởng đến hướng dẫn này.

## 4. Cấu hình Hardhat cho Rome

Chỉnh sửa file được tạo ra `hardhat.config.ts` và thêm các mạng Rome vào bên trong `defineConfig({ ... })`:

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

`configVariable("PRIVATE_KEY")` được lấy từ môi trường, vì vậy hãy xuất khóa riêng MetaMask của bạn:

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

Với bất kỳ thứ gì vượt quá một khóa dùng một lần, hãy ưu tiên kho khóa được mã hóa đi kèm toolbox: `npx hardhat keystore set PRIVATE_KEY`.)

## 5. Viết một hợp đồng

Tạo `contracts/HelloRome.sol`:

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

contract HelloRome {
    string public greeting = "Hello from 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. Triển khai

Tạo `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 deployed to:", hello.address);

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

  console.log("Counter:", (await hello.read.counter()).toString());
  console.log("Greeting:", await hello.read.greeting());
}

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

Triển khai lên Hadrian:

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

Kết quả mong đợi (địa chỉ của bạn sẽ khác):

```
HelloRome đã được triển khai tới: 0x09c437e305eeb698e1776cff23ca16c1bb25aabd
Bộ đếm: 1
Lời chào: Hello from Solana!
```

Mở địa chỉ đã triển khai trong [explorer](https://via-hadrian.testnet.romeprotocol.xyz/) để xem giao dịch của bạn, và theo liên kết "Settled in" để đến giao dịch Solana đã xác nhận nó. Hợp đồng Solidity của bạn giờ đang chạy trên Solana.

## Tiếp theo là gì

* [Triển khai Solidity](https://docs.rome.builders/vi/huong-dan-cho-nha-phat-trien/deploy-solidity.md) — triển khai Hardhat và Foundry chuyên sâu
* [Gọi Solana từ EVM](https://docs.rome.builders/vi/huong-dan-cho-nha-phat-trien/call-solana-from-evm.md) — gọi chương trình Solana từ Solidity qua CPI
* [Kiến trúc](https://docs.rome.builders/vi/bat-dau-1/architecture.md) — cách Rome thực thi EVM bên trong Solana

## Lỗi thường gặp

| Lỗi                       | Nguyên nhân                                       | Cách khắc phục                                                                                                            |
| ------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `không đủ tiền`           | Không đủ token gas cho gas limit nhân với giá gas | Hãy nạp ít nhất 0,5 USDC gas (xem bước 2) bằng [Cầu Rome](https://docs.rome.builders/vi/ung-dung-tren-rome/bridge-api.md) |
| `nonce quá thấp`          | Nonce giao dịch không khớp                        | Đặt lại tài khoản (MetaMask → Cài đặt → Nâng cao → Xóa hoạt động)                                                         |
| `thực thi bị hoàn nguyên` | Thực thi hợp đồng thất bại                        | Kiểm tra logic hợp đồng; dùng `eth_call` để gỡ lỗi                                                                        |
| Hết thời gian kết nối     | Không thể truy cập RPC                            | Xác minh URL RPC                                                                                                          |


---

# 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/vi/bat-dau-1/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.
