From the book: Fast, Low-Fee Mobile Crypto Payments: A Practical Guide to Solana USDC in React Native
This is a practical example demonstrating how to integrate Phantom wallet with a Next.js application and submit transactions to the Solana blockchain.
- ✅ Connecting to Phantom wallet browser extension
- ✅ Detecting wallet connection status
- ✅ Displaying connected wallet address
- ✅ Creating and signing Solana transactions
- ✅ Submitting SOL transactions to Solana devnet
- ✅ Transferring USDC tokens via SPL Token program
- ✅ Creating associated token accounts for recipients
- ✅ Confirming transaction finalization
app/page.tsx → Main entry point
components/phantom-connect.tsx → Phantom SDK Provider setup
components/wallet-connect.tsx → Wallet connection UI
components/solana-transaction.tsx → SOL transaction submission logic
components/usdc-transaction.tsx → USDC token transfer logic
- Node.js 18+ installed
- Phantom Wallet browser extension installed
- SOL tokens on devnet (get from Solana Faucet)
- Install dependencies:
npm install- Run the development server:
npm run dev-
Open your browser:
- Navigate to http://localhost:3000
- Click "Connect Wallet" button
- Approve connection in Phantom popup
-
Test transactions:
SOL Transfer:
- Click "Send SOL" button
- Approve transaction in Phantom
- Transaction sends 0.0005 SOL to a test address
USDC Transfer:
- Ensure you have devnet USDC tokens (see USDC Setup below)
- Click "Send USDC" button
- Approve transaction in Phantom
- Transaction sends 0.2 USDC to a test address
To test USDC transfers on devnet:
-
Get Devnet SOL:
solana airdrop 1 <YOUR_WALLET_ADDRESS> --url devnet
Or use Solana Faucet
-
Get Devnet USDC:
- The example uses USDC devnet mint:
4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU - You'll need to mint or receive devnet USDC tokens to this address
- Alternatively, use SPL Token Faucet or create your own tokens for testing
- The example uses USDC devnet mint:
- Next.js 15 - React framework with App Router
- @phantom/react-sdk - Official Phantom wallet React integration
- @solana/web3.js - Solana blockchain JavaScript SDK
- @solana/spl-token - SPL Token program library for token transfers
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
Wraps the app with PhantomProvider to enable wallet functionality across all components.
Uses usePhantom() hook to access connection state and ConnectBox component for UI.
Demonstrates complete SOL transaction lifecycle:
- Connect to Solana RPC
- Get wallet public key
- Create transfer instruction
- Build transaction message
- Sign and send via Phantom
- Confirm finalization
Shows how to transfer SPL tokens (USDC):
- Verify sufficient SOL balance for fees
- Get associated token addresses for sender and recipient
- Check sender's USDC balance
- Create recipient's token account if needed
- Build token transfer instruction (0.2 USDC)
- Sign, send, and confirm transaction
This example uses Solana Devnet for testing. To use mainnet:
const connection = new Connection("https://api.mainnet-beta.solana.com");This example is featured in Chapter X of Fast, Low-Fee Mobile Crypto Payments, demonstrating core concepts that apply to both web and React Native implementations.
Educational example for book readers.