OpenMSCP
  • Welcome
    • Introduction
    • OpenMSCP
  • Tokenomics
  • OpenMSCP SDK
    • About
    • Prerequisities & Installation
    • Quick Start
    • SDK Core
      • Profiles
      • Posts
      • Messaging
    • Contributing
  • MSCP Social
    • What is MSCP Social?
    • Registration
    • Features
Powered by GitBook
On this page
  • Basic Setup
  • Connecting to the Network
  • Initializing the Client
  • Basic Usage Examples
  • Error Handling
  • Configuration Options
  1. OpenMSCP SDK

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:

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:

// 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:

// 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

// 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

// 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

// 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:

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:

const client = new OpenMSCPClient(connection, wallet, {
  commitment: 'confirmed',
  timeout: 30000,
  preflightCommitment: 'processed'
});
PreviousPrerequisities & InstallationNextSDK Core

Last updated 1 month ago