Quick Start Guide
Get started quickly with BlockEden.xyz's x402 facilitator service as a merchant (server) or a buyer (client).
Coming Soon
BlockEden.xyz's x402 facilitator service is currently in development. This guide shows the planned API structure. Join the waitlist for early access.
Overview
This guide will help you:
- Merchants (Servers): Protect your APIs and content with x402 payment requirements
- Buyers (Clients): Enable your applications and AI agents to automatically pay for protected resources
Prerequisites
Before you begin, you'll need:
- BlockEden.xyz API Key: Sign up at blockeden.xyz/dash
- Wallet Setup: A wallet with USDC on supported networks (Sui recommended)
- Node.js 18+ or Python 3.8+ (depending on your stack)
For Servers (Merchants)
Installation
- TypeScript
- Python
npm install @blockeden/x402-sdk
# or
yarn add @blockeden/x402-sdk
pip install blockeden-x402
Basic Server Setup
- TypeScript (Express)
- TypeScript (Hono)
- Python (FastAPI)
- Python (Flask)
import express from 'express';
import { X402Middleware } from '@blockeden/x402-sdk';
const app = express();
// Configure x402 middleware
const x402 = X402Middleware({
apiKey: process.env.BLOCKEDEN_API_KEY,
facilitatorUrl: 'https://x402.blockeden.xyz',
network: 'sui', // Default network
token: 'USDC',
});
// Protect your endpoints with x402
app.get('/api/premium/data',
x402.require({
amount: '0.01', // 1 cent in USDC
network: 'sui',
}),
(req, res) => {
// Payment verified - deliver content
res.json({
data: 'Your premium content here',
payment: {
txHash: req.x402.txHash,
amount: req.x402.amount,
network: req.x402.network,
}
});
}
);
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
import { Hono } from 'hono';
import { x402Middleware } from '@blockeden/x402-sdk/hono';
const app = new Hono();
// Configure x402 middleware
app.use('/api/premium/*', x402Middleware({
apiKey: process.env.BLOCKEDEN_API_KEY,
facilitatorUrl: 'https://x402.blockeden.xyz',
network: 'sui',
token: 'USDC',
amount: '0.01',
}));
app.get('/api/premium/data', (c) => {
const payment = c.get('x402');
return c.json({
data: 'Your premium content here',
payment: {
txHash: payment.txHash,
amount: payment.amount,
}
});
});
export default app;
from fastapi import FastAPI, Depends
from blockeden_x402 import X402Middleware, X402Payment
app = FastAPI()
# Configure x402 middleware
x402 = X402Middleware(
api_key=os.environ["BLOCKEDEN_API_KEY"],
facilitator_url="https://x402.blockeden.xyz",
network="sui",
token="USDC",
)
@app.get("/api/premium/data")
async def get_premium_data(
payment: X402Payment = Depends(x402.require(amount="0.01"))
):
"""Protected endpoint requiring 0.01 USDC payment"""
return {
"data": "Your premium content here",
"payment": {
"tx_hash": payment.tx_hash,
"amount": payment.amount,
"network": payment.network,
}
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
from flask import Flask, jsonify
from blockeden_x402 import X402Middleware
app = Flask(__name__)
# Configure x402 middleware
x402 = X402Middleware(
api_key=os.environ["BLOCKEDEN_API_KEY"],
facilitator_url="https://x402.blockeden.xyz",
network="sui",
token="USDC",
)
@app.route('/api/premium/data')
@x402.require(amount="0.01")
def get_premium_data(payment):
"""Protected endpoint requiring 0.01 USDC payment"""
return jsonify({
"data": "Your premium content here",
"payment": {
"tx_hash": payment.tx_hash,
"amount": payment.amount,
"network": payment.network,
}
})
if __name__ == '__main__':
app.run(debug=True, port=8000)