x402 Stellar Fetch

Fetch wrapper that auto-pays 402 responses for simple client integrations.

Installation

npm install x402-stellar-fetch @stellar/stellar-sdk

Usage

import { wrapFetchWithPayment, createKeypairSigner } from "x402-stellar-fetch";
import { Keypair } from "@stellar/stellar-sdk";

const keypair = Keypair.fromSecret("SXXX...");
const signer = createKeypairSigner(keypair);

// Automatically handles 402 Payment Required responses
const fetchWithPay = wrapFetchWithPayment(fetch, signer);
const response = await fetchWithPay("https://api.example.com/premium");