x402 support is built for agents and developers paying for resources programmatically, via the SDK & CLI (
@veil-cash/sdk) and the MCP Server (@veil-cash/mcp). It funds payments from your private USDC balance—no custom merchant integration required.How it works
- Your agent requests a paid resource and receives a standard 402 with x402 v2 payment requirements.
- The SDK derives a fresh payer address deterministically from your Veil key and a payer index.
- The SDK builds a normal Veil USDC withdrawal proof and funds that payer with the exact payment amount through the Veil relay.
- The payer address signs the standard x402 payment, and the merchant’s facilitator settles it onchain and pays gas for that leg.
payerIndex), which avoids reusing the same public address across payments. The Veil withdrawal to fund that payer and the x402 payment from it are still public onchain legs.
Privacy boundaries
Veil hides your source wallet and private balance graph. It does not hide the funding or payment legs. Still visible or correlatable:- the Veil pool withdrawal to the fresh payer address
- the payer address’s payment to the merchant
- the USDC amount
- timing between funding and payment
- merchant and resource-server metadata
- your agent’s IP/session metadata, unless routed separately
Supported scope
The MVP is intentionally narrow:- Protocol: x402 v2,
exactscheme - Network: Base mainnet (
eip155:8453) - Asset: Base USDC (
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) - Funding: your private Veil USDC balance
upto, batch settlement), other networks, or non-USDC assets are rejected with a clear error before any funds move.
Paying from an agent (MCP)
The Veil MCP server exposesveil_pay_x402 for agents:
- Requires
confirm: true. - Pre-flights the endpoint before funding—if the unpaid probe does not return
402, it withdraws nothing (useful for malformed requests). If the probe returns402but the merchant validates only after payment, the payer may still be funded while delivery fails; see Recovery. - Enforces a spend cap:
maxPaymentis a decimal USDC string (e.g."0.10"), defaulting to and hard-capped at 10 USDC. A requirement above the cap is rejected before funding. - Reuses funded payers: before a fresh withdrawal it scans already-funded payer addresses; if one holds enough USDC it offers reuse instead of withdrawing again. This recovers funds when a payment funded but delivery failed. Reusing a funded payer links both attempts to the same public EOA—MCP surfaces this as
reuse_availablerather than doing it silently.
veil_x402_quote for a dry run, veil_x402_receipts for spend history, and veil_x402_payer_balances to check for funds stranded on a payer. See the MCP Server page for the full tool list and setup.
Paying from application code (SDK)
payerIndex for each payment. quoteX402Resource() probes a resource without paying; getX402PayerBalances() reports USDC held by each derived payer address (useful for recovering funds after a failed payment); and reuseExistingBalance: true retries a payment whose funding succeeded but whose delivery failed, paying directly from the already-funded payer with no new withdrawal. See SDK & CLI for install and setup.
Recovery
If a payment fails after funding, the USDC stays on the payer address and is recoverable—the payer key is derived from your Veil key and the payer index. The MCP reuse flow and the SDK’sreuseExistingBalance path recover these funds without a second withdrawal.
For the underlying tooling, see SDK & CLI and MCP Server. For how your keys work, see Veil Keypair.