A production-ready service that lets creators monetize any web resource (videos, PDFs, APIs, etc.) using the WS402 protocol and Solana blockchain payments. https://proxy.ws402.org https://proxy.ws402.org/embed-demo
ws402-proxy is an early-stage JavaScript project in the AI payments / x402 ecosystem, focused on solana, ws402, x402. It currently has 2 GitHub stars and 0 forks, and sits alongside related tools like CloddsBot, x402-openai-python, x402-client, x402-openai-typescript, solcex-autonomous-vanguard, r402.
A powerful payment-gated content proxy service built on Solana blockchain using the WS402 protocol. Monetize your digital content (images, videos, audio, PDFs) with per-second micropayments.

Create payment-gated URLs and protect your content with per-second billing

Easily embed protected content into any website with our simple embed code
git clone <your-repo-url>
cd ws402-proxy-service
npm install
npm install express ws cors dotenv @solana/web3.js ws402
.env fileCreate a .env file in the root directory:
# Server Configuration
PORT=4021
NODE_ENV=development
# Solana Configuration
SOLANA_NETWORK=devnet
SOLANA_RPC_URL=https://api.devnet.solana.com
# Service Wallet (Merchant)
SERVICE_WALLET_PUBLIC_KEY=YourPublicKeyHere
SERVICE_WALLET_PRIVATE_KEY=YourPrivateKeyHere
# Pricing Configuration
MIN_PRICE_PER_SECOND=1000
SERVICE_FEE_PERCENTAGE=5
MAX_SESSION_DURATION=3600
# CORS
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
For Devnet Testing:
# Generate new keypair
solana-keygen new --outfile ~/my-wallet.json
# Get public key
solana-keygen pubkey ~/my-wallet.json
# Get private key (as JSON array)
cat ~/my-wallet.json
# Fund with devnet SOL
solana airdrop 2 <YOUR_PUBLIC_KEY> --url devnet
For Production:
The service accepts two private key formats:
JSON Array Format (recommended):
SERVICE_WALLET_PRIVATE_KEY=[1,2,3,4,5,...]
Base58 Format (from Phantom/Solflare):
SERVICE_WALLET_PRIVATE_KEY=5J6fd...base58string...
npm run dev
npm start
The server will start on http://localhost:4021 (or your configured PORT).
Endpoint: POST /api/mask
Create a payment-gated resource.
Request Body:
{
"originalUrl": "https://example.com/image.jpg",
"pricePerSecond": 100000,
"estimatedDuration": 300,
"title": "My Premium Content",
"creatorWallet": "YourSolanaWalletAddress"
}
Parameters:
originalUrl (required): Direct URL to media filepricePerSecond (required): Price in lamports (1 SOL = 1,000,000,000 lamports)estimatedDuration (optional): Estimated viewing time in seconds (default: 300)title (optional): Resource title (default: "Untitled Resource")creatorWallet (required): Creator's Solana wallet addressResponse:
{
"success": true,
"maskedId": "abc123",
"accessUrl": "https://yourservice.com/watch/abc123",
"schemaUrl": "https://yourservice.com/api/resource/abc123/schema",
"embedCode": "<script src=\"...\"></script>",
"qrCode": "https://yourservice.com/api/qr/abc123",
"analytics": "https://yourservice.com/dashboard/abc123",
"resource": {
"id": "abc123",
"title": "My Premium Content",
"type": "image",
"pricePerSecond": 100000,
"priceSOL": "0.000100000 SOL",
"estimatedDuration": 300,
"totalEstimatedCost": 30000000,
"totalEstimatedCostSOL": "0.030000000 SOL"
}
}
Endpoint: GET /api/resource/:maskedId/schema
Get payment schema for WS402 protocol.
Response:
{
"ws402Schema": {
"version": "1.0",
"serviceName": "WS402 Proxy Payment",
"pricePerSecond": 100000,
"currency": "lamports",
"estimatedDuration": 300,
"paymentProvider": "solana",
"websocketEndpoint": "wss://yourservice.com/ws402?resourceId=abc123&userId=",
"resourceInfo": {
"name": "My Premium Content",
"type": "image",
"estimatedTime": 300,
"priceSOL": "0.000100000 SOL",
"totalPriceSOL": "0.030000000 SOL"
}
}
}
Endpoint: GET /proxy/:maskedId?token=xxx
Access the actual content (requires valid payment token).
Parameters:
maskedId: The masked resource IDtoken: Access token received after payment verificationEndpoint: GET /api/resources
List all masked resources.
Response:
{
"resources": [
{
"id": "abc123",
"title": "My Premium Content",
"type": "image",
"pricePerSecond": 100000,
"priceSOL": "0.000100000 SOL",
"estimatedDuration": 300,
"totalPrice": 30000000,
"totalPriceSOL": "0.030000000 SOL",
"views": 42,
"createdAt": 1699564800000
}
]
}
Endpoint: GET /api/resource/:maskedId
Get public information about a specific resource.
Endpoint: GET /api/resource/:maskedId/analytics
Get detailed analytics for a resource.
Endpoint: GET /blockhash
Get latest Solana blockhash for client-side transactions.
Endpoint: GET /health
Check service health and status.
Response:
{
"status": "ok",
"activeSessions": 5,
"activeHTTPSessions": 3,
"maskedResources": 10,
"solanaProvider": {
"network": "devnet",
"rpcEndpoint": "https://api.devnet.solana.com",
"merchantWallet": "...",
"autoRefundEnabled": true
},
"timestamp": 1699564800000
}
// Create masked resource
const response = await fetch('http://localhost:4021/api/mask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
originalUrl: 'https://example.com/premium-image.jpg',
pricePerSecond: 100000, // 0.0001 SOL per second
estimatedDuration: 60, // 1 minute
title: 'Premium Artwork',
creatorWallet: 'YourWalletAddress'
})
});
const data = await response.json();
console.log('Access URL:', data.accessUrl);
console.log('Total cost:', data.resource.totalEstimatedCostSOL);
<!-- Add to your webpage -->
<script
src="https://yourservice.com/embed.js"
data-resource="abc123"
></script>
Share the watch URL with users:
https://yourservice.com/watch/abc123
Users will:
┌─────────────┐
│ Client │
│ (Browser) │
└──────┬──────┘
│
│ 1. Request Schema
├──────────────────────────┐
│ │
│ ┌─────▼──────┐
│ │ Server │
│ │ (Express) │
│ └─────┬──────┘
│ │
│ 2. Get WS402 Schema │
│◄─────────────────────────┤
│ │
│ 3. Connect WebSocket │
├──────────────────────────►
│ │
│ 4. Solana Payment │
├──────────┐ │
│ │ │
┌───▼────┐ │ ┌────▼─────┐
│ Solana │ │ │ WS402 │
│ RPC │ │ │ Protocol │
└───┬────┘ │ └────┬─────┘
│ │ │
│ 5. Verify Payment │
└──────────►───────────────►
│
6. Grant Access │
◄──────────────────────────┤
│ │
│ 7. Get HTTP Token │
│◄─────────────────────────┤
│ │
│ 8. Access Content │
├──────────────────────────►
│ │
│ 9. Stream Content │
│◄─────────────────────────┤
│ │
│ 10. Session End │
├──────────────────────────►
│ │
│ 11. Auto-Refund │
│◄─────────────────────────┤
│ │
Price in Lamports (1 SOL = 1,000,000,000 lamports):
| Price per Second | SOL per Second | 1 Minute Cost | 5 Minutes Cost |
|---|---|---|---|
| 100,000 | 0.0001 SOL | 0.006 SOL | 0.03 SOL |
| 500,000 | 0.0005 SOL | 0.03 SOL | 0.15 SOL |
| 1,000,000 | 0.001 SOL | 0.06 SOL | 0.3 SOL |
| 10,000,000 | 0.01 SOL | 0.6 SOL | 3 SOL |
| Variable | Description | Default | Required |
|---|---|---|---|
PORT |
Server port | 4021 | No |
NODE_ENV |
Environment | development | No |
SOLANA_NETWORK |
devnet or mainnet-beta | devnet | Yes |
SOLANA_RPC_URL |
Solana RPC endpoint | https://api.devnet.solana.com | Yes |
SERVICE_WALLET_PUBLIC_KEY |
Merchant public key | Generated | No* |
SERVICE_WALLET_PRIVATE_KEY |
Merchant private key | None | No** |
MIN_PRICE_PER_SECOND |
Minimum price in lamports | 1000 | No |
SERVICE_FEE_PERCENTAGE |
Platform fee % | 5 | No |
MAX_SESSION_DURATION |
Max session time (seconds) | 3600 | No |
ALLOWED_ORIGINS |
CORS origins | * | No |
* If not provided, a temporary wallet is generated (not recommended for production)
** Required for automatic refunds and creator payments
Solution: Ensure your private key is in the correct format:
[1,2,3,...] (64 numbers)Solution:
Solution:
Solution:
SERVICE_WALLET_PRIVATE_KEY is setsolana airdrop 2 <YOUR_WALLET> --url devnet
curl -X POST http://localhost:4021/api/mask \
-H "Content-Type: application/json" \
-d '{
"originalUrl": "https://picsum.photos/800/600",
"pricePerSecond": 100000,
"estimatedDuration": 60,
"title": "Test Image",
"creatorWallet": "YOUR_WALLET_ADDRESS"
}'
accessUrl in your browser.Contributions are welcome! Please follow these steps:
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
Made with ❤️ using Solana and WS402
Last updated: November 2025
Open Source AI trading agent that operates autonomously across 1000+ markets - Polymarket, Kalshi, Binance, Hyperliquid, Solana DEXs, 5 EVM chains. Scans for edge, executes instantly, manages risk while you sleep. Agent commerce protocol for machine-to-machine payments. Self-hosted. Built on Claude.
Drop-in OpenAI Python client with transparent x402 payment support.
Client SDK for the Vybe x402 API. Pay-per-call USDC over HTTP and prepaid-credit WebSocket streaming for Vybe's Solana analytics API. Built for AI agents.
Drop-in OpenAI Typescript client with transparent x402 payment support.
Autonomous AI BD Agent for SolCex Exchange: 24/7 Cross-Chain Token Scoring & Payments 2026
Rust SDK for the x402 payment protocol.
DePIN for Vintage Hardware — Proof-of-Antiquity blockchain where old machines outmine new ones. AI-powered hardware fingerprinting, 15+ CPU architectures, Solana bridge (wRTC). $0 VC.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Agent skills for building, shipping, and growing software products
The payment rail AI agents use to get paid without human approval. Optimistic settlement on @solana. Jobs auto-finalize after a challenge period, disputed jobs escalate to a bonded arbitrator. One protocol, any agent.
Encrypted vault, ZK settlement archiving, x402 payment receipts, Agent Passport binding, and Solana anchoring for OpenClaw and agent runtimes. Drop-in stack — compression, privacy, payments, identity.