# Get Started

### Installation <a href="#installation" id="installation"></a>

Install the SDK and dependencies

```typescript
yarn add @prismon/sdk @solana/web3.js @solana/wallet-adapter-react @solana/wallet-adapter-wallets @solana/wallet-adapter-react-ui @solana/wallet-adapter-solflare bs58
```

### Prerequisites

Before using the createSolanaClient, ensure you have:

* **Node.js**: Version 16 or higher.
* **Solana Wallet**: A Solana-compatible wallet (e.g., Phantom, Solflare) with signTransaction and signMessage capabilities.
* **Prismon SDK**: Installed via npm or yarn.
* **API Key and App ID**: Obtained from the Prismon dashboard.
* **Solana RPC URL**: Access to a Solana RPC endpoint (e.g., <https://api.devnet.solana.com> for Devnet).
* **TypeScript (Optional)**: For type-safe development.

### Initialization

To use any method from Prismon, you must first initialize a PrismonClient using the `createPrismonClient` function. The client requires configuration parameters, including an **API key**, **base URL (optional)**, **app ID**, and **Solana RPC URL (optional).**

#### Example Initialization

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

const client = createPrismonClient({
  apiKey: 'prismon_17d6102e_app88ab15b9', // Your Prismon API key
  baseUrl: 'http://localhost:5122', // Prismon backend URL
  appId: '77ec7ed8-163f-49f8-a0ba-7e8693eb728f', // Your app ID
  solanaRpcUrl: 'https://api.devnet.solana.com', // Solana RPC endpoint
  enableLogging: true, // Enable debug logging
});
```

#### Configuration Parameters

| Parameter     | Type   | Description                                                                    |
| ------------- | ------ | ------------------------------------------------------------------------------ |
| apiKey        | string | Your Prismon API key, obtained from the Prismon dashboard.                     |
| baseUrl       | string | The base URL of the Prismon backend (e.g., <http://localhost:5122> for local). |
| appId         | string | Your application ID, a UUID provided obtained from Prismon dashboard.          |
| solanaRpcUrl  | string | Solana RPC endpoint (e.g., <https://api.devnet.solana.com> for Devnet).        |
| enableLogging | string | Enables debug logging for API requests and responses.                          |

Set up environment variables: Create a `.env` file in your project root

```typescript
PRISMON_API_KEY=prismon_215ccfbf_app48482f62
PRISMON_API_URL=https://api.prismon.io
SOLANA_RPC_URL=https://api.devnet.solana.com
PRISMON_APP_ID=77ec7ed8-163f-49f8-a0ba-7e8693eb728f
```

Replace `PRISMON_API_KEY` with your production API key and `PRISMON_API_URL` with your API endpoint.

## Quickstart

Create a basic React app to test wallet login and Walrus storage.

#### Setup wallet providers

```typescript
import React, { useState, useEffect } from 'react';
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { WalletProvider } from '@solana/wallet-adapter-react';
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
import { WalletModalProvider, WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import { useWallet } from '@solana/wallet-adapter-react';
import { createPrismonClient } from '@prismon/sdk';
import '@solana/wallet-adapter-react-ui/styles.css';

const client = createPrismonClient({
  apiKey: import.meta.env.PRISMON_API_KEY,
  appId: import.meta.env.PRISMON_APP_ID
  baseUrl: import.meta.env.PRISMON_API_URL,
  solanaRpcUrl: import.meta.env.SOLANA_RPC_URL,
  enableLogging: true,
});

export const App = () => {
  const { publicKey, signMessage, connected } = useWallet();
  const [message, setMessage] = useState<string>('');

  useEffect(() => {
    if (connected && publicKey && signMessage) {
      const login = async () => {
        const response = await client.users.getChallenge(publicKey.toBase58());
        if (response.success) {
          const { challenge, challengeId } = response.data;
          const loginResponse = await client.users.loginWallet(
            { publicKey, signMessage },
            challenge,
            challengeId
          );
          if (loginResponse.success) {
            client.setJwtToken(loginResponse.data.token);
            setMessage(`Logged in: ${loginResponse.data.userId}`);
          } else {
            setMessage(`Login failed: ${loginResponse.error}`);
          }
        }
      };
      login();
    }
  }, [connected, publicKey, signMessage]);

  return (
    <WalletProvider wallets={[
      new PhantomWalletAdapter(),
      new SolflareWalletAdapter({ network: WalletAdapterNetwork.Devnet }),
    ]} autoConnect={false}>
      <WalletModalProvider>
        <div style={{ padding: '20px' }}>
          <WalletMultiButton />
          <h2>Prismon SDK Demo</h2>
          <p>{message || 'Connect your wallet to start'}</p>
        </div>
      </WalletModalProvider>
    </WalletProvider>
  );
};
```

## Run the app:

```typescript
yarn run dev
```

### Test the app

* Open [http://localhost:5173](http://localhost:5173/)
* Connect a Solana wallet (Phantom or Solflare, set to devnet)
* Verify automatic login and JWT storage.

### Next Step

1. Explore **Authentication.**
2. Learn about **Walrus Operations** for decentralized storage.
3. Check the **API Reference** for detailed method documentation.


---

# 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/getting-started/quickstart.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.
