Verifies and settles presigned USDC transactions so your API can charge
per request — agents set feePayer = facilitator
and never need SOL.
The facilitator slots into standard x402 middleware. Set feePayer once and let the facilitator handle gas and broadcast.
Query the facilitator to get the feePayer address, supported networks, and USDC asset address. Point your agent at this once at startup.
Create a TokenTransferChecked transaction. Set tx.feePayer = facilitatorPubkey and sign as transfer authority only — no SOL required.
Forward the signed payload via X-PAYMENT header. The facilitator runs 10 checks, co-signs slot 0 as feePayer, broadcasts, and confirms on-chain.
Every payment request stays inside standard HTTP semantics while the facilitator handles verification, co-signing, and settlement.
feePayer check, TransferChecked detection, Ed25519 signature, amount, ATA derivation, mint, replay guard, and risk scoring — every request.
Agent signs only as transfer authority. The facilitator co-signs slot 0 as feePayer and pays all network fees (~0.000005 SOL/tx).
SQLite deduplication on payment signature. Every settled signature is recorded permanently — duplicates return ALREADY_SETTLED.
Decodes legacy and v0 Solana wire transactions using compact-u16 parsing. No blind trust in SDK structs or agent-supplied metadata.
Optional X-AGENT-TRACE header enables automated screening: dangerous tool names, velocity limits, and high-value amount blocks.
60 req/min per IP on /verify. Hard 10 req/min per IP on /settle to prevent broadcast spam. Returns 429 with retryAfter.
Build the USDC transfer, set feePayer to the facilitator address from /supported, sign as authority, and include in the X-PAYMENT header.
// 1. Get feePayer address from facilitator (API key required) const API_KEY = 'sk_your_api_key_here'; const { feePayer } = await fetch('https://facilitator.agentstrail.ai/supported', { headers: { 'Authorization': `Bearer ${API_KEY}` }, }).then(r=>r.json()); // 2. Build TransferChecked transaction const conn = new Connection('https://api.devnet.solana.com'); const USDC = new PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU'); const srcAta = await getAssociatedTokenAddress(USDC, agentKeypair.publicKey); const dstAta = await getAssociatedTokenAddress(USDC, new PublicKey(merchantWallet)); const tx = new Transaction({ feePayer: new PublicKey(feePayer), // <-- facilitator pays gas recentBlockhash: (await conn.getLatestBlockhash()).blockhash, }); tx.add(createTransferCheckedInstruction( srcAta, USDC, dstAta, agentKeypair.publicKey, 1_000_000n, 6 )); // 3. Sign as authority only (no SOL needed) tx.partialSign(agentKeypair); const txBase64 = tx.serialize({ requireAllSignatures: false }).toString('base64'); const sigBase58 = bs58.encode(tx.signatures[0].signature); // 4. Call paid API with X-PAYMENT + Authorization headers const payment = { x402Version: 1, scheme: 'exact', network: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG', payload: { signature: sigBase58, transaction: txBase64 }, }; await fetch('https://merchant.api/resource', { headers: { 'X-PAYMENT': JSON.stringify(payment) }, }); // Or call the facilitator directly: await fetch('https://facilitator.agentstrail.ai/settle', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}`, }, body: JSON.stringify({ paymentPayload: payment, paymentRequirements }), });
Protect your API with x402 and accept USDC payments from AI agents. The facilitator handles verification, co-signing, and broadcast.
import express from 'express'; import { paymentMiddleware } from 'x402-express'; const app = express(); // Point x402 middleware at this facilitator const facilitatorConfig = { url: process.env.FACILITATOR_URL, createAuthHeaders: async () => ({ verify: { 'Authorization': `Bearer ${process.env.FACILITATOR_API_KEY}` }, settle: { 'Authorization': `Bearer ${process.env.FACILITATOR_API_KEY}` }, supported: { 'Authorization': `Bearer ${process.env.FACILITATOR_API_KEY}` }, }), }; // Protect your endpoint — agents pay 0.01 USDC per request app.use(paymentMiddleware( process.env.MERCHANT_WALLET, // your Solana wallet address { 'GET /api/data': { price: '$0.01', network: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG', }, }, facilitatorConfig )); app.get('/api/data', (req, res) => { res.json({ result: 'premium data' }); }); app.listen(3001); // The middleware handles the full x402 flow automatically: // Agent hits /api/data → gets 402 + PaymentRequirements // Agent builds tx, sets feePayer = facilitator pubkey // Agent sends X-PAYMENT header → middleware calls /verify // Middleware calls /settle → facilitator co-signs + broadcasts // Agent receives the API response ✅
Five endpoints. POST bodies are identical for /verify and /settle — just switch the URL to confirm settlement.
API keys are required to access /verify,
/settle, and
/supported.
Fill out a short form and your key will be generated within 24 hours.