Learn how to integrate the Questflow X402 Facilitator into your application to enable crypto payments for your APIs and services.
Install the required dependencies based on your framework:
# For Express.js
npm install x402-express @coinbase/x402
# For Python
pip install x402-python cdp-sdk
Create your Facilitator configuration object with authentication headers:
{
url: 'https://facilitator.questflow.ai',
createAuthHeaders: async () => {
return {
verify: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
settle: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
supported: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
}
};
},
}
Note: Store your FACILITATOR_API_KEY securely in environment variables.
Integrate the payment middleware into your Express.js application:
import express from "express";
import { paymentMiddleware } from "x402-express";
const app = express();
const facilitatorConfig = {
url: 'https://facilitator.questflow.ai',
createAuthHeaders: async () => {
return {
verify: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
settle: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
supported: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
list: {
Authorization: `Bearer ${process.env.FACILITATOR_API_KEY}`,
},
};
},
};
app.use(paymentMiddleware(
"0xYourWalletAddress", // Your receiving wallet
{
"GET /api/data": {
price: "$0.01",
network: "base",
config: {
description: "Access premium API data",
inputSchema: {
type: "object",
properties: {
query: { type: "string" }
}
}
}
}
},
facilitatorConfig
));
Make a test request to your protected endpoint:
curl http://localhost:3000/api/data
The server will respond with 402 Payment Required and payment instructions. Complete the payment and retry with the payment proof in the X-PAYMENT header.