Skip to content
Fast
SDK References / Payment Protocol Adapters / x402-sdk

x402-client

Pay for x402-protected HTTP resources with @fastxyz/x402-client

@fastxyz/x402-client provides x402Pay() for payment-aware HTTP requests. See the package README for the current X402PayParams type and complete examples.

Terminal window
npm install @fastxyz/x402-client
import { x402Pay } from '@fastxyz/x402-client';
const result = await x402Pay({
url: 'https://api.example.com/premium',
wallet: {
type: 'fast',
privateKey,
publicKey,
address,
rpcUrl: 'https://api.fast.xyz/proxy-rest',
},
});

The public API accepts a Fast wallet or an EVM wallet, plus EVM network configuration where needed. If both wallet types and bridgeConfig are supplied, supported flows can bridge Fast-side funds when the EVM balance is insufficient. That cross-network movement is asynchronous and requires correct AllSet endpoints.

x402Pay() is a spending operation, not a dry-run API. If you need a price preview, make a separate request and inspect the 402 requirements without calling x402Pay(). Do not assume that a preview reserves the price or guarantees a later payment. For Fast payments, result.payment.amount is a raw smallest-unit string; humanize it with the asset’s actual decimals. The current EVM path has a USDC six-decimal assumption, so consumers should not infer units from the display value alone.

An HTTP timeout after payment is an uncertain outcome. Reconcile payment identity and resource delivery before paying again; a second call can be a second payment. Protect private keys and never log the payment payload or signer material.