MoonPay Module
Seamless fiat on-ramp integration for purchasing cryptocurrency with credit cards and Apple Pay
The MoonPay module provides seamless cryptocurrency purchasing capabilities directly within your app. Users can buy crypto using credit cards, debit cards, Apple Pay, and other payment methods through MoonPay’s trusted platform.
Core Functionalities
Crypto On-Ramp
Purchase cryptocurrencies directly using various payment methods with automatic wallet integration
Wallet Integration
Automatically populates the user’s connected wallet address as the destination for purchases
Customizable Widget
Configurable MoonPay widget supporting both sandbox and production environments
Balance Management
View wallet balances and seamlessly navigate to purchase flows when funds are needed
Installation & Setup
Install MoonPay SDK
The module uses the official MoonPay React Native SDK:
Configure API Key
Add your MoonPay API key to .env.local
:
Import Components
Import the components you need:
API Keys: Use pk_test_
prefixed keys for testing and pk_live_
for production. The module automatically detects the environment.
Module Architecture
Core Components
MoonPayWidget
- Core component that embeds MoonPay’s purchase flow
Props:
apiKey
- Your MoonPay API keyenvironment
- ‘sandbox’ or ‘production’height
- Widget height in pixelsonOpen
- Callback when widget loadsonError
- Error handling callbackonRetry
- Retry mechanism callback
MoonPayWidget
- Core component that embeds MoonPay’s purchase flow
Props:
apiKey
- Your MoonPay API keyenvironment
- ‘sandbox’ or ‘production’height
- Widget height in pixelsonOpen
- Callback when widget loadsonError
- Error handling callbackonRetry
- Retry mechanism callback
OnrampScreen
- Complete purchase screen with navigation and wallet integration
Features:
- Automatic wallet address detection
- Loading and error states
- Navigation header integration
- Informational content about the purchase process
WalletScreen
- Wallet balance display with on-ramp entry point
Features:
- SOL balance display
- Wallet address with copy functionality
- Add funds button integration
- Balance refresh capability
Quick Start Example
MoonPay Service Configuration
The moonpayService.ts
provides configuration and validation utilities:
Utility Functions
Advanced Usage Patterns
Custom Purchase Flow
Transaction Status Tracking
Balance-Based Recommendations
Integration with Other Modules
Wallet Providers
Automatic wallet address detection and integration
Data Module
Real-time balance updates and transaction history
Swap Module
Purchase crypto then immediately swap to desired tokens
Thread Module
Share purchase milestones and achievements
Combined Workflow Example
Environment Configuration
- Uses sandbox environment automatically
- Test transactions don’t involve real money
- Full widget functionality for testing
- Uses sandbox environment automatically
- Test transactions don’t involve real money
- Full widget functionality for testing
- Uses live MoonPay environment
- Real transactions with actual payment processing
- Requires KYC compliance and full verification
Error Handling & Troubleshooting
Security Considerations
API Key Security: Never expose production API keys in client-side code. Consider using a backend proxy for additional security.
User Verification: MoonPay handles KYC/AML compliance, but ensure your app provides clear information about verification requirements.
API Reference
For detailed API documentation, see:
The MoonPay module provides a seamless bridge between traditional finance and crypto, enabling users to easily onboard into the Solana ecosystem with familiar payment methods.