@x402/core client library to handle the 402 negotiation and payment flow automatically.
Prerequisites
- A Crossmint EVM wallet on Base with USDC. See the Wallets quickstart.
- The agent must be authorized as a signer on the wallet. See Authorize the Agent.
Install dependencies
Pay an x402 endpoint
x402-payment.tsx
How the code works
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.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.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.Learn more
Wallets quickstart
Set up a stablecoin wallet for your agent.

