Skip to main content

Documentation Index

Fetch the complete documentation index at: https://crushrewards.dev/docs/llms.txt

Use this file to discover all available pages before exploring further.

x402 is an open protocol that maps the long-dormant HTTP 402 Payment Required status code onto modern stablecoin rails. Crush Rewards implements x402 on both Solana and Base for USDC. The Crush Rewards server is also indexed on x402scan so any x402-aware agent can discover it without prior knowledge of the URL.

How it works

The payment authorization is bound to the specific request — it cannot be replayed against a different endpoint.

Integrate with @x402/fetch

The official @x402/fetch wrapper handles the full handshake — discovery, signing, retry — transparently:
import { wrapFetchWithPayment } from "@x402/fetch";
import { createSolanaSigner } from "@x402/svm";

const signer = createSolanaSigner(process.env.SOLANA_PRIVATE_KEY!);
const paidFetch = wrapFetchWithPayment(fetch, signer);

const res = await paidFetch(
  "https://api.crushrewards.dev/v1/shopper/best-price?q=airpods+pro&country=US"
);
const data = await res.json();

Manual integration

If you can’t use the SDK, the protocol is two HTTP requests:
// 1. Discovery — call without payment, parse the 402 response
const discovery = await fetch(url).then((r) => r.json());
const { recipient, price, chain } = discovery["x-payment-info"].x402;

// 2. Sign a USDC transfer authorization for `price` USDC to `recipient`
//    on `chain`, bound to this request URL. Format depends on chain.
const xPayment = await signUsdcTransferAuthorization({ recipient, price, chain });

// 3. Retry with the X-Payment header
const response = await fetch(url, {
  headers: { "X-Payment": xPayment },
});
The exact signing payload format is defined in the x402 spec. Use @x402/svm/exact/client or @x402/evm/exact/client if you want signing helpers without the fetch wrapper.

Supported chains

ChainAssetSettlement time
SolanaUSDC (SPL)~1 second
BaseUSDC (ERC-20)~2 seconds
The recipient address is returned in the x-payment-info discovery block — never hardcode it. We may rotate keys without prior notice.

Failed payments

If chain settlement fails (insufficient balance, expired authorization, network issue), the API returns 402 Payment Required with an error field describing the cause. Retry with a fresh authorization.