
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
@payai/x402-solana-react
Advanced tools
Reusable React paywall components for Solana using the x402 payment protocol
A reusable React component library that provides drop-in paywall functionality for Solana-based applications using the x402 payment protocol v2.
x402 Protocol v2: This package uses
x402-solanawhich implements the x402 v2 specification with CAIP-2 network identifiers,PAYMENT-SIGNATUREheaders, and improved payload structure. See the CHANGELOG for details.
|
|
|
|
|
|
|
|
|
npm install @payai/x402-solana-react
# or
yarn add @payai/x402-solana-react
# or
pnpm add @payai/x402-solana-react
You'll also need Solana wallet adapter packages:
npm install @solana/wallet-adapter-react @solana/wallet-adapter-react-ui @solana/wallet-adapter-wallets @solana/web3.js
Import the required styles in your main file (e.g., main.tsx or App.tsx):
import '@payai/x402-solana-react/styles';
import '@solana/wallet-adapter-react-ui/styles.css';
For production use, configure a custom RPC endpoint to avoid rate limiting on public RPCs:
Create a .env file (you can copy from the included .env.example) and set your RPC URL:
# Your Helius/QuickNode/Alchemy RPC URL
VITE_SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=your_api_key_here
Restart the dev server after changing .env so Vite picks up updates.
Option A: Auto-Setup (Recommended) 🎉
The component automatically sets up wallet providers for you! Just use it directly:
import { X402Paywall } from '@payai/x402-solana-react';
function App() {
return (
<X402Paywall
amount={0.01}
description="Premium Content"
network="solana" // Automatically configures mainnet
>
<YourPremiumContent />
</X402Paywall>
);
}
Option B: Manual Setup (if you need custom wallet configuration)
Wrap your app with Solana wallet providers:
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
import { clusterApiUrl } from '@solana/web3.js';
function App() {
const network = WalletAdapterNetwork.Mainnet;
const endpoint = clusterApiUrl(network);
const wallets = [new PhantomWalletAdapter(), new SolflareWalletAdapter()];
return (
<ConnectionProvider endpoint={endpoint}>
<WalletProvider wallets={wallets} autoConnect={false}>
<WalletModalProvider>
<X402Paywall
amount={0.01}
description="Premium Content"
network="solana"
autoSetupProviders={false} // Disable auto-setup
>
<YourPremiumContent />
</X402Paywall>
</WalletModalProvider>
</WalletProvider>
</ConnectionProvider>
);
}
import { X402Paywall } from '@payai/x402-solana-react';
import '@payai/x402-solana-react/styles';
import '@solana/wallet-adapter-react-ui/styles.css';
function PremiumPage() {
return (
<X402Paywall
amount={0.02}
description="Premium AI Chat Access"
network="solana" // Use 'solana' for mainnet, 'solana-devnet' for testing
onPaymentSuccess={txId => console.log('Payment successful!', txId)}
>
<PremiumContent />
</X402Paywall>
);
}
import { X402Paywall } from '@payai/x402-solana-react';
function PremiumPage() {
// Set via environment variable: VITE_SOLANA_RPC_URL
const rpcUrl = import.meta.env.VITE_SOLANA_RPC_URL;
return (
<X402Paywall
amount={0.02}
description="Premium Content"
network="solana"
rpcUrl={rpcUrl} // Avoids rate limiting on public RPCs
onPaymentSuccess={txId => {
console.log('Payment successful!', txId);
// Update your backend, show success message, etc.
}}
onPaymentError={error => {
console.error('Payment failed:', error);
}}
>
<PremiumContent />
</X402Paywall>
);
}
The component comes with multiple built-in themes:
light - Clean light theme with gradientsdark - Dark theme with pink/purple/blue gradientssolana-light - Official Solana light theme (default)solana-dark - Official Solana dark themeseeker - Emerald/teal gradient themeseeker-2 - Enhanced seeker theme with backdrop blurterminal - Retro terminal green-on-black themeimport { X402Paywall } from '@payai/x402-solana-react';
import { useState } from 'react';
function PremiumPage() {
const [theme, setTheme] = useState('light');
return (
<X402Paywall
amount={0.02}
description="Premium Features"
network="solana"
theme={theme} // Try: 'light', 'dark', 'solana-light', 'solana-dark', etc.
onPaymentSuccess={txId => console.log('Paid!', txId)}
>
<AdvancedFeatures />
</X402Paywall>
);
}
You can customize further using classNames and customStyles props:
<X402Paywall
amount={5.0}
description="Premium Features"
network="solana"
theme="dark"
classNames={{
container: 'bg-gradient-to-r from-purple-600 to-blue-600',
button: 'bg-white text-purple-600 hover:bg-gray-50 font-bold',
}}
customStyles={{
button: { boxShadow: '0 10px 30px rgba(153, 69, 255, 0.4)' },
}}
>
<AdvancedFeatures />
</X402Paywall>
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
amount | number | ✅ | - | Payment amount in USDC |
description | string | ✅ | - | Payment description |
children | ReactNode | ✅ | - | Protected content to show after payment |
network | 'solana' | 'solana-devnet' | ❌ | 'solana-devnet' | Solana network to use |
wallet | WalletAdapter | ❌ | - | Optional wallet adapter (auto-uses context if not provided) |
rpcUrl | string | ❌ | - | Custom RPC URL (recommended to avoid rate limits) |
autoSetupProviders | boolean | ❌ | true | Automatically setup wallet providers |
providerNetwork | WalletAdapterNetwork | ❌ | Auto-detected | Network for auto-setup providers |
providerEndpoint | string | ❌ | - | Custom endpoint for auto-setup providers |
apiEndpoint | string | ❌ | https://x402.payai.network/api/solana/paid-content | Custom API endpoint |
facilitatorUrl | string | ❌ | - | Custom facilitator URL |
theme | ThemePreset | ❌ | 'solana-light' | Visual theme (see Themes section) |
logoUrl | string | ❌ | - | Custom logo URL to display |
showBalance | boolean | ❌ | true | Show wallet USDC balance |
showNetworkInfo | boolean | ❌ | true | Show network information |
showPaymentDetails | boolean | ❌ | true | Show payment details section |
maxPaymentAmount | number | ❌ | - | Maximum allowed payment amount |
classNames | ComponentClassNames | ❌ | - | Custom CSS classes for components |
customStyles | ComponentStyles | ❌ | - | Custom inline styles for components |
onPaymentStart | () => void | ❌ | - | Callback when payment starts |
onPaymentSuccess | (txId: string) => void | ❌ | - | Callback on successful payment |
onPaymentError | (error: Error) => void | ❌ | - | Callback on payment error |
onWalletConnect | (publicKey: string) => void | ❌ | - | Callback when wallet connects |
onDisconnect | () => void | ❌ | - | Callback when wallet disconnects |
See full API documentation for complete reference.
# Clone the repository
git clone https://github.com/payainetwork/x402-solana-react.git
cd x402-solana-react
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
# Edit .env and add your custom RPC URL (Helius, QuickNode, etc.)
# Example: VITE_SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY
# Start development server
npm run dev
# Build library
npm run build
# Type check
npm run typecheck
# Lint
npm run lint
"Wallet not connected"
"Insufficient USDC balance"
"RPC rate limit exceeded"
VITE_SOLANA_RPC_URL in .env filerpcUrl prop: rpcUrl={import.meta.env.VITE_SOLANA_RPC_URL}"Transaction failed"
Styling not working
import '@payai/x402-solana-react/styles';
import '@solana/wallet-adapter-react-ui/styles.css';
"process is not defined" error
import.meta.env instead of process.envimport.meta.env.VITE_SOLANA_RPC_URLReady for Production - Fully functional x402 paywall components with PayAI facilitator integration.
x402-solanaThis package supports the x402 v2 specification which includes:
| Feature | v1 | v2 |
|---|---|---|
| Network Format | solana, solana-devnet | CAIP-2 format (auto-converted) |
| Payment Header | X-PAYMENT | PAYMENT-SIGNATURE |
| Amount Field | maxAmountRequired | amount |
Note: You can still use simple network names (solana, solana-devnet) in your code - the library automatically converts them to CAIP-2 format internally.
This project is currently in early development. Contributions welcome!
MIT License
Built with ❤️ for the Solana ecosystem
FAQs
Reusable React paywall components for Solana using the x402 payment protocol
We found that @payai/x402-solana-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.