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

# Ephemeral SPL Token クイックスタート

> ephemeral-rollups-sdk を使って SPL token account を Ephemeral Rollup に委任し、ER 上で送金して base layer に出金します。

***

<Tip>
  **AI コーディングエージェントで開発していますか？** MagicBlock Dev Skill をインストールすると、デリゲーションフロー、Magic Actions、Crank、VRF など、MagicBlock 固有の開発パターンをエージェントに提供できます。

  Claude Code でのクイックインストール：

  ```bash theme={null}
  npx add-skill https://github.com/magicblock-labs/magicblock-dev-skill
  ```

  Cursor、Codex、Windsurf、Cline などをお使いの場合は、[AI Dev Skill](/jp/pages/overview/additional-information/ai-dev-skill) ページですべてのインストール方法をご確認ください。
</Tip>

### クイックアクセス

サンプルを確認：

<CardGroup cols={2}>
  <Card title="GitHub" icon="github" href="https://github.com/magicblock-labs/magicblock-engine-examples/tree/main/spl-tokens" iconType="duotone">
    SPL Token の Anchor 実装
  </Card>

  <Card title="ライブサンプルアプリ" icon="coins" href="https://one.magicblock.app/" iconType="duotone">
    プライベート決済を試す
  </Card>
</CardGroup>

<Note>
  これらのスニペットは、legacy-vault パスを使う `@magicblock-labs/ephemeral-rollups-sdk`
  **v0.14.3** 向けです。idempotent-shuttle パスは v0.15.3 向けです。1 つのライフサイクルでは
  `delegateSpl` / `undelegateIx` / `withdrawSpl` に同じパスを使用してください。
</Note>

***

## ステップ別ガイド

Ephemeral SPL Token プログラム `SPLxh1LVZzEkX99H6rqYizhytLWPZVV296zyYDPagv2` で
SPL token のライフサイクル全体を実行します。[委任](/jp/pages/ephemeral-rollups-ers/introduction/ephemeral-accounts)し、
[ER](/jp/pages/ephemeral-rollups-ers/introduction/ephemeral-rollup) 上で取引してから Solana に決済します：

<Steps>
  <Step title={<a href="#1-delegate">token account を委任</a>}>
    base layer 上で所有者の残高を validator に委任します。mint の初回委任時に共有
    Global Vault が作成されます。
  </Step>

  <Step title={<a href="#2-transfer">ER 上で送金</a>}>
    rollup 内の eATA 間で token を公開またはプライベートに移動します。
  </Step>

  <Step title={<a href="#3-undelegate">委任解除してコミット</a>}>
    ER 上で委任を解除し、base layer へのコミットを待ちます。
  </Step>

  <Step title={<a href="#4-withdraw">base layer に出金</a>}>
    残高を Global Vault から base-layer token account に移動します。
  </Step>
</Steps>

***

## Ephemeral SPL Token の例

以下のソフトウェアパッケージが必要になる場合があります。ほかのバージョンでも互換性がある可能性があります。

