API Reference
Core Client
PNPClient
Main client class for interacting with the PNP protocol. This is the primary entry point for all SDK operations.
rpcUrl: The URL of the Solana RPC endpoint (e.g., ‘https://api.mainnet-beta.solana.com’)privateKey: (Optional) Private key for signing transactions, provided as:- Base58-encoded string
- Uint8Array containing raw bytes
- Object with secretKey property containing Uint8Array
- Without a private key, only read-only methods will be available
- With a valid private key, all modules (market, trading, redemption) are initialized
- The client automatically detects and supports both SPL Token and Token-2022 programs
SDK Module Structure
The PNP SDK is organized into modules for different functionality areas:-
Core Client Methods - Available directly on the
PNPClientinstance:redeemPosition- Redeem winning positions after market resolutionclaimMarketRefund- Claim refund for unresolvable marketsfetchMarket,fetchMarkets,fetchGlobalConfig- Read-only data methodsgetMarketPriceV2- Get real-time prices & multipliers for V2 AMM marketsfetchSettlementCriteria,getSettlementCriteria- Proxy server integrationfetchSettlementData,getSettlementData- Get market settlement detailsfetchMarketAddresses- Get all market addresses from proxy
-
Market Module - Available via
client.market(requires signer):createMarket- Create new prediction markets
-
Trading Module - Available via
client.trading(requires signer):buyOutcome- Buy YES/NO tokens with collateralsellOutcome- Sell YES/NO tokens for collateralgetMarketInfo- Get detailed market information
-
Redemption Module - Available via
client.redemption(requires signer):redeemPositionV2- Low-level position redemption (used by coreredeemPosition)creatorRefund,creatorRefundV2- Low-level refund methods
-
Anchor-based Modules - Available via
client.anchorMarketandclient.anchorClient(optional):- Provides Anchor program interfaces for advanced use cases
Main SDK Methods
redeemPosition(market: PublicKey, options?: RedeemPositionOptions): Promise<{ signature: string }>
Redeems a winning position in a resolved market. This is used to claim your winnings after a market has been resolved.
Parameters:
market: PublicKey - The market where the position was createdoptions: (Optional) Configuration objectadmin: PublicKey - Override the admin account from global configmarketCreator: PublicKey - Override the market creator from market accountcreatorFeeTreasury: PublicKey - Override the creator fee treasury account
claimMarketRefund(market: PublicKey): Promise<{ signature: string }>
Claims a refund for a market creator if the market is not resolvable. This method allows creators to retrieve their initial liquidity if the market cannot be resolved.
Parameters:
market: PublicKey - The market to claim the refund for
- Market must not be resolvable (checked via on-chain flag or proxy server)
- The caller (signer) must be the market creator
Read-Only Helpers
These methods are available even without providing a private key to the client constructor.fetchMarket(market: PublicKey): Promise<{ publicKey: PublicKey; account: MarketType }>
Fetches detailed information about a specific market.
Parameters:
market: PublicKey - The market to fetch information for
publicKey: PublicKey - The market’s public keyaccount: MarketType - The market account data
fetchMarkets(): Promise<MarketsResponse>
Fetches all available markets.
Returns: Promise that resolves to an object containing:
count: number - The number of markets founddata: Array of market objects with:publicKey: string - The market’s public key as a base58 stringaccount: MarketType - The market account data
fetchGlobalConfig(): Promise<{ publicKey: PublicKey; account: GlobalConfigType }>
Fetches the global configuration account for the PNP program.
Returns: Promise that resolves to an object containing:
publicKey: PublicKey - The global config account’s public keyaccount: GlobalConfigType - The global config account data
getMarketPriceV2(market: string | PublicKey): Promise<MarketPriceV2Data>
Fetches real-time price and multiplier data for a V2 AMM market. This is a read-only operation that doesn’t require a wallet or private key.
Parameters:
market: string | PublicKey - The V2 market address (as string or PublicKey)
MarketPriceV2Data object containing:
yesPrice: number - Current YES token price (0-1 range)noPrice: number - Current NO token price (0-1 range)yesMultiplier: number - Potential return multiplier if YES winsnoMultiplier: number - Potential return multiplier if NO winsmarketReserves: number - Total collateral in human-readable unitsyesTokenSupply: number - YES token supply in human-readable unitsnoTokenSupply: number - NO token supply in human-readable unitsmarketReservesRaw: string - Total collateral in raw base unitsyesTokenSupplyRaw: string - YES token supply in raw base unitsnoTokenSupplyRaw: string - NO token supply in raw base units
Proxy Server Integration
The SDK provides methods to interact with the PNP proxy server for fetching market data and settlement information.fetchSettlementCriteria(market: string | PublicKey, baseUrl?: string): Promise<SettlementCriteria>
Fetches settlement criteria for a market from the proxy server.
Parameters:
market: string | PublicKey - Market address (as string or PublicKey)baseUrl: string (Optional) - Base URL for the proxy server. Defaults to environment variable or hardcoded value.
getSettlementCriteria(market: string | PublicKey, baseUrl?: string, options?: { retryDelayMs?: number; maxRetryTimeMs?: number }): Promise<SettlementCriteria>
Gets settlement criteria with automatic retry logic. This is useful for waiting for criteria to become available.
Parameters:
market: string | PublicKey - Market address (as string or PublicKey)baseUrl: string (Optional) - Base URL for the proxy serveroptions: (Optional) Retry configurationretryDelayMs: number - Milliseconds to wait between retries (default: 2000)maxRetryTimeMs: number - Maximum time to retry in milliseconds (default: 15 minutes)
fetchSettlementData(market: string | PublicKey, baseUrl?: string): Promise<SettlementData>
Fetches settlement data for a market from the proxy server.
Parameters:
market: string | PublicKey - Market address (as string or PublicKey)baseUrl: string (Optional) - Base URL for the proxy server
getSettlementData(market: string | PublicKey, baseUrl?: string): Promise<SettlementData>
Alias for fetchSettlementData.
fetchMarketAddresses(baseUrl?: string): Promise<string[]>
Fetches all market addresses from the proxy server.
Parameters:
baseUrl: string (Optional) - Base URL for the proxy server
