> ## 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.

# 快速入门

> 将 LiteSVM 与 @solana/kit 搭配使用，实现快速的进程内 Solana 测试

如果 Solana 测试套件依赖启动 `solana-test-validator`，每个测试都要耗费数秒——
你需要等待进程启动、RPC 连接和网络往返。
LiteSVM 运行相同的测试只需几毫秒。无需外部进程，无需网络，
一切都在测试运行器内的内存中完成。

<Info>
  **测试版本：** `@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` 以及 `litesvm@1.6.1`。这些插件包
  都比较新，变化很快。如果遇到版本不匹配的问题，请安装上述确切
  版本，例如 `npm install @solana/kit@8.6.0 @solana/kit-plugin-litesvm@0.23.0`。
</Info>

你可以通过 `.use()` 安装插件，基于 `@solana/kit` 组装 Kit 客户端：一个签名者插件
（[`@solana/kit-plugin-signer`](https://www.npmjs.com/package/@solana/kit-plugin-signer)）、
LiteSVM 插件
（[`@solana/kit-plugin-litesvm`](https://www.npmjs.com/package/@solana/kit-plugin-litesvm)），
以及你需要的任何程序插件。最终得到的客户端提供 `client.sendTransaction()`、
`client.rpc`，并可直接访问账户状态、时钟和 sysvar——全程
无需离开你的进程。

## 快速开始

<Steps titleSize="h3">

<Step title="安装依赖">
```bash
npm install @solana/kit @solana/kit-plugin-litesvm @solana/kit-plugin-signer @solana-program/system
```

</Step>

<Step title="创建客户端">
```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()` 返回一个空壳——每次 `.use(plugin)` 都会为其叠加
  新的能力。`signer()` 插件必须放在 `litesvm()` **之前**，
  因为 `litesvm()` 在安装时会读取 `client.payer`。`signer(mySigner)` 是将同一个 keypair 同时安装为
  `payer` 和 `identity` 的简写——如果你想把这两种角色分开，
  请使用同一软件包中的 `payer()` 或 `identity()`。
</Info>

<Info>
  想用一行代码快速搭建环境来做实验？可以跳过 `signer()`，改用
  `@solana/kit-plugin-signer` 中的 `generatedPayer` 和 `airdropPayer`：
  `const client = await createClient().use(generatedPayer()).use(litesvm()).use(airdropPayer(lamports(10_000_000_000n)));`
  `generatedPayer()` 放在 `litesvm()` 之前，而 `airdropPayer()` 放在其之后，
  因为它需要 `litesvm()` 提供的空投函数。请勿
  与 `signer()` 同时使用（否则 payer 会被定义两次）。
</Info>

</Step>

</Steps>

## 了解客户端

在执行 `.use(signer(...)).use(litesvm())` 之后，客户端会提供以下内容：

| 属性                    | 描述                                                                                                                                                                                              |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client.payer`              | 通过 `signer()` 插件安装的 `TransactionSigner`（同时也会被设置为 `client.identity`）                                                                                                         |
| `client.identity`           | 拥有账户、代币和权限的钱包签名者                                                                                                                                            |
| `client.svm`                | 直接访问 [`LiteSVM`](https://www.npmjs.com/package/litesvm) 实例，用于账户管理、交易和配置                                                                               |
| `client.rpc`                | 兼容 Kit 的 RPC 接口（子集：`getAccountInfo`、`getBalance`、`getEpochSchedule`、`getLatestBlockhash`、`getMinimumBalanceForRentExemption`、`getMultipleAccounts`、`getSlot`、`requestAirdrop`） |
| `client.sendTransaction(s)` | 将指令规划、签名并作为交易发送                                                                                                                                                       |
| `client.airdrop`            | 从 LiteSVM 水龙头申请 SOL                                                                                                                                                                      |
| `client.getMinimumBalance`  | 计算免除 rent 所需的最低 lamports                                                                                                                                                              |

### 使用 client.svm

可直接访问 LiteSVM，用于：

- 账户管理（`setAccount`、`getAccount`、`airdrop`）
- 交易执行（`sendTransaction`、`simulateTransaction`）
- 配置（`withSigverify`、`withBlockhashCheck` 等）
- 时间操控（`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();
```

### 使用 client.rpc

用于标准操作的、兼容 Kit 的 RPC 接口：

```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>
  RPC 层仅支持 **base64 编码**。请求其他编码
  将会抛出错误。
</Warning>

## 配置

使用 `client.svm` 上的构建器方法来配置 LiteSVM：

```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
```

## 发送交易

在传输层之后叠加程序插件——它们会把指令构建器
挂载到客户端上，这样你就无需直接处理原始的 `TransactionMessage`：

```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();
```

## SVM → RPC 流程

你可以通过 SVM 设置状态，再通过 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']
```

## 下一步

以上涵盖了核心客户端的用法——创建账户、发送指令以及
读取状态。如果你的测试涉及 SPL 代币（mint、ATA、转账），
[代币测试指南](/developers/docs/tools/litesvm/typescript/tokens)会展示
`tokenProgram()` 插件如何将约 40 行的设置代码精简为 3 次调用。完整的
API 参考，请参阅 [API 文档](/developers/docs/tools/litesvm/typescript/api-reference)。
