Client Usage
Installation
pnpm add @shade402/client @shade402/core @solana/web3.jsClient Types
Explicit Client
Automatic Client
Explicit Client
Basic Usage
import { X402Client } from '@shade402/client';
import { Keypair } from '@solana/web3.js';
const wallet = Keypair.generate();
const client = new X402Client(wallet, process.env.SOLANA_RPC_URL);
try {
// Make initial request
let response = await client.get('https://api.example.com/data');
// Check if payment required
if (client.paymentRequired(response)) {
// Parse payment request
const paymentRequest = client.parsePaymentRequest(response);
// Create payment
const authorization = await client.createPayment(paymentRequest);
// Retry with payment
response = await client.get('https://api.example.com/data', {
payment: authorization,
});
}
// Process response
console.log(response.data);
} finally {
// Always close the client
await client.close();
}HTTP Methods
Options
Local Development
Automatic Client
Basic Usage
Configuration Options
HTTP Methods
Error Handling
Resource Encryption
Payment Amount Control
URL Validation
Cleanup
Complete Example
Best Practices
Next Steps
Last updated
