x402 Data API Docs - How to Query x402 Payment Data
Learn how to query x402 payment data using GraphQL APIs. This comprehensive guide shows you how to access payment transactions, monitor server activity in real-time, and analyze payment analytics across multiple blockchain networks. The examples in this guide use Base network, but x402 protocol supports multiple chains.
What is x402 API?
The x402 API provides programmatic access to x402 protocol payment data through GraphQL queries. You can query payment transactions, track server activity, monitor real-time payments, and analyze payment analytics directly from the blockchain using Bitquery's streaming data platform.
x402 Overview
x402 is a decentralized payment protocol that enables pay-per-use API access on blockchain networks. It allows developers to monetize APIs and services by accepting cryptocurrency payments directly, eliminating the need for traditional subscription models or credit card processing. The protocol operates on multiple blockchain networks (including Base) and uses smart contracts to facilitate automatic payment verification and settlement between clients, servers, and facilitators.
How x402 Works?
x402 operates on a three-party architecture consisting of clients (API consumers), servers (API providers), and facilitators (payment processors). When a client wants to use a paid API service, they initiate a payment transaction on the blockchain. The facilitator validates the payment and notifies the server, which then processes the API request. The server verifies the payment payload embedded in the request headers before delivering the service. This creates a trustless system where payments are verified on-chain before service delivery, ensuring both parties fulfill their obligations without requiring intermediaries. All payment transactions are recorded on the blockchain and can be queried using GraphQL transfer queries for the respective network.
Various Actors in x402
The x402 ecosystem consists of three main actors:
-
Clients: Users or applications that consume paid API services. They initiate payment transactions and include payment payloads in their API requests.
-
Servers: API providers who offer services for payment. They verify payment payloads and deliver services after confirming valid payments on-chain. Server addresses can be tracked using transfer queries.
-
Facilitators: Payment processors that validate transactions, monitor the blockchain for payments, and notify servers when valid payments are detected. They help bridge the gap between on-chain payments and off-chain service delivery.
x402 Bazaar - Discover Services and Endpoints
The x402 Bazaar is a discovery service that allows you to find available x402-compatible APIs and services. You can query the Bazaar API to discover resources, view service metadata, check pricing, and understand API requirements.
Discovery API Endpoint
The x402 Bazaar discovery endpoint is available at:
https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources
This endpoint returns a paginated list of available x402 services with detailed information about each resource, including payment requirements, API schemas, performance metrics, and reliability scores.
Example API Response
When you query the x402 Bazaar discovery endpoint, you receive detailed information about each available service. Here's an example response structure:
{
"accepts": [
{
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"description": "Payment for token analysis service ($0.01)",
"extra": {
"name": "USD Coin",
"version": "2"
},
"maxAmountRequired": "10000",
"maxTimeoutSeconds": 300,
"mimeType": "application/json",
"network": "base",
"outputSchema": {
"input": {
"bodyFields": {
"chain": {
"default": "bsc",
"description": "Blockchain name (bsc, solana, ethereum, etc.)",
"required": false,
"type": "string"
},
"language": {
"default": "English",
"description": "Output language (English, Chinese, Korean, etc.)",
"required": false,
"type": "string"
},
"token": {
"description": "Token address or symbol (e.g. BTC, ETH, SOL, etc.)",
"required": true,
"type": "string"
}
},
"bodyType": "json",
"headerFields": {
"X-PAYMENT": {
"description": "Base64-encoded JSON PaymentPayload; automatically filled by x402scan",
"required": false,
"type": "string"
}
},
"method": "POST",
"type": "http"
},
"output": {
"analysis": "object",
"chain": "string",
"created_at": "string",
"language": "string",
"status": "string",
"token": "string",
"workflow_run_id": "string|null"
}
},
"payTo": "0x83240485b70e5c820e5f180533fc6156470cfd0e",
"resource": "https://x402.lucyos.ai/x402/tools/analyze_token",
"scheme": "exact"
}
],
"lastUpdated": "2025-11-27T12:57:44.059Z",
"metadata": {
"confidence": {
"overallScore": 0.75,
"performanceScore": 0.32,
"recencyScore": 1,
"reliabilityScore": 0.98,
"volumeScore": 0.8
},
"errorAnalysis": {
"abandonedFlows": 18,
"apiErrors": 0,
"delayedSettlements": 0,
"facilitatorErrors": 0,
"requestErrors": 0
},
"paymentAnalytics": {
"averageDailyTransactions": 139,
"base:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913": 9730000,
"totalTransactions": 973,
"totalUniqueUsers": 942,
"transactions24h": 973,
"transactionsMonth": 973,
"transactionsWeek": 973
},
"performance": {
"avgLatencyMs": 2525,
"maxLatencyMs": 18221,
"minLatencyMs": 1076,
"recentAvgLatencyMs": 2359
},
"reliability": {
"apiSuccessRate": 0.98,
"successfulSettlements": 973,
"totalRequests": 991
}
},
"resource": "x402.lucyos.ai/x402/tools/analyze_token",
"type": "http",
"x402Version": 1
}
Understanding the Response Structure
The response contains several key sections:
accepts: Array of payment configurations, including the asset (token), payment amount, network, and API endpoint detailspayTo: The server's wallet address that receives paymentsresource: The actual API endpoint URLoutputSchema: Defines the API's input requirements and expected output formatmetadata: Contains performance metrics, reliability scores, payment analytics, and error analysisconfidence: Overall quality scores based on performance, recency, reliability, and transaction volume
Payment Payload and Verification
The x402 protocol uses a payment payload system to verify payments between clients and servers. When a client makes a payment, they include a Base64-encoded JSON payment payload in the X-PAYMENT header of their API request.
Payment Payload Structure
The payment payload typically contains:
- Transaction hash of the payment
- Payment amount
- Recipient address (server)
- Timestamp
- Nonce or unique identifier
Verification Process
-
Client Side: The client initiates a payment transaction on the supported blockchain network, sending supported tokens (such as USDC) to the server's address. The client then encodes the payment details into a Base64 JSON payload.
-
Server Side: The server receives the API request with the
X-PAYMENTheader. It decodes the payload and verifies the payment by checking:- The transaction exists on-chain (verifiable through transaction queries)
- The payment amount matches the required fee
- The recipient address matches the server's address
- The transaction is confirmed and not a double-spend
-
Facilitator Role: Facilitators monitor the blockchain for payment transactions using real-time subscriptions. When they detect a valid payment to a registered server, they notify the server, enabling faster service delivery without waiting for full blockchain confirmation.
This architecture ensures that servers only deliver services after verifying valid on-chain payments, creating a trustless pay-per-use system. To check from the client side that a USDC payment was settled, see Verify an x402 Payment Settled On-Chain.
x402 Data API Queries
The following queries demonstrate how to query x402 payment data using Bitquery's GraphQL API. These queries help you monitor payments, track server activity, and analyze payment analytics. For more information on building queries, see our GraphQL query guide and filtering documentation.
x402 protocol supports multiple blockchain networks. The examples below use Base network, but you can adapt these queries for other supported chains by changing the network parameter.
Example x402 Server
For the following examples, we'll use this x402 server address:
Server Address: 0x83240485b70e5c820e5f180533fc6156470cfd0e
This server provides token analysis services and accepts USDC payments. The examples below use Base network, but the same query structure applies to other supported chains.
Listening to Latest Payments to a Specific Server
This query retrieves the most recent payments made to a specific x402 server. It's useful for monitoring server activity and tracking payment transactions.
You can run this query here.
query MyQuery {
EVM(dataset: realtime, network: base) {
Transfers(
where: {Transfer: {Receiver: {in: ["0x83240485b70e5c820e5f180533fc6156470cfd0e"]}}}
orderBy: {descending: Block_Number}
limit: {count: 100}
) {
Transaction {
Hash
}
Transfer {
Amount
Sender
Receiver
Currency {
Symbol
Name
}
}
}
}
}
Query Explanation
dataset: realtime: Queries the most recent blockchain data. Learn more about dataset optionsnetwork: base: Specifies the network (Base in this example). Change this to query other supported chains (e.g.,network: ethereum,network: bsc). See supported networksReceiver: {in: [...]}: Filters transfers to the specific server address using GraphQL filtersorderBy: {descending: Block_Number}: Returns the most recent payments first. See sorting documentationlimit: {count: 100}: Retrieves up to 100 payment transactions. Check query limits
Real-Time Payment Monitoring with GraphQL WebSockets
You can monitor payments to a specific x402 server in real-time using GraphQL WebSocket subscriptions. This enables live tracking of payment activity without polling.
You can run this subscription here.
subscription {
EVM(network: base) {
Transfers(
where: {Transfer: {Receiver: {in: ["0x83240485b70e5c820e5f180533fc6156470cfd0e"]}}}
) {
Transaction {
Hash
}
Transfer {
Amount
Sender
Receiver
Currency {
Symbol
Name
}
}
}
}
}