# Magicblock Operations

The Prismon SDK provides a convenient interface for interacting with the MagicBlock platform on Solana. It offers methods for player management, leaderboard operations, score submission, and achievement handling.

### Initialization

```typescript
import { createPrismonClient } from '@prismon/sdk';

const client = createPrismonClient({
  apiKey: 'your-api-key-here',        // Your Prismon API key
  appId: 'your-app-id',               // Your application ID
  logger: boolean,                    // Logger implementation
});
```

### Wallet Setup

The SDK requires a wallet object with the following interface:

```typescript
interface WalletProps {
  publicKey: PublicKey | null; // The public key of the wallet
  signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>; // Transaction signing function
  signMessage?: ((message: Uint8Array) => Promise<Uint8Array>) | undefined; // Optional message signing function
}
```

### API Methods

#### 1. Player Management

**Register a Player**

Register a new player in the system.

```typescript
async function registerPlayerExample() {
  const request: PlayerRequest = {
    userPublicKey: wallet.publicKey.toString(),
    username: 'solana_player_42', // Must be unique
    nftMeta: 'https://nft.storage/player-identity.json'
  };
  
  const PROGRAM_ID = 'your-program-id'; // Solana program ID
  
  const response = await client.magicBlock.registerPlayer(
    request,
    wallet,
    PROGRAM_ID
  );
  console.log('Player registered:', response.data.transactionId);
}
```

**Get Player Information**

Retrieve information about a registered player.

```typescript
async function getPlayerInfo(playerPublicKey: string) {
  const response = await client.magicBlock.getPlayer(
    playerPublicKey,
    PROGRAM_ID
  );
  console.log('Player data:', response.data);
}
```

#### 2. Leaderboard Operations

**Create a Leaderboard**

Create a new leaderboard for your game.

```typescript
async function createGameLeaderboard() {
  const request: LeaderboardRequest = {
    gamePublicKey: GAME_PUBLIC_KEY,
    description: 'Weekly Tournament - Season 3',
    nftMeta: 'https://nft.storage/leaderboard-rewards.json',
    scoresToRetain: 1000, // Keep top 1000 scores
  };

  const response = await client.magicBlock.createLeaderboard(
    request,
    wallet,
    PROGRAM_ID
  );
  console.log('Leaderboard created:', response.data);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lucky-israel.gitbook.io/prismon-docs/features/integrations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
