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

# Client Implementation

> Client-side guide to building with Magic Actions

***

### Quick Access

> [card] [Magic Actions Example](https://github.com/magicblock-labs/magicblock-engine-examples/tree/main/magic-actions/anchor)
>
> Explore reference implementation on GitHub

***

### Setup Router Connection

Use Magic Router to route and send transactions to ER and base layer.

```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",
});
```

### Transaction Flow

1. Delegate counter to ER

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

2. Increment counter on ER in real-time

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

3. Commit with Magic Action

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

### Examples

> [card] [Quickstart Ephemeral Rollups](https://docs.magicblock.gg/pages/ephemeral-rollups-ers/how-to-guide/quickstart.md)
>
> End-to-end walkthrough on ER usage

> [card] [Magic Router](https://docs.magicblock.gg/pages/ephemeral-rollups-ers/introduction/magic-router.md)
>
> Router overview and flow


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.