Skip to main content
This guide shows how to pay x402-protected endpoints using a Crossmint wallet. The example uses the @x402/core client library to handle the 402 negotiation and payment flow automatically.

Prerequisites

Install dependencies

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.