402LXP Protocol
Implement HTTP micropayments on Paxeer using the 402LXP protocol for API monetization and agent-to-agent payments.
402LXP brings HTTP-native micropayments to Paxeer, enabling you to monetize APIs, premium content, and digital services with instant, low-cost payments. Whether you're building AI agent APIs, data feeds, or premium content platforms, 402LXP makes it simple to add payment gates to any HTTP endpoint.
Built for Paxeer's agent layer: 402LXP runs on LayerX - Paxeer's dedicated agent channel - leveraging fast finality, low gas, and EVM compatibility to enable seamless machine-to-machine payment flows that complete in milliseconds.
Why 402LXP on Paxeer?
- Fast & Cheap Payments: Paxeer's Twin Turbo Consensus delivers ~400ms finality with minimal gas. Perfect for pay-per-request APIs and agent-to-agent payments.
- EVM Compatible: Use familiar tools like Viem, Ethers.js, and Hardhat. All existing Ethereum tooling works seamlessly on Paxeer.
- Agent-Native: 402LXP is designed for autonomous AI agents on LayerX - agents can pay for inference, data, and services without human intervention.
Use Cases on Paxeer
The 402LXP protocol enables a wide range of monetization strategies for web services and APIs:
- AI & Machine Learning Services: Per-inference pricing for LLM APIs, image generation, and data processing.
- Premium Content & Media: Pay-per-view articles, videos, and subscription gates.
- Real-Time Data & APIs: Market data feeds, weather and IoT data monetization.
- Agent-to-Agent Commerce: Autonomous agents paying other agents for services on LayerX.
Protocol Overview
402LXP leverages the HTTP 402 status code ("Payment Required") to facilitate blockchain-based micropayments directly through HTTP requests.
Key Features
- HTTP-Native: Uses standard HTTP status codes and headers
- Blockchain Integration: Runs on Paxeer's EVM layer via LayerX
- Real-time Settlement: Enables instant payment verification
- Interoperable: Works across different payment schemes and networks
- Micropayment Support: Designed for small, frequent transactions
Payment Flow
- Initial Request: Client makes a request to a protected resource
- 402 Response: Server responds with HTTP 402 and payment requirements
- Payment Execution: Client executes blockchain payment (USDX on LayerX)
- Payment Proof: Client includes payment proof in subsequent request
- Resource Access: Server verifies payment and grants access
Payment Challenge Response
{
"x402Version": 1,
"accepts": [
{
"scheme": "exact",
"network": "paxeer",
"maxAmountRequired": "1000",
"resource": "/api/data",
"description": "Get current data",
"mimeType": "application/json",
"payTo": "0x9dC2aA0038830c052253161B1EE49B9dD449bD66",
"maxTimeoutSeconds": 300,
"asset": "0xUSDX_TOKEN_ADDRESS",
"extra": {
"name": "USDX",
"version": "2",
"reference": "paxeer-1234567890-abc123"
}
}
]
}
Payment Execution
The agent executes a USDX transfer on Paxeer:
const transferData = encodeFunctionData({
abi: [
{
name: 'transfer',
type: 'function',
stateMutability: 'nonpayable',
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' }
],
outputs: [{ name: '', type: 'bool' }]
}
],
functionName: 'transfer',
args: [recipient, amountInUnits]
});
const hash = await walletClient.sendTransaction({
to: USDX_TOKEN_ADDRESS,
data: transferData
});
Payment Proof Submission
Client → GET /api/data + X-Payment Header (base64 encoded payment proof)
Server → Verifies payment + Returns data
Code Example: Paid API Implementation
export async function GET(req: NextRequest) {
const paymentHeader = req.headers.get('x-payment');
if (!paymentHeader) {
return NextResponse.json(generatePaymentChallenge(), { status: 402 });
}
const verification = await verifyPayment(paymentHeader);
if (!verification.isValid) {
const challenge = generatePaymentChallenge();
challenge.error = verification.reason || 'Payment verification failed';
return NextResponse.json(challenge, { status: 402 });
}
return NextResponse.json({ data: "Your protected content" });
}
Security Considerations
Payment Verification
- On-chain Verification: All payments are verified against the Paxeer blockchain.
- Transaction Receipt Validation: Ensures transaction success and proper recipient.
- Payment Caching: Prevents double-spending by caching verified payments.
- Reference Validation: Unique payment references prevent replay attacks.
Network Security
- HTTPS Required: All API communications use secure connections.
- Base64 Encoding: Payment proofs are base64 encoded for safe transmission.
- Timeout Handling: Payment challenges include timeout mechanisms.
Wallet Security
- Private Key Management: Private keys are stored securely in environment variables.
- Transaction Signing: All transactions are properly signed before submission.
- Balance Validation: Sufficient balance checks before payment execution.