@x402 packages.
Install
Load a Solana wallet
The wallet is used to sign both x402exact payments and SIWX messages. It must be a funded Solana mainnet wallet (USDC + a small SOL balance for transaction fees) and must not equal the gateway’s payTo wallet.
Wrap fetch with x402
@x402/fetch transparently handles the 402 challenge/retry cycle, including exact payment and SIWX signing.
gatewayFetch is now a drop-in replacement for fetch against any gateway route.
Call a paid RPC route
gatewayFetch will:
- Hit the gateway and receive
402 Payment Required. - Build an SVM
exacttransfer for the price advertised in the challenge. - Retry with
PAYMENT-SIGNATURE. - Return the upstream response to your code.
Call a Tokens API (SIWX) route
gatewayFetch constructed a SIWX payload, signed it with your wallet, and sent it in the SIGN-IN-WITH-X header.
Discover routes dynamically
For agent-style clients that need to enumerate available routes:inputSchema, outputSchema, and (for templated paths) pathParamsSchema are valid JSON Schema documents. You can feed them to any validator.
Common integration patterns
Pay-per-call worker
Best fit: background jobs that need Solana data but are cost-sensitive.SIWX-only Tokens client
Best fit: dashboards and explorers that want Tokens API data without shipping an API key.Agent wallet
Best fit: autonomous agents that reason about which route to call and should pay directly.- Fetch
GET /v1/catalogat startup. - Pass the route descriptors into the agent’s tool schema.
- Use
gatewayFetchto invoke selected routes.
priceUsd and every SIWX route advertises accessMode: "siwx", agents can budget and choose between paid and unpaid calls deterministically.
Error handling
See Payment headers reference for the full list of headers and error shapes. In brief:400— invalid input (guardrails violated, malformed body or query params). No settlement.402— payment or SIWX challenge. Your x402 client library retries automatically.429— rate limited. Back off;retryAfterMsis included in the body.5xx— upstream or facilitator failure. No settlement on failed paid requests.
Base URL
The default base URL ishttps://gateway.agonx402.com. Self-hosted deployments change this — see Deploy.

