@x402/core client library to handle the 402 negotiation and payment flow automatically.
Prerequisites
- A funded Crossmint EVM wallet on Base with USDC. See the Wallets quickstart, then fund it with USDC.
- The agent must be authorized as a signer on the wallet. See Authorize the Agent.
Install dependencies
Fund the wallet
Before the wallet can pay an x402 endpoint, it must hold USDC. In production, fund it through the Crossmint onramp or by transferring USDC directly towallet.address. In staging, wallet.stagingFund(5) mints test USDXM into the wallet.
x402-funding.tsx
Pay an x402 endpoint
x402-payment.tsx
How the code works
1
Create an EVM signer from the Crossmint wallet
The
EVMWallet.from(wallet) call wraps the Crossmint wallet into an EVM-compatible interface. A custom signer object is created that delegates signTypedData calls to the Crossmint wallet, which signs on Base using the agent’s delegated permissions.2
Register the signer with the x402 client
The
x402Client is initialized and the EVM scheme is registered for all EIP-155 chains (eip155:*). This tells the x402 client how to sign payments on any EVM chain.3
Wrap fetch with x402 payment handling
wrapFetchWithPayment returns a modified fetch function that automatically handles the 402 flow: if a request returns 402 Payment Required, it reads the payment terms, signs a stablecoin payment, and retries with the payment proof attached.4
Verify the payment receipt
After a successful response,
getPaymentSettleResponse extracts the settlement receipt from the response headers, confirming the payment was processed onchain.Learn more
Wallets quickstart
Set up a stablecoin wallet for your agent.
Onramps
Fund the wallet with USDC so the agent can pay.

