> ## 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="/ko/pages/ephemeral-rollups-ers/how-to-guide/quickstart" iconType="duotone">
    ER 사용을 처음부터 끝까지 살펴보는 가이드
  </Card>

  <Card title="Magic Router" icon="route" href="/ko/pages/ephemeral-rollups-ers/introduction/magic-router" iconType="duotone">
    Router 개요와 흐름
  </Card>
</CardGroup>
