View example code
Explore the complete collection of h402 solana RPC integration examples in our repository.
H402 Solana RPC Proxy
Your personal, on-demand, account-free gateway to the Solana blockchain. This project is a simple but powerful proxy server for Solana RPC calls that uses the H402 protocol for micropayments. Think of it as your own personal Helius or QuickNode, but without the need to create an account, manage API keys, or commit to a monthly subscription. You pay for exactly what you use, on the fly. The flow varies depending on blockchain, token, crypto and other aspectsWhy is this cool?
In the current Web3 landscape, accessing blockchain data usually means signing up for a service, getting an API key, and dealing with monthly bills. This project demonstrates a more open, decentralized, and flexible approach.- No Accounts, No Subscriptions: Ditch the tedious sign-up forms and monthly commitments. Your wallet is your account.
- On-Demand, Per-Request Payments: Pay only for the specific RPC calls you make, when you make them.
- Enhanced Privacy: No need to hand over personal information to a third-party service.
- Perfect for High-Availability Systems: Use it as a primary RPC endpoint or as a pay-on-demand backup. If your main provider fails, you can instantly fall back to this proxy without any prior setup or cost commitment. This is the model we use for our resilient infrastructure.
The Power of H402 + Solana
This project leverages a powerful combination:- The H402 Protocol: A standard for handling payments over HTTP. It allows the server to issue a
402 Payment Requiredchallenge, which the client can programmatically pay and retry. - The Solana Blockchain: With transactions that confirm in the blink of an eye and cost a fraction of a cent, Solana is the perfect payment rail for this kind of real-time, high-frequency use case.
How It Works
Here’s how it works step by step:- A client makes a standard RPC request to the proxy server (e.g.,
getAccountInfo). - The proxy checks its configuration and determines the cost for that specific method.
- It responds with a standard
402 Payment Requiredheader, detailing the exact amount of USDC to send and the address to send it to. - An H402-aware client (like one using our
@bit-gpt/h402-fetchlibrary) automatically parses this challenge, crafts and signs the tiny payment transaction, and sends it on Solana. - Once the payment is confirmed (typically in under a second), the client automatically retries the original RPC request.
- The proxy verifies the payment and forwards the RPC request to the upstream provider (e.g., Helius), returning the response to the client.
Getting Started
Prerequisites
- Node.js
pnpmis recommended (npm install -g pnpm)
1. Clone the Repository
2. Install Dependencies
3. Configure Your Environment
Copy the example environment file and fill in the details..env file:
Server Config:
RPC_URL: The upstream Solana RPC endpoint you want to proxy.PORT: The port your proxy server will run on.SOLANA_PAY_TO_ADDRESS: The public key of the Solana wallet that will receive the payments.
SOLANA_PRIVATE_KEY: The base58-encoded private key of the Solana wallet that will send the payments.RESOURCE_SERVER_URL: The full URL of your running proxy server (e.g.,http://localhost:19782).ENDPOINT_PATH: The path for the RPC endpoint on your proxy (/rpc).
4. Run the Proxy Server
PORT you configured.
5. Run the Client to Test
In a separate terminal, run the client to send a testgetLatestBlockhash request:
Future Roadmap
This is just the beginning! We’re planning to evolve this concept by adding:- A Credit-Based System: Allow users to pre-fund an account with a larger, one-time payment. The proxy will then deduct credits for each RPC call, offering even lower latency by removing the need for an on-chain transaction for every single request.

