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();