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

# クライアント実装

> Magic Actions を構築するためのクライアント側ガイド

***

### クイックアクセス

<CardGroup cols={2}>
  <Card title="Magic Actions Example" icon="code" href="https://github.com/magicblock-labs/magicblock-engine-examples/tree/main/magic-actions" iconType="duotone">
    GitHub でリファレンス実装を見る
  </Card>
</CardGroup>

***

### Router 接続のセットアップ

Magic Router を使って、ER とベースレイヤーにトランザクションをルーティングして送信します。

<CodeGroup>
  ```typescript Kit theme={null}
  import { Connection } from "@magicblock-labs/ephemeral-rollups-kit";

  // Initialize connection
  const connection = await Connection.create(
    "https://devnet-router.magicblock.app",
    "wss://devnet-router.magicblock.app"
  );

  // ... create transaction

  // Send and confirm transaction
  const txHash = await connection.sendAndConfirmTransaction(
    transactionMessage,
    [userKeypair],
    { commitment: "confirmed", skipPreflight: true }
  );
  ```

  ```typescript Web3.js theme={null}
  import { sendAndConfirmTransaction } from "@solana/web3.js";
  import { ConnectionMagicRouter } from "@magicblock-labs/ephemeral-rollups-sdk";

  // Initialize connection
  const connection = new ConnectionMagicRouter(
    "https://devnet-router.magicblock.app/",
    { wsEndpoint: "wss://devnet-router.magicblock.app/" }
  );

  // ... create transaction

  // Send and confirm transaction
  const txHash = await sendAndConfirmTransaction(connection, tx, [payer], {
    skipPreflight: true,
    commitment: "confirmed",
  });
  ```
</CodeGroup>

### トランザクションフロー

1. カウンターを ER に委任する

```ts theme={null}
const delegateTx = await program.methods
  .delegate()
  .accounts({
    payer: anchor.Wallet.local().publicKey,
    pda: pda,
  })
  .transaction();
```

2. ER 上でカウンターをリアルタイムにインクリメントする

```ts theme={null}
const incrementTx = await program.methods
  .increment()
  .accounts({
    counter: pda,
  })
  .transaction();
```

3. Magic Action 付きでコミットする

```ts theme={null}
const commitTx = await program.methods
  .commitAndUpdateLeaderboard()
  .accounts({ payer: wallet.publicKey /* your accounts */ })
  .transaction();
```

### 例

<CardGroup cols={2}>
  <Card title="Quickstart Ephemeral Rollups" icon="play" href="/jp/pages/ephemeral-rollups-ers/how-to-guide/quickstart" iconType="duotone">
    ER 利用のエンドツーエンド解説
  </Card>

  <Card title="Magic Router" icon="route" href="/jp/pages/ephemeral-rollups-ers/introduction/magic-router" iconType="duotone">
    Router の概要とフロー
  </Card>
</CardGroup>
