sdk-use
v1.0.0
Published
This directory contains SDK usage examples for `@parthsoni07/pnp-sdk-v2`. Each file demonstrates how to use the SDK to perform various operations that were previously done via scripts.
Readme
SDK Usage Examples
This directory contains SDK usage examples for @parthsoni07/pnp-sdk-v2. Each file demonstrates how to use the SDK to perform various operations that were previously done via scripts.
Setup
- Install dependencies:
npm install- Set up environment variables (create a
.envfile in the root directory):
PNP_RPC_URL=https://api.mainnet-beta.solana.com
HARDCODED_PRIVATE_KEY=your_private_key_hereNote: All examples load the .env file from the root directory (parent of sdk-use), not from sdk-use itself.
Usage
Each example file can be run directly with tsx or ts-node:
# Example: Create a P2P market
tsx createP2PQuickstart.ts
# Example: Trade on V3 market
tsx trade_v3.ts
# Example: Get market info
tsx market-info.tsAvailable Examples
These examples demonstrate the new functionality and logic enhancements added in v2 branch (not just logging improvements).
P2P Market Creation (NEW in v2)
createP2PQuickstart.ts- Create a generic P2P market with simple parameterscreateP2PTwitter.ts- Create a Twitter-linked P2P marketcreateP2PYoutube.ts- Create a YouTube-linked P2P marketcreateP2PandTrade.ts- Create a P2P market and trade on itp2pRefund.ts- Claim P2P market creator refund
V3 Market Operations (NEW in v2)
trade_v3.ts- Trade on V3 marketsredeem_v3_position.ts- Redeem winning positions from resolved V3 marketsv3_market_info.ts- Get information about V3 P2P marketslist_v3_markets.ts- List all V3 market addressesfetch_my_v3_markets.ts- Fetch V3 markets where you have positionsfetch_resolved_markets.ts- Fetch all resolved V3 markets
Market Creation (Enhanced in v2)
createMarket.ts- Create a standard market (with balance checking logic)createMarketV3.ts- Create a V3 market (P2P market creation)createMarketV3_oracle.ts- Create a V3 market with oraclecreateMarketAndRefund.ts- Create market and claim refund if not resolvablecreateMarketAndTrade.ts- Create market and trade on it
Market Information (NEW in v2)
market-info.ts- Get comprehensive market information (enhanced)v2_market_info.ts- Get V2 market informationv3_market_info.ts- Get V3 market informationwinningToken.ts- Get winning token for resolved markets (V2 or V3)
Key Differences from Scripts
- Import from npm package: All examples import from
@parthsoni07/pnp-sdk-v2instead of local paths - Environment variables: Use
.envfile withdotenv/configfor configuration - ESM modules: All files use ES modules (
import/export) - Simplified structure: Focus on SDK usage rather than script execution
Note
Only files with actual logic enhancements or new functionality in v2 are included here. Files that only had logging improvements, type safety changes, or minor refactoring have been excluded.
Notes
- All examples output structured JSON results between
=== RESULT ===markers - Set
VERBOSE=1environment variable for detailed output - Private key (
HARDCODED_PRIVATE_KEY) can be provided as JSON array string or base58 string in the root.envfile - Most read-only operations don't require a private key
