# Quick Start

The OpenMSCP SDK provides a straightforward way to interact with the OpenMSCP protocol. This guide will walk you through the basic setup and usage.

### Basic Setup

First, ensure you have the necessary dependencies installed:

```typescript
import { OpenMSCPClient } from 'openmscp-sdk';
import { Connection, Keypair } from '@solana/web3.js';
import { Wallet } from '@project-serum/anchor';
```

### Connecting to the Network

The SDK supports different Solana networks (mainnet, devnet, testnet). Here's how to initialize the connection:

```typescript
// For devnet
const connection = new Connection('https://api.devnet.solana.com');

// For mainnet
const connection = new Connection('https://api.mainnet-beta.solana.com');
```

### Initializing the Client

The `OpenMSCPClient` is the main entry point for all SDK operations. You can initialize it in several ways:

```typescript
// Using a Keypair
const wallet = Keypair.generate();
const client = new OpenMSCPClient(connection, wallet);

// Using a Wallet adapter
const wallet = new Wallet(adapter);
const client = new OpenMSCPClient(connection, wallet);
```

### Basic Usage Examples

#### Profile Management

```typescript
// Create a profile
const profile = await client.profile.create({
  username: 'alice',
  bio: 'Blockchain enthusiast',
  profilePicture: 'ipfs://QmHash...'
});

// Update a profile
await client.profile.update({
  bio: 'Updated bio',
  profilePicture: 'ipfs://QmNewHash...'
});

// Get a profile
const profile = await client.profile.get(publicKey);
```

#### Post Management

```typescript
// Create a post
const post = await client.post.create('Hello, OpenMSCP!');

// Get posts
const posts = await client.post.getAll();
const userPosts = await client.post.getByUser(publicKey);

// Interact with posts
await client.post.like(postId);
await client.post.comment(postId, 'Great post!');
```

#### Messaging

```typescript
// Send a message
const message = await client.message.send(
  recipientPublicKey,
  'This is an encrypted message'
);

// Get messages
const messages = await client.message.getThread(recipientPublicKey);
const allMessages = await client.message.getAll();
```

### Error Handling

The SDK provides comprehensive error handling:

```typescript
try {
  const profile = await client.profile.create({
    username: 'alice',
    bio: 'Blockchain enthusiast'
  });
} catch (error) {
  if (error instanceof ProfileError) {
    console.error('Profile creation failed:', error.message);
  } else if (error instanceof NetworkError) {
    console.error('Network error:', error.message);
  }
}
```

### Configuration Options

The client can be configured with various options:

```typescript
const client = new OpenMSCPClient(connection, wallet, {
  commitment: 'confirmed',
  timeout: 30000,
  preflightCommitment: 'processed'
});
```
