API Reference
Complete documentation for integrating x402-RPC-Aggregator into your applications. This API provides intelligent RPC routing with built-in x402 micropayment support for Solana, Ethereum, and Base chains.
Quick Start
Make your first RPC call in less than 5 minutes.
1. Make an RPC Request
curl -X POST https://x402labs.cloud/rpc \
-H "Content-Type: application/json" \
-d '{
"method": "getSlot",
"chain": "solana"
}'
2. Receive 402 Payment Challenge
{
"invoice": {
"amount": 0.0001,
"to": "FacilitatorWalletAddress...",
"network": "solana-mainnet",
"provider": "Triton One",
"nonce": "1730000000000-abc123"
}
}
3. Pay and Retry (Automatic with SDK)
import { X402Agent } from './x402-client';
const agent = new X402Agent('https://x402labs.cloud/');
const result = await agent.callRPC('getSlot', [], 'solana');
console.log('Slot:', result.result);
console.log('Tx Hash:', result.x402.paymentInfo.txHash);
Authentication LIVE
x402-RPC-Aggregator uses the x402 protocol for authentication. Instead of API keys, you pay per request using USDC micropayments on Solana or Base.
Payment Flow
- Make request without payment → Receive 402 with invoice
- Sign payment with wallet (Phantom/MetaMask)
- Retry request with x402-payment header
- Facilitator verifies & settles payment
- Receive RPC response with receipt
RPC Endpoint LIVE
Execute an RPC call with intelligent provider routing and x402 payment.
Request Body
| Parameter | Type | Description |
|---|---|---|
| methodrequired | string | RPC method name (e.g., "getSlot", "eth_blockNumber") |
| paramsoptional | array | Method parameters (default: []) |
| chainoptional | string | Blockchain: "solana" | "ethereum" | "base" (default: "solana") |
| preferencesoptional | object | Routing preferences (see Routing Strategies) |
Response (200 Success)
{
"jsonrpc": "2.0",
"id": 1,
"result": 182456789,
"x402": {
"provider": "Triton One",
"paymentInfo": {
"provider": "solana",
"chain": "solana",
"txHash": "5x...",
"amount": 0.0001,
"explorer": "https://orb.helius.dev/tx/5x..."
},
"cost": 0.0001,
"status": "settled"
}
}
Response (402 Payment Required)
{
"invoice": {
"amount": 0.0001,
"to": "FacilitatorWallet...",
"network": "solana-mainnet",
"resource": "/rpc",
"nonce": "unique-nonce",
"provider": "Triton One",
"batchOption": {
"calls": 1000,
"price": 0.08,
"savings": "20%"
}
}
}
Health Check
Check service health and provider status.
curl https://x402labs.cloud//health
Response
{
"status": "ok",
"timestamp": "2025-10-27T12:00:00.000Z",
"version": "1.0.0",
"chains": ["solana", "ethereum", "base"],
"stats": {
"totalProviders": 8,
"activeProviders": 8,
"healthyProviders": 7,
"averageLatency": 312
}
}
List Providers
Get list of all RPC providers with real-time health status.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| chainoptional | string | Filter by chain: "solana" | "ethereum" | "base" |
curl 'https://x402labs.cloud//providers?chain=solana'
Response
{
"providers": [
{
"id": "triton-solana",
"name": "Triton One",
"chains": ["solana"],
"costPerCall": 0.0001,
"batchCost": { "calls": 1000, "price": 0.08 },
"status": "active",
"priority": 100,
"averageLatency": 245
}
],
"total": 1
}
Routing Strategies LIVE
Customize how the aggregator selects RPC providers for your requests.
Available Strategies
1. Lowest Cost (Default)
Selects the provider with the lowest cost per call.
{
"method": "getSlot",
"chain": "solana",
"preferences": {
"strategy": "lowest-cost"
}
}
2. Lowest Latency
Selects the fastest provider based on real-time health checks.
{
"method": "getSlot",
"chain": "solana",
"preferences": {
"strategy": "lowest-latency",
"maxLatencyMs": 2000
}
}
3. Highest Priority
Uses premium providers first (e.g., Triton One for Solana).
{
"method": "getSlot",
"chain": "solana",
"preferences": {
"strategy": "highest-priority"
}
}
4. Round Robin
Distributes load evenly across all providers.
{
"method": "getSlot",
"chain": "solana",
"preferences": {
"strategy": "round-robin"
}
}
Batch Payments LIVE
Purchase multiple calls upfront for discounted pricing (20% savings).
Get Batch Pricing
curl 'https://x402labs.cloud/batch-pricing?chain=solana'
Response
{
"chain": "solana",
"batchOptions": [
{
"providerId": "triton-solana",
"providerName": "Triton One",
"calls": 1000,
"price": 0.08,
"pricePerCall": 0.00008,
"savings": "20.0%"
}
]
}
Purchase Batch
Include batchPurchase: true in payment payload to buy a batch.
Use Batch
Include batch ID in header for subsequent calls:
curl -X POST /rpc \
-H "x402-batch: {\"batchId\": \"batch_123...\"}" \
-d '{"method":"getSlot","chain":"solana"}'
Error Handling
HTTP Status Codes
| Code | Meaning | Action |
|---|---|---|
| 200 | Success | Payment settled, RPC executed |
| 402 | Payment Required | Pay invoice and retry |
| 400 | Bad Request | Check request parameters |
| 404 | Not Found | Check endpoint URL |
| 500 | Server Error | Retry with fallback provider |
JavaScript/TypeScript SDK
import { X402Agent } from './lib/x402-client';
// Initialize agent
const agent = new X402Agent('https://x402labs.cloud/');
// Make RPC call (handles payment automatically)
const result = await agent.callRPC('getSlot', [], 'solana');
console.log('Current slot:', result.result);
console.log('Payment tx:', result.x402.paymentInfo.txHash);
With Preferences
const result = await agent.callRPC(
'getBalance',
['SomeWalletAddress...'],
'solana',
{
strategy: 'lowest-latency',
maxLatencyMs: 1500,
preferredProviders: ['triton-solana']
}
);
Python (Concept)
from x402_client import X402Agent
# Initialize
agent = X402Agent('https://x402labs.cloud/')
# Make call
result = agent.call_rpc('getSlot', [], chain='solana')
print(f"Slot: {result['result']}")
print(f"Tx: {result['x402']['paymentInfo']['txHash']}")
cURL Examples
Solana - Get Slot
curl -X POST https://x402labs.cloud/rpc \
-H "Content-Type: application/json" \
-d '{
"method": "getSlot",
"chain": "solana"
}'
Ethereum - Block Number
curl -X POST https://x402labs.cloud/rpc \
-H "Content-Type: application/json" \
-d '{
"method": "eth_blockNumber",
"chain": "ethereum"
}'
With Custom Routing
curl -X POST https://x402labs.cloud/rpc \
-H "Content-Type: application/json" \
-d '{
"method": "getSlot",
"chain": "solana",
"preferences": {
"strategy": "lowest-latency",
"maxLatencyMs": 2000
}
}'