Drop-in fetch wrapper that auto-pays HTTP 402 endpoints on Abstract.
x402-fetch is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on abstract, abstract-blockchain, developer-tools, erc-3009. It currently has 1 GitHub stars and 1 forks, and sits alongside related tools like x402charity, tdm-integration-kit, tdm-sdk.
Drop-in fetch wrapper that auto-pays HTTP 402 endpoints on Abstract.
One function. Wraps native fetch(), detects 402 responses, signs the payment, retries with the payment header. Zero config required.
npm install x402-fetch viem
viem is a peer dependency. You need it for wallet creation.
import { createX402Fetch } from "x402-fetch";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { abstractTestnet } from "viem/chains";
const wallet = createWalletClient({
account: privateKeyToAccount("0x..."),
chain: abstractTestnet,
transport: http(),
});
const x402fetch = createX402Fetch(wallet);
// Use like normal fetch. Payments handled automatically.
const res = await x402fetch("https://api.example.com/premium-data");
const data = await res.json();
x402fetch() exactly like fetch()transferWithAuthorization using your viem wallet clientX-PAYMENT header (base64 JSON)The server's facilitator verifies the signature and settles the payment onchain. Your code just gets the response.
createX402Fetch(wallet, config?)Returns a fetch function that handles 402 payment flows automatically.
Parameters:
| Parameter | Type | Description |
|---|---|---|
wallet |
WalletClient |
A viem wallet client with an account and chain attached |
config |
X402Config |
Optional configuration (see below) |
Returns: (input: string \| URL \| Request, init?: RequestInit) => Promise<Response>
interface PaymentRequirements {
x402Version: number;
scheme: string;
network: string;
amount: string;
asset: string;
recipient: string;
extra?: { name?: string; description?: string };
}
interface PaymentDetails {
url: string;
amount: string;
asset: string;
recipient: string;
network: string;
name?: string;
description?: string;
}
interface X402Config {
maxPayment?: string;
onPayment?: (details: PaymentDetails) => void | Promise<void>;
}
maxPaymentSet a ceiling on automatic payments. If a server requests more than this amount, the wrapper throws instead of signing.
const x402fetch = createX402Fetch(wallet, {
maxPayment: "0.01", // in token units
});
onPaymentCallback invoked before each payment is signed. Useful for logging, analytics, or user confirmation flows.
const x402fetch = createX402Fetch(wallet, {
onPayment: (details) => {
console.log(`Paying ${details.amount} to ${details.recipient} for ${details.name}`);
},
});
| Tool | What it does |
|---|---|
| abstract-audit | Catch EVM incompatibilities in your Solidity contracts |
| x402-fetch (this package) | Auto-pay HTTP 402 endpoints on Abstract |
| abstract-gas | Estimate gas costs on Abstract vs Ethereum |
Created by Heathen
Built in Mirra
MIT License
Copyright (c) 2026 Heathen
Automatic micro-donations powered by x402. Drop-in Express/Next.js middleware that sends USDC to charities on every user action. npm install x402charity.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Open contract-facing SDK for payable routes and gateway-backed integrations. Thin public surface for authorize, checkout, and session flows.
Open Source AI trading agent that operates autonomously across 1000+ markets - Polymarket, Kalshi, Binance, Hyperliquid, Solana DEXs, 5 EVM chains. Scans for edge, executes instantly, manages risk while you sleep. Agent commerce protocol for machine-to-machine payments. Self-hosted. Built on Claude.
Drop-in OpenAI Python client with transparent x402 payment support.
Drop-in OpenAI Typescript client with transparent x402 payment support.
TypeScript Interface for Machine Payments Protocol
Production-ready x402 facilitator server.
Rust SDK for the x402 payment protocol.