@cherrydotfun/stem-sdk
v1.0.2
Published
SDK for the Stem protocol on Solana: account abstractions, peer-to-peer chat, protocol transactions.
Readme
stem-sdk
TypeScript/Node.js SDK for interacting with the Stem protocol on the Solana blockchain.
Provides abstractions for account management, peer-to-peer chat, group chats, and protocol-specific transactions.
Features
- Solana Account Abstractions: Classes for managing Solana accounts, connections, and signatures
- Peer-to-Peer Chat: Manage peer lists, invitations, and encrypted chat channels between wallets
- Group Chats: Create and manage group chats with different group types
- Protocol Transactions: Helpers for registration, inviting, accepting/rejecting peers, and sending messages
- Borsh Serialization: Uses borsh schemas for efficient on-chain data encoding/decoding
- Event-driven: Emits events for account and chat updates
Installation
npm install @cherrydotfun/stem-sdkUsage
import { Connection, Account } from "@cherrydotfun/stem-sdk/dist/solana";
import { Stem } from "@cherrydotfun/stem-sdk/dist/stem";
import { PublicKey } from "@solana/web3.js";
// Connect to Solana
const conn = new Connection("https://api.mainnet-beta.solana.com");
// Your wallet public key
const myPubkey = new PublicKey("...");
// Create Stem instance
const stem = new Stem(myPubkey, conn, true);
// Register, invite, accept, send messages, etc.API Overview
Solana Abstractions
Connection: Wraps Solana RPC/WebSocket, provides account management and airdropAccount: Represents a Solana account, supports fetching and subscribing to changesSignature: Handles transaction signature status and confirmation
Stem Protocol
Stem: Main class for protocol logic (registration, peer management, chat, groups)init(): Loads and subscribes to descriptor and chat accountscreateRegisterTx(): Returns a transaction for registeringcreateInviteTx(pubkey, message): Returns a transaction to invite a peercreateAcceptTx(pubkey): Accepts an invitecreateRejectTx(pubkey): Rejects an invitecreateSendMessageTx(pubkey, message): Sends a message to a peercreateCreateGroupTx(type, title, description, image_url): Creates a group chatcreateSendMessageToGroupTx(group, content): Sends a message to a groupcreateInviteToGroupTx(group, invitee): Invites to a groupcreateAcceptInviteToGroupTx(group): Accepts a group invitecreateJoinGroupTx(group): Joins a public group- Event emitters:
onChatsUpdated,onStatusUpdated,onChatUpdated,onGroupsUpdated
Helpers
helpers.getDescriptorPda(pubkey): Returns PDA for a wallet descriptorhelpers.getChatPda(pubkey, peer): Returns PDA for a private chathelpers.getChatHash(pubkey, peer): Deterministic hash for chathelpers.getNewGroupPda(pubkey, groups_count): Returns PDA for a new grouphelpers.getdisc(name): Generates discriminator for global name
Types
PeerStatus:Invited,Requested,Accepted,RejectedGroupPeerStatus:Invited,Joined,Rejected,Left,KickedDescriptor,Peer,Chat,Message,GroupDescriptorand their borsh-encoded variants
Constants
PROGRAM_ID: Stem protocol program ID on SolanaSEED_DESCRIPTOR,SEED_PRIVATE_CHAT,SEED_GROUP_DESCRIPTOR: Seeds for PDA derivation
Dependencies
@solana/web3.js^1.98.2borsh^2.0.0buffer^6.0.3crypto-js^4.2.0
Development
- TypeScript, CommonJS output
- Node.js >= 16
- No tests included by default
- See
src/for implementation details
License
MIT
