Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 479 additions & 0 deletions docs/x402/demo/X402_DEMO_GUIDE.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions docs/x402/demo/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsx src/api.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "[email protected]",
"dependencies": {
"dotenv": "^17.2.2",
"express": "^5.1.0",
"x402-express": "^0.6.1"
},
"devDependencies": {
"@types/node": "^24.5.2",
"tsx": "^4.20.5"
}
}
6,039 changes: 6,039 additions & 0 deletions docs/x402/demo/api/pnpm-lock.yaml

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions docs/x402/demo/api/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import express from "express";
import { Network, paymentMiddleware, SolanaAddress } from "x402-express";
import { config } from "dotenv";
import path from "path";

config({ path: path.join(process.cwd(), '..', '.env') });

type Resource = `${string}://${string}`;

const API_PORT = process.env.API_PORT || 4021;
const FACILITATOR_URL = process.env.FACILITATOR_URL as Resource || "http://localhost:3000";
const NETWORK = (process.env.NETWORK || "solana-devnet") as Network;
const KORA_SIGNER_ADDRESS = process.env.KORA_SIGNER_ADDRESS as SolanaAddress;

if (!KORA_SIGNER_ADDRESS) {
throw new Error("KORA_SIGNER_ADDRESS is not set");
}

const app = express();

app.use(
paymentMiddleware(
KORA_SIGNER_ADDRESS,
{
"GET /protected": {
price: "$0.0001",
network: NETWORK,
},
},
{
url: FACILITATOR_URL,
}
),
);

app.get("/protected", (req, res) => {
res.json({
message: "Protected endpoint accessed successfully",
timestamp: new Date().toISOString(),
});
});

app.get("/health", (req, res) => {
res.json({ status: "ok" });
});


app.listen(API_PORT, () => {
console.log(`Server listening at http://localhost:${API_PORT}`);
});

// curl -X GET http://localhost:4021/protected
// curl -X GET http://localhost:4021/health
Binary file added docs/x402/demo/assets/x402-protocol-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docs/x402/demo/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "kora-demo-client",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "tsx src/index.ts",
"setup": "tsx src/setup.ts"
},
"keywords": [
"solana",
"kora",
"client"
],
"author": "Solana Foundation",
"license": "MIT",
"packageManager": "[email protected]",
"dependencies": {
"dotenv": "^17.2.0",
"gill": "^0.11.0",
"x402-fetch": "^0.6.0"
},
"devDependencies": {
"@types/node": "^24.0.13",
"tsx": "^4.20.5",
"typescript": "^5.8.3"
}
}
Loading