Quickstart for Sellers

This guide walks you through integrating with x402 to enable payments for your API or service. By the end, your API will be able to charge buyers and AI agents for access.

Note: This quickstart begins with testnet configuration for safe testing. When you're ready for production, see Running on Mainnet for the simple changes needed to accept real payments on Base (EVM) and Solana networks.

Prerequisites

Before you begin, ensure you have:

Note: The Python SDK is currently under development for x402 v2. For immediate v2 support, use TypeScript or Go.

Note We have pre-configured examples available in our repo for both Node.jsarrow-up-right and Goarrow-up-right. We also have an advanced examplearrow-up-right that shows how to use the x402 SDKs to build a more complex payment flow.

1. Install Dependencies

Install the x402 Express middleware packagearrow-up-right.

npm install @x402/express @x402/core @x402/evm

2. Add Payment Middleware

Integrate the payment middleware into your application. You will need to provide:

  • The Facilitator URL or facilitator client. For testing, use https://x402.org/facilitator which works on Base Sepolia and Solana devnet.

  • The routes you want to protect.

  • Your receiving wallet address.

Full example in the repo herearrow-up-right.

Route Configuration Interface:

When a request is made to these routes without payment, your server will respond with the HTTP 402 Payment Required code and payment instructions.

3. Test Your Integration

To verify:

  1. Make a request to your endpoint (e.g., curl http://localhost:4021/weather).

  2. The server responds with a 402 Payment Required, including payment instructions in the PAYMENT-REQUIRED header.

  3. Complete the payment using a compatible client, wallet, or automated agent. This typically involves signing a payment payload, which is handled by the client SDK detailed in the Quickstart for Buyers.

  4. Retry the request, this time including the PAYMENT-SIGNATURE header containing the cryptographic proof of payment.

  5. The server verifies the payment via the facilitator and, if valid, returns your actual API response (e.g., { "data": "Your paid API response." }).

When using the CDP facilitator, your endpoints can be listed in the x402 Bazaar, our discovery layer that helps buyers and AI agents find services. To enable discovery:

Learn more about the discovery layer in the Bazaar documentation.

5. Error Handling

  • If you run into trouble, check out the examples in the repoarrow-up-right for more context and full code.

  • Run npm install or go mod tidy to install dependencies


Running on Mainnet

Once you've tested your integration on testnet, you're ready to accept real payments on mainnet.

1. Update the Facilitator URL

For mainnet, use the CDP facilitator:

2. Update Your Network Identifier

Change from testnet to mainnet network identifiers:

3. Register Multiple Schemes (Multi-Network)

For multi-network support, register both EVM and SVM schemes:

4. Update Your Wallet

Make sure your receiving wallet address is a real mainnet address where you want to receive USDC payments.

5. Test with Real Payments

Before going live:

  1. Test with small amounts first

  2. Verify payments are arriving in your wallet

  3. Monitor the facilitator for any issues

Warning: Mainnet transactions involve real money. Always test thoroughly on testnet first and start with small amounts on mainnet.


Network Identifiers (CAIP-2)

x402 v2 uses CAIP-2arrow-up-right format for network identifiers:

Network
CAIP-2 Identifier

Base Mainnet

eip155:8453

Base Sepolia

eip155:84532

Solana Mainnet

solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp

Solana Devnet

solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1

See Network Support for the full list.


Next Steps

For questions or support, join our Discordarrow-up-right.

Summary

This quickstart covered:

  • Installing the x402 SDK and relevant middleware

  • Adding payment middleware to your API and configuring it

  • Testing your integration

  • Deploying to mainnet with CAIP-2 network identifiers

Your API is now ready to accept crypto payments through x402.

Last updated