> 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/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 vòng chưa đầy 5 phút. Hướng dẫn này dành cho [**Hadrian**](/vi/mang/hadrian.md), chuỗi testnet công khai. [Rubicon](/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 test 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). Gọi hợp đồng từ ví Solana cần một ví ký được 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](/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/`     |
| Mã Chain            | `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, mà trên Hadrian là USDC. Trên Hadrian, nó được bảo chứng bởi Solana Devnet USDC của Circle (mint `4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU`), vì vậy devnet SOL không phải là gas. Không có faucet của Rome. Có hai cách để đưa USDC lên Hadrian:

**Từ Solana** — lấy Solana Devnet USDC từ [faucet Circle](https://faucet.circle.com/) (chọn Solana Devnet) và một ít devnet SOL cho 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](/vi/ung-dung-tren-rome/bridge-api.md) với Hadrian là đích đến 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 claim trên Hadrian, giao dịch này chuyển USDC thành gas.

**Bằng cách bridge từ một chuỗi EVM** — mint USDC test trên Ethereum Sepolia từ [faucet Circle](https://faucet.circle.com/), rồi chuyển nó sang Rome bằng [Cầu Rome](/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 [Faucets](/vi/tai-nguyen/faucets.md) cho từng faucet.

**Bao nhiêu?** Một lần ghi trên Rome tốn nhiều hơn trực giác về Ethereum gợi ý, vì phần lớn gas của nó trả cho việc tạo 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. Hãy dùng `eth_estimateGas`, mà công cụ tiêu chuẩn vốn làm vậy, và đừng bao giờ hardcode 21,000. Ước tính bao gồm việc tạo tài khoản, Rome tính phí gas mà một giao dịch thực sự dùng (trong các phép đo trên Hadrian thì điều đó chưa bao giờ vượt quá ước tính), và `submitRomeTx` của SDK cộng thêm 1.3x vào ước tính như một biên an toàn, điều này không tốn gì vì chỉ gas đã dùng mới bị tính phí. Nạp ít nhất **0.5 USDC gas**; 1 USDC sẽ chừa ra một khoảng thoải mái. Các con số trong [Hỗ trợ JSON-RPC](/vi/tai-lieu-tham-khao/json-rpc.md) cho thấy chi phí của từng lần ghi riêng lẻ.

Nếu một lần nạp từ phía Solana thất bại với cảnh báo "insufficient SOL" dù ví đã có tiền, hãy đặt ví Solana của bạn sang Chế độ Testnet / Devnet (xem [Câu hỏi thường gặp](/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 mặc định khi được nhắc — Hardhat 3, thư mục hiện tại, và mẫu TypeScript + Node Test Runner + viem — rồi để nó cài các phụ thuộc. Mẫu này đi kèm một ví dụ `Counter` hợp đồng kèm theo 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 đã tạo `hardhat.config.ts` và thêm các mạng Rome 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 private key MetaMask của bạn:

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

(Đối với bất cứ thứ gì vượt quá một key dùng một lần, hãy ưu tiên keystore được mã hóa đi kèm với 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 = "Xin chào từ 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 đã được triển khai tới:", 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ả đầu ra mong đợi (địa chỉ của bạn sẽ khác):

```
HelloRome deployed to: 0x09c437e305eeb698e1776cff23ca16c1bb25aabd
Counter: 1
Greeting: Xin chào từ Solana!
```

Mở địa chỉ đã triển khai trong [trình khám phá](https://via-hadrian.testnet.romeprotocol.xyz/) để xem các chỉ thị Solana phía sau giao dịch của bạn. Hợp đồng Solidity của bạn hiện đang chạy trên Solana.

## Tiếp theo là gì

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

## Các 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 giới hạn gas nhân với giá gas | Nạp ít nhất 0.5 USDC gas (xem bước 2) với [Cầu Rome](/vi/ung-dung-tren-rome/bridge-api.md) |
| `nonce quá thấp`          | Sai khớp nonce của giao dịch                         | Đặ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 của hợp đồng; dùng `eth_call` để gỡ lỗi                                     |
| Hết thời gian chờ kết nối | RPC không truy cập được                              | 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/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.
