A seamless Web3 payment solution that bridges traditional payments with Solana blockchain
|
|
npm install solana-pay-widget
# or
yarn add solana-pay-widget
import { CheckoutWidget, WalletConnectionProvider } from 'solana-pay-widget';
import 'solana-pay-widget/dist/index.css';
function App() {
return (
<WalletConnectionProvider rpcEndpoint='https://api.devnet.solana.com'>
<CheckoutWidget
checkoutId="demo_checkout_123"
merchantWallet="4rbzcZsLxEefKdyho3U2dc5tfKUMdSM4vyRQhAkL4EHX"
amount={0.001}
currency="SOL"
productName="Premium Subscription"
description="Monthly premium subscription with all features"
isOpen={true}
onClose={() => {}}
onSuccess={(txnId) => {}}
onError={(err) => {}}
/>
</WalletConnectionProvider>
);
}
<CheckoutWidget
checkoutId="demo_checkout_123"
merchantWallet="4rbzcZsLxEefKdyho3U2dc5tfKUMdSM4vyRQhAkL4EHX"
amount={0.001}
currency="SOL"
productName="Premium Subscription"
description="Monthly premium subscription with all features"
isOpen={true}
onClose={() => {}}
onSuccess={(txnId) => {}}
onError={(err) => {}}
/>
graph TB
A[π€ User] -->|Creates Payment| B[π Checkout]
B --> C[π³ Payment Method]
C -->|Solana Pay| D[π Solana Blockchain]
D -->|Verify| F[β‘ Backend API]
F -->|Update Status| G[β
Order Complete]
F -->|Success Return| H[π§ You can store TxnId in DB]
Prop | Type | Required | Description |
---|---|---|---|
checkoutId |
string |
β | Unique checkout identifier for tracking |
merchantWallet |
string |
β | Merchant's Solana wallet address (recipient) |
amount |
number |
β | Payment amount (e.g., 0.001 for SOL) |
currency |
'SOL' | 'USDC' | 'USDT' |
β | Payment currency |
productName |
string |
β | Product/service name shown in widget |
description |
string |
β | Product description |
theme |
'light' | 'dark' | 'auto' |
β | Widget theme (default: 'light') |
enableNftReceipt |
boolean |
β | Enable NFT receipt minting (not implemented) |
webhookUrl |
string |
β | Payment webhook URL (not implemented) |
onSuccess |
(txId: string) => void |
β | Success callback with transaction ID |
onError |
(error: Error) => void |
β | Error callback |
onClose |
() => void |
β | Close callback |
className |
string |
β | Custom CSS class for styling |
isOpen |
boolean |
β | Control widget modal visibility |
Prop | Type | Required | Description |
---|---|---|---|
rpcEndpoint |
string |
β | Solana RPC endpoint (default: devnet) |
children |
ReactNode |
β | Child components |
Supported Wallets:
- π¦ Phantom
- βοΈ Solflare
π °οΈ Alpha Wallet
<WalletConnectionProvider rpcEndpoint='https://api.devnet.solana.com'>
<CheckoutWidget
merchantWallet="4rbzcZsLxEefKdyho3U2dc5tfKUMdSM4vyRQhAkL4EHX"
// ... other props
/>
</WalletConnectionProvider>
<WalletConnectionProvider rpcEndpoint='https://api.mainnet-beta.solana.com'>
<CheckoutWidget
merchantWallet="YOUR_MAINNET_WALLET_ADDRESS"
// ... other props
/>
</WalletConnectionProvider>
- Widget automatically uses appropriate token addresses based on network
- USDC/USDT payments require token accounts (automatically created if needed)
- Always test on devnet before deploying to mainnet
- Direct wallet-to-wallet transfers
- Minimum amount: 0.000001 SOL
- Includes transaction fee estimation
- Requires associated token accounts
- Automatic token account creation for recipients
- 6 decimal precision for both USDC and USDT
- Mobile wallet compatible
- Real-time transaction polling
- Automatic payment verification
The widget includes comprehensive error handling:
const handleError = (error) => {
switch(error.message) {
case 'Insufficient SOL balance':
// Handle insufficient funds
break;
case 'Transaction was cancelled':
// Handle user cancellation
break;
case 'Network error':
// Handle connection issues
break;
default:
// Handle other errors
}
};
Common Error Types:
Insufficient funds
- User needs more SOL/tokensToken account not found
- User needs to create token accountTransaction was cancelled
- User rejected transactionNetwork error
- Connection or RPC issues
- QR Generation - Secure Solana Pay URL created
- Mobile Scan - User scans with mobile wallet
- Transaction - Payment processed on blockchain
- Verification - Auto-polling confirms payment
- Completion - Success callback triggered
QR Code Features:
- Auto-generated reference for tracking
- Error correction for reliable scanning
- Timeout after 5 minutes
- Real-time status updates
<CheckoutWidget
className="my-custom-checkout"
theme="dark"
// ... other props
/>
.my-custom-checkout {
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.my-custom-checkout .sp-checkout-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
Available CSS Classes:
.sp-modal-overlay
- Modal backdrop.sp-modal-container
- Main modal container.sp-checkout-header
- Header section.sp-qr-payment
- QR code container.sp-wallet-payment
- Wallet payment section