Skip to content

runeape-sats/x402-sol-member

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402member01.mp4

x402-sol-member

Serverless x402 facilitator for Solana USDC payments with free SPL memecoin holder access

Introduction

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.

Features

  • 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.

Folder Structure

  • 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).

Prerequisites

  • 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

Installation

  1. Clone the repository:

    git clone https://github.com/runeape-sats/x402-sol-member.git
    cd x402-sol-member
  2. Set up Firebase project:

    • Install Firebase CLI: npm install -g firebase-tools
    • Login: firebase login
    • Initialize: firebase init (select Functions and Hosting)
  3. Set up facilitator using Firebase Functions:

    cd functions
    npm i

    Run the local Firebase Fucntions simulator firebase emulators:start --only functions

    Check endpoint

    • GET /weather: Requires x402 payment header. Returns weather data if payment is valid.
  4. Set up web client:

    cd host
    npm i

    Create host/.env:

    VITE_RPC_ENDPOINT=https://api.mainnet-beta.solana.com
    VITE_FIREBASE_FUNCTIONS_URL=https://your-project.firebaseapp.com/weather

    Run npm run dev

    Open browser to http://localhost:5173 (or Vite's default port).

Testing Payment Flow

  1. Connect Phantom wallet.
  2. Click "Pay & Fetch /weather" to make a payment and retrieve data.
  3. Membership holders (based on SPL balance) skip fee verification.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is a proof-of-concept implementation. Use at your own risk. Ensure compliance with Solana and payment regulations.

About

x402 facilitator for detecting membership from spl balance. minimum dependency.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages