Set up your x402 seller wallet

Before you can sell data, you need a place to receive the micropayments. This section covers the foundational infrastructure for an x402 seller: your wallet and the role of the facilitator. We will use Coinbase Developer Platform (CDP) as the reference implementation, as it provides the most straightforward path for integrating x402 into existing services.

Choose a Base-compatible wallet

x402 payments settle on the Base network. To accept these payments, you need a wallet that can hold USDC on Base. The most reliable option for developers is the Coinbase Developer Platform (CDP) wallet, which is purpose-built for API integrations.

You do not need to manage private keys manually. CDP provides a managed wallet environment that handles key security and transaction signing automatically. This reduces the risk of losing funds due to mismanaged keys, a common pitfall in crypto integrations. If you already have a wallet that supports Base, you can use that, but CDP is recommended for its developer experience and built-in support for x402 standards.

Note: Base is the primary network for x402 due to low transaction costs and fast settlement times. Using other networks may result in fees that exceed the value of the data being sold.

Understand the facilitator role

In the x402 protocol, the "facilitator" is the entity that helps route payments between the buyer (or AI agent) and your seller wallet. For CDP users, the facilitator is effectively handled by the CDP infrastructure. When a buyer sends a payment, the facilitator ensures the transaction is valid, broadcasts it to the Base network, and confirms the receipt of funds in your seller wallet.

This separation of concerns means you don't need to build a complex payment routing system yourself. You focus on serving the data; the facilitator handles the settlement. This is critical for high-stakes research feeds where payment reliability is as important as data accuracy.

Verify your setup

Once your wallet is created, verify that it is connected to the Base network and holds a small amount of USDC to cover any initial gas fees for receiving payments. You can test this by sending a small test payment to your wallet address. If the payment confirms successfully, your seller wallet is ready for x402 integration.

For detailed instructions on creating and configuring your CDP wallet, refer to the Coinbase Developer Platform Quickstart for Sellers. This guide walks you through the technical steps of enabling your API to charge buyers and AI agents using x402.

Configure the payment-gated endpoint

Implementing the x402 protocol requires a server-side handler that validates incoming payments before releasing premium research data. Unlike standard API keys, x402 relies on HTTP 402 responses to signal that a microtransaction is required. This section walks you through the technical implementation, focusing on the logic needed to gate your endpoint securely.

1
Set up the x402 facilitator

Before handling requests, you need a facilitator to manage the blockchain transaction flow. Tools like Thirdweb’s x402 facilitator simplify this by abstracting the complex smart contract interactions. This facilitator acts as the bridge between your API and the blockchain network, ensuring that payments are verified in real-time. You will typically initialize this in your server environment to handle the USDC or stablecoin transactions required for access.

2
Implement the 402 response logic

Your endpoint must detect when a payment token is missing or invalid. When a client requests data without a valid x402 token, your server should respond with an HTTP 402 status code. This response includes a Payment-Required header that specifies the amount due and the wallet address to send it to. This is the core mechanism that enforces the paywall; the client cannot proceed until they interact with the facilitator to settle the debt.

3
Validate the payment token

Once a client presents a token, your server must verify its authenticity. This involves checking the token against the blockchain to ensure the transaction was confirmed and the amount matches the price of the research feed. You can use the facilitator’s SDK to perform this validation efficiently. If the token is valid and not expired, you grant access to the data. If it is invalid, you return the 402 response again, prompting a new transaction.

4
Serve the premium research data

Only after successful validation should your endpoint return the requested research data. This data is typically sensitive, such as real-time market feeds or proprietary AI inference results. Ensure that the response is returned in the same request cycle as the validation to maintain a seamless user experience. The client receives the data immediately, and the facilitator records the transaction on-chain for auditability.

For developers looking to test these integrations locally, having the right debugging tools is essential. A reliable API client can help you simulate the 402 responses and verify that your headers are being parsed correctly by the client-side SDK.

By following these steps, you create a robust payment-gated endpoint that leverages the x402 protocol to monetize premium research feeds effectively. This approach ensures that only paying users access your high-value data, while maintaining the security and transparency of blockchain transactions.

Integrate a facilitator for agent payments

Handling the cryptographic signing and verification for x402 endpoints is complex. You don’t want to build a custom payment router from scratch. Instead, use a facilitator like Thirdweb or the Coinbase Developer Platform (CDP). These tools act as a middleman, automating the heavy lifting of validating crypto payments and releasing API access.

Think of a facilitator as a digital bouncer. It checks the ID (the payment signature) at the door and only lets the guest in if the credentials are valid. This abstraction lets you focus on your API logic rather than blockchain mechanics.

Step 1: Choose your facilitator

Start by selecting a provider that fits your stack. Thirdweb offers a dedicated x402 facilitator that integrates well with Next.js and other modern frameworks. Alternatively, CDP provides a robust quickstart for sellers looking to enable payments for APIs or services. Both options are officially documented and widely used.

Step 2: Install the SDK

Add the facilitator’s SDK to your project dependencies. For example, if you choose Thirdweb, you will install their core package. If you use CDP, you will import their specific API client. This SDK provides the functions needed to interact with the blockchain and verify signatures.

Step 3: Configure payment parameters

Define the rules for your endpoint. Specify which stablecoin you accept (usually USDC) and the price per request. The facilitator needs to know how much to expect and which blockchain network to monitor for transactions. This configuration is typically handled via environment variables or a simple config object.

Step 4: Implement the verification middleware

This is the core integration. Wrap your API route with the facilitator’s verification function. When an AI agent sends a request, the middleware intercepts it. It checks the payment signature included in the headers against the blockchain. If the payment is valid and unspent, the request proceeds. If not, the middleware returns a 402 Payment Required error.

Step 5: Test with a sandbox

Before going live, test the flow using a testnet. Send a mock request with a test payment. Verify that the facilitator correctly validates the signature and that your API responds with the expected data. This step ensures your integration is robust and prevents accidental charges on the mainnet.

Test the endpoint with a live transaction

You have configured the headers and signed the payment. Now comes the moment of truth: sending the request to see if the premium research feed responds. This step verifies that your x402 implementation correctly processes the cryptocurrency payment and unlocks data access.

Send the request

Use a tool like curl or Postman to send a GET request to your target endpoint. Ensure the Authorization header includes your signed token. If the endpoint is configured correctly, it should accept the payment and return the requested data immediately. For a detailed walkthrough of the payment structure, refer to the complete guide on x402.

Verify the response

Check the HTTP status code. A successful transaction returns a 200 OK with the premium content in the body. If you receive a 402 Payment Required, the payment was rejected or malformed. Double-check your signature and ensure the payment amount matches the endpoint's requirements. Browserbase’s documentation offers further insights into handling these integration nuances.

Troubleshoot common issues

If the request fails, verify that your wallet has sufficient funds and that the network is not congested. Sometimes, a delay in blockchain confirmation can cause the endpoint to reject the token. In such cases, wait a few seconds and retry the request. This ensures the payment is recognized as valid before accessing the data.

Common integration mistakes to avoid

Even with a solid x402 implementation, small oversights can break your data pipeline. The most frequent errors involve header formatting and transaction reliability. Since premium research feeds often involve high-value data, these mistakes can lead to silent failures or unexpected charges.

Incorrect header formatting

The x402 protocol relies on specific HTTP headers to authorize transactions. A common mistake is misformatting the x-paywalled or x-paywalled-credentials headers. If the structure doesn't match the API's expectations, the request fails before it even reaches the payment gateway. Double-check that your client library correctly encodes these headers according to the official specification.

Failing to handle retry logic

Network interruptions are inevitable. If your code doesn't implement retry logic for failed transactions, a single timeout can break your entire data ingestion process. Implement exponential backoff to handle transient errors. This ensures that your application can recover gracefully without missing critical research updates or duplicating charges.

Frequently asked questions about x402