Examples & Best Practices
Usage Examples
Creating a Market
This example demonstrates how to create a new prediction market using the SDK.- You must initialize the client with a valid private key to create markets
- The
baseMintparameter specifies the collateral token (e.g., USDC) - Initial liquidity should be specified in the base units of the collateral token
- End time is a Unix timestamp in seconds
Trading Tokens
Buying and Selling Tokens
The trading module allows you to buy and sell YES/NO outcome tokens in a market.Fetching Settlement Criteria
You can fetch settlement criteria from the proxy server to check if a market is resolvable.Getting Comprehensive Market Information
This example shows how to gather all available information about a market from both on-chain data and the proxy server.Best Practices
Error Handling
Always wrap SDK calls in try-catch blocks and check for specific error conditions:SDK Initialization
-
Read-only operations: Initialize without a private key
-
Write operations: Initialize with a private key
-
Always verify that required modules are available
Performance Optimization
- Batch transactions when possible
- Use commitment levels appropriately
- Cache frequently accessed accounts
- Use connection commitment level ‘confirmed’ for better performance
Security Considerations
- Never expose private keys in client-side code
- Validate all user inputs
- Use the latest version of the SDK
- Verify transaction details before signing
Frequently Asked Questions
How do I get started with the SDK?
See the Quick Start section for installation and basic usage.What networks are supported?
The SDK supports all Solana networks: mainnet-beta, devnet, and testnet.How do I handle transaction timeouts?
Implement retry logic with exponential backoff:How can I monitor market events?
Use Solana’s websocket API to subscribe to program accounts and logs.What’s the difference between market and limit orders?
- Market orders execute immediately at the best available price
- Limit orders only execute at the specified price or better
Contributing
We welcome contributions! Please follow these steps:- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a pull request
Development Setup
- Clone the repository
- Install dependencies:
- Build the project:
- Run tests:
Code Style
- Follow TypeScript best practices
- Use ESLint and Prettier for consistent formatting
- Write tests for new features
- Document public APIs with JSDoc
Changelog
v0.1.0 (2025-02-15)
- Initial release
- Basic market creation and trading functionality
- TypeScript type definitions
- Comprehensive documentation
License
Apache-2.0Support
For support, please open an issue on GitHub.Acknowledgments
- PNP team
- Solana Team
- Anchor Framework
- All contributors
