The Server SDK is currently experimental and not ready for production use.
@phantom/server-sdk
into your application for secure wallet management and transaction signing.
Critical Security Information
IMPORTANT: The private key for your organization is meant to be stored ONLY on your server, in a secure environment.
- NEVER expose this key in client-side code
- NEVER commit it to version control
- Store it securely using environment variables or secret management systems
Backend Integration
When integrating the SDK into your backend, it’s IMPORTANT to maintain the relationship between your users and their wallets.Key Requirements
- Always store the wallet ID in your database immediately after creation
- Associate each wallet with a user ID to maintain ownership
- Use meaningful wallet names (e.g.,
user_${userId}
) for easier recovery
Database Schema
Here’s an example using Prisma:Complete API Example
Here’s a production-ready Express API with proper wallet management:Best Practices
1. Wallet Management
- Always use meaningful wallet names: Use identifiers like
user_${userId}
ororg_${orgId}_wallet_${timestamp}
to make wallet recovery easier. - Store wallet IDs immediately: As soon as you create a wallet, persist the
walletId
in your database. This is critical for accessing the wallet later. - Maintain wallet-user relationships: Always associate wallets with user accounts in your database to ensure proper ownership tracking.
2. Error Handling
- Implement retry logic: Network requests can fail. Implement exponential backoff for transient failures.
- Log errors comprehensively: Log both the error message and any response data for debugging.
- Handle specific error cases: Different errors require different handling (e.g., insufficient balance vs network errors).
3. Performance
- Cache wallet addresses: After fetching addresses, cache them to reduce API calls.
- Use pagination: When listing wallets, always use pagination to handle large datasets efficiently.
- Batch operations: If you need to perform multiple operations, consider batching where possible.
4. Transaction Management
- Always verify transactions: After signing and sending, always wait for confirmation.
- Implement timeout handling: Set reasonable timeouts for transaction confirmations.
- Store transaction history: Keep records of all transactions for audit trails.
Security Considerations
1. API Key Management
2. Environment Security
- Use secret management services: In production, use services like AWS Secrets Manager, HashiCorp Vault, or similar.
- Rotate keys regularly: Implement a key rotation strategy.
- Limit key access: Only give access to the private key to services that absolutely need it.
- Monitor API usage: Set up alerts for unusual API activity.
3. Database Security
- Encrypt sensitive data: Consider encrypting wallet IDs and user associations at rest.
- Use database access controls: Implement proper RBAC for database access.
- Audit wallet operations: Log all wallet creation and transaction operations.
4. API Security
- Implement rate limiting: Protect your endpoints from abuse.
- Use authentication: Require proper authentication for all wallet operations.
- Validate all inputs: Never trust client-provided data.
- Use HTTPS only: Ensure all API communications are encrypted.
Next Steps
- View example implementations
- Explore the complete API reference
- Learn about creating wallets
- Sign and send transactions