| ソフトウェア     | バージョン   | インストールガイド                                                       |
| ---------- | ------- | --------------------------------------------------------------- |
| **Solana** | 3.1.9   | [Solana をインストール](https://docs.anza.xyz/cli/install)             |
| **Rust**   | 1.89.0  | [Rust をインストール](https://www.rust-lang.org/tools/install)         |
| **Anchor** | 1.0.2   | [Anchor をインストール](https://www.anchor-lang.com/docs/installation) |
| **Node**   | 24.10.0 | [Node をインストール](https://nodejs.org/en/download/current)          |

SDK をインストールします：

```bash theme={null}
yarn add @magicblock-labs/ephemeral-rollups-sdk@0.14.3
```

### コードスニペット

<Tabs>
  <Tab title="1. 委任">
    `delegateSpl` は所有者の残高を validator に委任します。mint の初回委任時に共有 Global Vault
    を作成し（`initVaultIfMissing: true`）、以降は再利用します。**base layer** 上で送信し、
    委任前に rent sponsor（`deriveRentPda()`）へ資金を入れてください。

    ```typescript theme={null}
    // Legacy vault flow — keep the same idempotent setting across
    // delegateSpl / undelegateIx / withdrawSpl within one lifecycle.
    const delegateOpts = { validator, idempotent: false as const, payer: admin.publicKey };

    const ixs = await delegateSpl(owner.publicKey, mint.publicKey, amount, {
      ...delegateOpts,
      initVaultIfMissing, // true for the first owner of this mint, false after
    });

    await provider.sendAndConfirm(
      new anchor.web3.Transaction().add(...ixs),
      [owner, admin],
      { commitment: "confirmed", skipPreflight: true },
    );
    ```

    [⬆️ トップに戻る](#code-snippets)
  </Tab>

  <Tab title="2. 送金">
    `transferSpl` は rollup 内の eATA 間で token を移動します。**ephemeral** provider で送信します。
    プライベート決済には `visibility: "private"`、通常の高速送金には `"public"` を設定します。

    ```typescript theme={null}
    // Delegation confirms on base before the ER clones the account —
    // poll the ER view before transferring.
    await waitForErTokenAccount(ata, expectedAmount);

    const transferIxs = await transferSpl(
      recipientA.publicKey,
      recipientB.publicKey,
      mint.publicKey,
      2n,
      { visibility: "public", fromBalance: "ephemeral", toBalance: "ephemeral" },
    );

    await providerEphemeralRollup.sendAndConfirm(
      new anchor.web3.Transaction().add(...transferIxs),
      [recipientA],
      { commitment: "confirmed", skipPreflight: true },
    );
    ```

    [⬆️ トップに戻る](#code-snippets)
  </Tab>

  <Tab title="3. 委任解除">
    ER 上で所有者ごとに委任を解除し（1 トランザクションにつき 1 件）、出金前に
    `GetCommitmentSignature` で base layer へのコミットを待ちます。

    ```typescript theme={null}
    const sgn = await providerEphemeralRollup.sendAndConfirm(
      new anchor.web3.Transaction().add(undelegateIx(owner.publicKey, mint.publicKey)),
      [owner],
      { commitment: "confirmed", skipPreflight: true },
    );

    // Wait for the commit back to base before withdrawing, or the withdraw
    // races the commit and fails with InvalidAccountOwner.
    const commit = await GetCommitmentSignature(sgn, providerEphemeralRollup.connection);
    await connection.confirmTransaction(commit, "confirmed");
    ```

    [⬆️ トップに戻る](#code-snippets)
  </Tab>

  <Tab title="4. 出金">
    `withdrawSpl` は残高を Global Vault から所有者の base-layer ATA に戻します。

    ```typescript theme={null}
    const withdrawIxs = await withdrawSpl(owner.publicKey, mint.publicKey, amount, {
      idempotent: false,
    });

    await provider.sendAndConfirm(
      new anchor.web3.Transaction().add(...withdrawIxs),
      [owner],
      { commitment: "confirmed" },
    );
    ```

    [⬆️ トップに戻る](#code-snippets)
  </Tab>

  <Tab title="ER 対応プログラム">
    SDK helper ではなく独自プログラム経由で ER 側の送金を処理するには、`#[ephemeral]`
    属性を追加します。この命令は通常の SPL Token CPI です。カストディと PDA 署名送金については
    [スマートコントラクト統合](/jp/pages/ephemeral-spl-token/smart-contract-integration)を参照してください。

    ```rust theme={null}
    use anchor_lang::prelude::*;
    use anchor_spl::token::{self, Token, TokenAccount, Transfer as SplTransfer};
    use ephemeral_rollups_sdk::anchor::ephemeral;

    #[ephemeral]
    #[program]
    pub mod spl_tokens {
        use super::*;

        /// Transfer `amount` of SPL tokens from `from` to `to`.
        pub fn transfer(ctx: Context<TransferTokens>, amount: u64) -> Result<()> {
            require!(amount > 0, ErrorCode::InvalidAmount);
            let cpi_accounts = SplTransfer {
                from: ctx.accounts.from.to_account_info(),
                to: ctx.accounts.to.to_account_info(),
                authority: ctx.accounts.payer.to_account_info(),
            };
            let cpi_ctx = CpiContext::new(ctx.accounts.token_program.to_account_info(), cpi_accounts);
            token::transfer(cpi_ctx, amount)?;
            Ok(())
        }
    }
    ```

    [⬆️ トップに戻る](#code-snippets)
  </Tab>
</Tabs>

<Note>
  **ローカルで実行：** `yarn` → `yarn build` → `yarn setup`（ローカルの base + ER
  クラスターを起動し、そのまま実行）→ 2 つ目のターミナルで `yarn test:local`。
</Note>

***

## Solana エクスプローラー

Solana 上のトランザクションとアカウントの情報を確認できます。

<CardGroup cols={2}>
  <Card title="Solana エクスプローラー" icon="search" href="https://explorer.solana.com/" iconType="duotone">
    公式 Solana エクスプローラー
  </Card>

  <Card title="Solscan" icon="searchengin" href="https://solscan.io/" iconType="duotone">
    Solana ブロックチェーンを探索する
  </Card>
</CardGroup>

## Solana RPC プロバイダー

既存の RPC プロバイダーを通じてトランザクションやリクエストを送信します。

<CardGroup cols={2}>
  <Card title="Solana" icon="star" href="https://solana.com/docs/references/clusters#on-a-high-level" iconType="duotone">
    Free Public Nodes
  </Card>

  <Card title="Helius" icon="sun" href="https://www.helius.dev/solana-rpc-nodes" iconType="duotone">
    Free Shared Nodes
  </Card>

  <Card title="Triton" icon="crystal-ball" href="https://triton.one/solana" iconType="duotone">
    Dedicated High-Performance Nodes
  </Card>
</CardGroup>

## Solana バリデータダッシュボード

Solana バリデータインフラのリアルタイム更新を確認できます。

<CardGroup cols={2}>
  <Card title="Solana Beach" icon="wave" href="https://solanabeach.io/" iconType="duotone">
    Get Validator Insights
  </Card>

  <Card title="Validators App" icon="cloud-binary" href="https://www.validators.app/" iconType="duotone">
    Discover Validator Metrics
  </Card>
</CardGroup>

## サーバーステータス

Solana と MagicBlock のサーバーステータスを確認しましょう。

<CardGroup cols={2}>
  <Card title="Solana Status" icon="server" href="https://status.solana.com/" iconType="duotone">
    Subscribe to Solana Server Updates
  </Card>

  <Card title="MagicBlock Status" icon="heart-pulse" href="/jp/pages/overview/additional-information/system-status" iconType="duotone">
    Subscribe to MagicBlock Server Status
  </Card>
</CardGroup>

***

## MagicBlock 製品

<CardGroup cols={2}>
  <Card title="エフェメラルロールアップ（ER）" icon="bolt" href="/jp/pages/ephemeral-rollups-ers/how-to-guide/quickstart" iconType="duotone">
    Solana 上でリアルタイムかつ手数料ゼロのトランザクションを安全に実行します。
  </Card>

  <Card title="プライベート・エフェメラルロールアップ（PER）" icon="shield-check" href="/jp/pages/private-ephemeral-rollups-pers/how-to-guide/quickstart" iconType="duotone">
    コンプライアンスを保ちながら機密データを保護 — Ephemeral Rollups の上に構築されています。
  </Card>

  <Card title="Ephemeral SPL Token" icon="coins" href="/jp/pages/ephemeral-spl-token/overview" iconType="duotone">
    rollup の速度で SPL token を移動 — 公開・プライベート送金、swap、取引・DeFi アプリ向けのプライベート決済に対応します。
  </Card>

  <Card title="予測市場と取引" icon="chart-line" href="/pages/solutions/prediction-markets" iconType="duotone">
    リアルタイム実行、session key、token custody、価格フィード、自動化、決済を組み合わせます。
  </Card>

  <Card title="Solana VRF" icon="dice" href="/jp/pages/verifiable-randomness-functions-vrfs/introduction/solana-vrf" iconType="duotone">
    ゲーム、抽選、リアルタイムアプリに証明可能に公平なオンチェーンランダムネスを追加します。
  </Card>

  <Card title="価格オラクル" icon="waveform" href="/jp/pages/tools/oracle/introduction" iconType="duotone">
    取引や DeFi 向けの低遅延オンチェーン価格フィードにアクセスできます。
  </Card>
</CardGroup>

***
