> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Bắt đầu

> Sử dụng LiteSVM với @solana/kit để kiểm thử Solana nhanh, chạy ngay trong tiến trình

Các bộ kiểm thử Solana khởi chạy `solana-test-validator` mất vài giây cho mỗi bài kiểm thử —
bạn phải chờ khởi động tiến trình, kết nối RPC và các vòng trao đổi qua mạng.
LiteSVM chạy cùng những bài kiểm thử đó chỉ trong vài mili giây. Không cần tiến trình bên ngoài, không cần mạng,
tất cả diễn ra trong bộ nhớ ngay bên trong trình chạy kiểm thử của bạn.

<Info>
  **Đã kiểm thử với:** `@solana/kit@8.6.0`, `@solana/kit-plugin-litesvm@0.23.0`,
  `@solana/kit-plugin-signer@0.23.0`, `@solana-program/system@0.16.0`,
  `@solana-program/token@0.18.0` và `litesvm@1.6.1`. Các gói plugin này
  còn mới và thay đổi nhanh. Nếu gặp lỗi không khớp phiên bản, hãy cài đúng
  các phiên bản trên, ví dụ `npm install @solana/kit@8.6.0 @solana/kit-plugin-litesvm@0.23.0`.
</Info>

Bạn dựng một Kit client từ `@solana/kit` bằng cách cài đặt các plugin với
`.use()`: plugin signer
([`@solana/kit-plugin-signer`](https://www.npmjs.com/package/@solana/kit-plugin-signer)),
plugin LiteSVM
([`@solana/kit-plugin-litesvm`](https://www.npmjs.com/package/@solana/kit-plugin-litesvm)),
và bất kỳ plugin chương trình nào bạn cần. Kết quả cung cấp `client.sendTransaction()`,
`client.rpc`, cùng khả năng truy cập trực tiếp vào trạng thái tài khoản, đồng hồ và các sysvar — tất cả
mà không cần rời khỏi tiến trình của bạn.

## Bắt đầu nhanh

<Steps titleSize="h3">

<Step title="Cài đặt các thư viện phụ thuộc">
```bash
npm install @solana/kit @solana/kit-plugin-litesvm @solana/kit-plugin-signer @solana-program/system
```

</Step>

<Step title="Tạo client của bạn">
```typescript
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";

// Payer first, then the LiteSVM transport.
const mySigner = await generateKeyPairSigner();
const client = createClient().use(signer(mySigner)).use(litesvm());

// Fund the payer
client.svm.airdrop(client.payer.address, lamports(5_000_000_000n));

// Check the balance
const balance = client.svm.getBalance(client.payer.address);
console.log("Balance:", balance, "lamports");
```

<Info>
  `createClient()` trả về một vỏ rỗng — mỗi lệnh `.use(plugin)` bổ sung
  thêm các khả năng cho nó. Plugin `signer()` phải được đặt **trước** `litesvm()`,
  vì `litesvm()` đọc `client.payer` khi được cài đặt. `signer(mySigner)` là cách viết tắt để cài đặt cùng một keypair làm
  cả `payer` và `identity` — hãy dùng `payer()` hoặc `identity()` từ cùng
  gói nếu bạn muốn tách hai vai trò này.
</Info>

<Info>
  Muốn thiết lập một dòng cho các thử nghiệm nhanh? Hãy bỏ qua `signer()` và dùng
  `generatedPayer` và `airdropPayer` từ `@solana/kit-plugin-signer`:
  `const client = await createClient().use(generatedPayer()).use(litesvm()).use(airdropPayer(lamports(10_000_000_000n)));`
  `generatedPayer()` đặt trước `litesvm()`, còn `airdropPayer()` đặt sau nó
  vì cần hàm airdrop do `litesvm()` cung cấp. Đừng
  kết hợp chúng với `signer()` (payer sẽ bị định nghĩa hai lần).
</Info>

</Step>

</Steps>

## Tìm hiểu về Client

Sau `.use(signer(...)).use(litesvm())`, client cung cấp:

| Thuộc tính                    | Mô tả                                                                                                                                                                                              |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client.payer`              | `TransactionSigner` mà bạn đã cài đặt bằng plugin `signer()` (cũng được gán làm `client.identity`)                                                                                                         |
| `client.identity`           | Signer của ví sở hữu các tài khoản, token và quyền hạn                                                                                                                                            |
| `client.svm`                | Instance [`LiteSVM`](https://www.npmjs.com/package/litesvm) trực tiếp để quản lý tài khoản, giao dịch và cấu hình                                                                               |
| `client.rpc`                | Giao diện RPC tương thích với Kit (tập con: `getAccountInfo`, `getBalance`, `getEpochSchedule`, `getLatestBlockhash`, `getMinimumBalanceForRentExemption`, `getMultipleAccounts`, `getSlot`, `requestAirdrop`) |
| `client.sendTransaction(s)` | Lập kế hoạch, ký và gửi các instruction dưới dạng một giao dịch                                                                                                                                                       |
| `client.airdrop`            | Yêu cầu SOL từ faucet của LiteSVM                                                                                                                                                                      |
| `client.getMinimumBalance`  | Tính số lamport tối thiểu để được miễn rent                                                                                                                                                              |

### Sử dụng client.svm

Truy cập trực tiếp vào LiteSVM để:

- Quản lý tài khoản (`setAccount`, `getAccount`, `airdrop`)
- Thực thi giao dịch (`sendTransaction`, `simulateTransaction`)
- Cấu hình (`withSigverify`, `withBlockhashCheck`, v.v.)
- Điều khiển thời gian (`warpToSlot`, `getClock`)

```typescript
import { address, generateKeyPairSigner, lamports } from "@solana/kit";

const myAddress = (await generateKeyPairSigner()).address;

// Fund an account
client.svm.airdrop(myAddress, lamports(1_000_000_000n));

// Set account state directly
client.svm.setAccount({
  address: myAddress,
  data: new Uint8Array([1, 2, 3]),
  executable: false,
  lamports: lamports(1_000_000n),
  programAddress: address("11111111111111111111111111111111"),
  space: 3n
});

// Get the latest blockhash
const blockhash = client.svm.latestBlockhash();
```

### Sử dụng client.rpc

Giao diện RPC tương thích với Kit cho các thao tác tiêu chuẩn:

```typescript
// Get account info (returns base64-encoded data)
const { value: account } = await client.rpc.getAccountInfo(myAddress).send();

// Get multiple accounts in one call
const { value: accounts } = await client.rpc
  .getMultipleAccounts([myAddress, client.payer.address])
  .send();

// Get latest blockhash
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send();
```

<Warning>
  Lớp RPC chỉ hỗ trợ **mã hóa base64**. Yêu cầu các kiểu mã hóa khác
  sẽ gây ra lỗi.
</Warning>

## Cấu hình

Cấu hình LiteSVM bằng các phương thức builder trên `client.svm`:

```typescript
const client = createClient().use(signer(mySigner)).use(litesvm());

// Configure for testing
client.svm
  .withSigverify(false) // Skip signature verification
  .withBlockhashCheck(false) // Skip blockhash validation
  .withSysvars() // Reset Clock, Rent, and other sysvars to their defaults
  .withBuiltins() // Enable ed25519, secp256k1
  .withTransactionHistory(100n); // Store transaction history
```

## Gửi giao dịch

Thêm các plugin chương trình sau phần transport — chúng gắn các trình tạo instruction
vào client để bạn không bao giờ phải đụng đến `TransactionMessage` thô:

```typescript
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";
import { systemProgram } from "@solana-program/system";

const mySigner = await generateKeyPairSigner();
const client = createClient()
  .use(signer(mySigner))
  .use(litesvm())
  .use(systemProgram());

client.svm.airdrop(client.payer.address, lamports(10_000_000_000n));

const recipient = await generateKeyPairSigner();

// Build and send in one call
await client.system.instructions
  .transferSol({
    source: client.payer,
    destination: recipient.address,
    amount: lamports(1_000_000_000n)
  })
  .sendTransaction();
```

## Luồng SVM → RPC

Bạn có thể đặt trạng thái qua SVM và đọc nó qua RPC:

```typescript
import { address, lamports } from "@solana/kit";

// Set account directly via SVM
client.svm.setAccount({
  address: myAddress,
  data: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
  executable: false,
  lamports: lamports(1_000_000n),
  programAddress: address("11111111111111111111111111111111"),
  space: 4n
});

// Read via RPC (returns base64-encoded data)
const { value } = await client.rpc.getAccountInfo(myAddress).send();
console.log("Data:", value?.data); // ['3q2+7w==', 'base64']
```

## Tiếp theo

Phần này đã bao quát client cốt lõi — tạo tài khoản, gửi instruction và
đọc trạng thái. Nếu các bài kiểm thử của bạn liên quan đến token SPL (mint, ATA, chuyển token),
[hướng dẫn kiểm thử token](/developers/docs/tools/litesvm/typescript/tokens) sẽ cho thấy cách
plugin `tokenProgram()` rút gọn khoảng 40 dòng thiết lập chỉ còn 3 lệnh gọi. Để xem
tài liệu tham khảo API đầy đủ, hãy xem [tài liệu API](/developers/docs/tools/litesvm/typescript/api-reference).
