x402member01.mp4
Serverless x402 facilitator for Solana USDC payments with free SPL memecoin holder access
This is a minimal dependency (no-viem) x402 facilitator (using serverless Firebase Functions, low deployment cost) for providing a member-only access based on SPL token balance or processing a x402 USDC payment. This sample project comes with a minimum React client for pay-per-call API access with Solana-based USDC payments.
This project shows that you can host your own facilitator to remove 3rd party dependency and provide memecoin utilities by allowing holders to free access the gated API calls.
- Host your own x402 facilitator using serverless Firebase Functions (pay-for-use plan). Your facilitator does not even need to hold any pkeys.
- Membership Detection: Checks SPL token balance for membership status and skip payment broadcasting (i.e., free API access for SPL token holders). Using SPL memecoins for x402 payments may not be cost-efficient for new users.
- Step-by-step React client DEMO: Simple UI for connecting Phantom wallet and making payments.
- Minimal Dependencies: Lightweight implementation focused on core functionality. No viem, no typescripts.
- Backend (
functions/): Firebase Cloud Functions handle x402 payment verification, transaction validation, and membership checks. - Frontend (
host/): React app built with Vite for user interaction with Phantom wallet. - Deployment: It's up to you but it's easy to host on Firebase (functions and static hosting).
- Node.js (v18 or later)
- Firebase CLI (for setting up a Firebase project)
- Phantom wallet (for web-client payment)
- Solana RPC url
- Solana address for receiving x402 payment
-
Clone the repository:
git clone https://github.com/runeape-sats/x402-sol-member.git cd x402-sol-member -
Set up Firebase project:
- Install Firebase CLI:
npm install -g firebase-tools - Login:
firebase login - Initialize:
firebase init(select Functions and Hosting)
- Install Firebase CLI:
-
Set up facilitator using Firebase Functions:
cd functions npm iRun the local Firebase Fucntions simulator
firebase emulators:start --only functionsCheck endpoint
- GET /weather: Requires x402 payment header. Returns weather data if payment is valid.
-
Set up web client:
cd host npm iCreate
host/.env:VITE_RPC_ENDPOINT=https://api.mainnet-beta.solana.com VITE_FIREBASE_FUNCTIONS_URL=https://your-project.firebaseapp.com/weather
Run
npm run devOpen browser to
http://localhost:5173(or Vite's default port).
- Connect Phantom wallet.
- Click "Pay & Fetch /weather" to make a payment and retrieve data.
- Membership holders (based on SPL balance) skip fee verification.
This project is licensed under the MIT License - see the LICENSE file for details.
This is a proof-of-concept implementation. Use at your own risk. Ensure compliance with Solana and payment regulations.