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

# はじめに

> @solana/kit と LiteSVM を使った、高速なプロセス内 Solana テスト

`solana-test-validator` を起動する Solana のテストスイートは、1テストあたり数秒かかります。プロセスの起動、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>

`@solana/kit` から Kit クライアントを組み立てるには、`.use()` でプラグインをインストールします。signer プラグイン([`@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>
  手軽な実験向けに 1 行でセットアップしたいですか? `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()` が提供するエアドロップ関数を必要とするため、`litesvm()` の後に置きます。`signer()` と組み合わせて使用しないでください(payer が二重に定義されてしまいます)。
</Info>

</Step>

</Steps>

## クライアントを理解する

`.use(signer(...)).use(litesvm())` の後、クライアントは次のプロパティを提供します。

| プロパティ                    | 説明                                                                                                                                                                                              |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client.payer`              | `signer()` プラグインでインストールした `TransactionSigner`(`client.identity` としても設定されます)                                                                                                         |
| `client.identity`           | アカウント、トークン、権限を所有するウォレット signer                                                                                                                                            |
| `client.svm`                | アカウント管理、トランザクション、設定のための [`LiteSVM`](https://www.npmjs.com/package/litesvm) インスタンスへの直接アクセス                                                                               |
| `client.rpc`                | Kit 互換の RPC インターフェース(サブセット: `getAccountInfo`、`getBalance`、`getEpochSchedule`、`getLatestBlockhash`、`getMinimumBalanceForRentExemption`、`getMultipleAccounts`、`getSlot`、`requestAirdrop`) |
| `client.sendTransaction(s)` | instructions をトランザクションとして構築・署名・送信します                                                                                                                                                       |
| `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
```

## トランザクションを送信する

トランスポートの後にプログラムプラグインを重ねます。プラグインは instruction ビルダーをクライアントに追加するため、生の `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']
```

## 次のステップ

ここまででコアとなるクライアント(アカウントの作成、instructions の送信、状態の読み取り)を一通り説明しました。テストで SPL トークン(mint、ATA、転送)を扱う場合は、[トークンテストガイド](/developers/docs/tools/litesvm/typescript/tokens)で、`tokenProgram()` プラグインによって約 40 行のセットアップをわずか 3 回の呼び出しにまとめる方法を紹介しています。API の完全なリファレンスについては、[API ドキュメント](/developers/docs/tools/litesvm/typescript/api-reference)をご覧ください。
