x402-guard-sdk
v1.0.0
Published
Monetize any API in 60 seconds using Stacks blockchain - Blockchain-native API monetization middleware
Maintainers
Readme
x402 Guard SDK - Core Package
Core SDK for monetizing APIs with Stacks blockchain.
Installation
npm install x402-guard-sdkQuick Start
import express from 'express';
import { x402Guard } from 'x402-guard-sdk';
const app = express();
app.use(x402Guard({
price: 10000,
freeTier: 10,
wallet: 'ST3ES29PTAHRWTCAK6MPP3YCK84JNSJFNH340BK8P'
}));
app.get('/api/data', (req, res) => {
res.json({ data: 'protected' });
});
app.listen(3000);API
x402Guard(config)
Main middleware function.
Parameters:
{
wallet: string; // Required: Your Stacks wallet
price?: number; // Price in microSTX (default: 100000)
freeTier?: number; // Free requests (default: 10)
token?: string; // Token type (default: 'STX')
model?: string; // Pricing model (default: 'per-call')
network?: string; // Network (default: 'testnet')
botProtection?: boolean; // Enable bot detection (default: true)
}Returns: Express middleware function
Classes
PaymentValidator
Verify Stacks blockchain transactions.
import { PaymentValidator } from 'x402-guard-sdk';
const validator = new PaymentValidator({
wallet: 'ST3ES29...',
network: 'testnet'
});
const result = await validator.verify(txId);BotDetector
Detect and block bot traffic.
import { BotDetector } from 'x402-guard-sdk';
const detector = new BotDetector();
const analysis = detector.analyze(req);
if (analysis.isBot) {
// Block request
}RateLimiter
Track free tier usage per client.
import { RateLimiter } from 'x402-guard-sdk';
const limiter = new RateLimiter();
const result = limiter.track(clientId, freeTier);DashboardReporter
Track earnings and statistics.
import { DashboardReporter } from 'x402-guard-sdk';
const reporter = new DashboardReporter();
reporter.recordPayment({ txId, amount, sender });
const stats = reporter.getStats();Documentation
License
MIT
