pnp-sdk
v0.2.3
Published
Production-ready SDK for Solana prediction markets: create markets, trade, and redeem positions.
Readme
pnp-sdk
Production-ready SDK for Solana prediction markets: create markets, trade, and redeem positions.
Install
npm i pnp-sdkUsage (Node)
Environment Setup
Create a .env file with the following variables:
# Solana RPC URL (mainnet, devnet, testnet, or local)
RPC_URL=https://api.devnet.solana.com
# Wallet private key (as Base58 string or array)
WALLET_SECRET_BASE58=YourBase58EncodedPrivateKeyHere
# OR as array
WALLET_SECRET_ARRAY=[38,217,47,162,6,...] # your array of numbers
# Program ID is embedded in the program IDL; no env needed
# Optional: Mint addresses for market creation
BASE_MINT=YourBaseMintAddressHere
QUOTE_MINT=YourQuoteMintAddressHereWith Base58 Private Key
import { PNPClient } from "pnp-sdk";
import bs58 from "bs58";
import * as dotenv from "dotenv";
dotenv.config();
const maybePk = process.env.WALLET_SECRET_BASE58 ? bs58.decode(process.env.WALLET_SECRET_BASE58) : undefined;
const client = new PNPClient(process.env.RPC_URL!, maybePk);
// Read-only
const global = await client.fetchGlobalConfig();
// With private key present, you can access write modules:
// await client.trading!.buyTokensUsdc(...)With Private Key Array
import { PNPClient } from "pnp-sdk";
import * as dotenv from "dotenv";
dotenv.config();
const privateKeyArray = JSON.parse(process.env.WALLET_SECRET_ARRAY!);
const privateKeyBytes = new Uint8Array(privateKeyArray);
const client = new PNPClient(process.env.RPC_URL!, privateKeyBytes);Development
- Build:
npm run build - Test:
npm test - Typecheck:
npm run typecheck
REST API Server
The SDK includes an Express server implementation that allows you to create markets via HTTP endpoints:
# Start the API server
npm run api:server
# Access the API at http://localhost:3000API Endpoints
GET /health- Health check endpointPOST /create-market- Create a new market- Request body:
{ "question": "Your market question here" }
- Request body:
Command Line Interface
You can also create markets directly from the command line:
# Create a market with a specific question
npm run api:server "Will this market prediction come true?"Example Response
{
"success": true,
"txSignature": "2NPJ3NCuP1EZpN8DAwyjUgKJbRNZ6ZzmLSz8gXq3wMARMjeY3Y8xpGKUQo4hjiP7eoqAa6bHLNvWUbHMRGZ1sk9n",
"market": "CL9tjeJL38C3KyVvUxSHiiMzfvvB6gNn6TCweE9TH45t",
"yesTokenMint": "BzPKqzBNKw3hjj7BNn6oT7GXG3LKv7R1mFQby5bAYvdG",
"noTokenMint": "5ctuKQpZMQ2HoMvjXZHxAT3QxCN5mq8Ss1U5YCvFg8aZ",
"marketDetails": {
"id": "42",
"question": "Will this market prediction come true?",
"creator": "BUbQNJKKRvZesSPbgJyw1nHDRNMn7demZjcaqWpLXcFe",
"initialLiquidity": "50000000",
"marketReserves": "50000000",
"yesTokenSupply": "50000000",
"noTokenSupply": "50000000",
"endTime": "2025-08-27T19:12:28.000Z",
"resolved": false
}
}Next steps
- Replace placeholder instruction data encodings with your program's IDL/Borsh schemas.
- Add account metas per instruction (vaults, ATAs, mints, PDAs).
- Expand tests to integration against
solana-test-validator.
