Skip to content

​Before you charge real money

  1. Move to the x402 SDK. This tutorial uses x402 version 1 message shapes so you can read every check. New integrations should use version 2: the @x402/express (or @x402/next, @x402/hono) middleware on the server, @x402/fetch on the client, and @x402/svm for Solana. Version 2 sends the price in a PAYMENT-REQUIRED header, and uses PAYMENT-SIGNATURE and PAYMENT-RESPONSE in place of X-PAYMENT and X-PAYMENT-RESPONSE. x402 on Solana has a server and a client built with these packages.
  2. Choose a facilitator. With the SDK, a facilitator verifies and settles payments for your server, and on Solana it can pay the network fee for the client. Use a hosted facilitator, run your own, or settle inside your server as this tutorial does. See x402 facilitators.
  3. Switch to mainnet values. Set the environment variables from the table below. Use an RPC provider: public endpoints are rate-limited.
  4. Create your USDC token account first. The client’s transfer doesn’t create the payTo wallet’s USDC account, so create it before you publish the price, or every payment fails.
  5. Store accepted payment signatures. The example keeps them in memory. Put them in your database so every server instance, and the server after a restart, refuses a payment that was already used.
  6. Log the signature with each paid request. It is your receipt: anyone can look the transaction up on the network.
  7. Rate-limit unpaid requests. A 402 is cheap to send, but each one still costs you a request.
  8. Limit what clients can spend. Give every client and agent a maxAmount, and a wallet that holds only what it may spend.

​Devnet and mainnet values

VariableDevnet (testing)Mainnet (real money)
RPC_URLhttps://api.devnet.solana.comYour RPC provider’s HTTPS URL
RPC_SUBSCRIPTIONS_URLwss://api.devnet.solana.comYour RPC provider’s WebSocket URL
USDC_MINT4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDUEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
X402_NETWORKsolana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp
MoneyFree test tokensReal USDC

​You paywalled an API

You paid for an API as a client, read the server that takes the payment, and ran both on your machine. From here: