Menu

Explorer & Settings

Tempo Explorer Submit Project
🧪 Learn by example

x402 Examples

The fastest way to learn x402 is to run a real one. Below: a minimal copyable snippet, plus a curated list of starter kits and demos pulled live from the 87+ example projects we track.

Diagram of x402 starter kits — a Next.js paywall, a FastAPI server and an AI agent buyer — with a clone, install and run flow to start accepting USDC payments in minutes

Minimal example (one middleware)

The smallest working x402 example: wrap one route, set a price and a receiving wallet. The route returns HTTP 402 until the caller pays USDC.

import express from "express";
import { paymentMiddleware } from "@x402/express";

const app = express();

// One middleware = a working x402 paywall
app.use(
  paymentMiddleware(
    "0xYourReceivingWalletAddress",
    { "GET /weather": { price: "$0.01", network: "base" } },
  )
);

app.get("/weather", (req, res) => {
  res.json({ forecast: "sunny" }); // runs only after payment
});

app.listen(3000);

Other languages & frameworks (Next.js, Node, Python, Go) are in the x402 SDK guide.

Starter kits & demos

Curated real repos · stars are live from GitHub · sorted by popularity.

coinbase/x402 Official examples

A payments protocol for the internet. Built on HTTP.

⭐ 6.4k TypeScript 🧱 TS / Python / Go

A popular full starter kit for building x402 apps end to end.

⭐ 179 TypeScript 🧱 TypeScript

Deployable template that puts an x402 paywall in front of an API.

⭐ 94 JavaScript 🧱 JavaScript

Vercel Labs starter for x402 + AI — agents paying for inference/tools.

⭐ 73 TypeScript 🧱 TypeScript

AWS payment demo of x402 using Bedrock AgentCore, Strands SDK, and CloudFront.

⭐ 24 Python 🧱 Python

Demos and starter code for building agentic finance apps with Crossmint

⭐ 19 TypeScript 🧱 TypeScript

Production-ready Rust server template for building HTTP APIs with x402 payment integration on Solana. Accept USDC payments for API access. Includes Axum, Actix and Rocket templates.

⭐ 13 Rust 🧱 Rust
Jnix2007/x402-demo Minimal demo

a simple x402 demo using CDP facilitator, embedded wallet, faucet, and token balances API. Includes an x402-enabled API, and simple web app from which the user can call the API.

⭐ 12 TypeScript 🧱 TypeScript

Protect your APIs with pay-per-call logic using a single Spring Boot annotation.

⭐ 11 Java 🧱 Java

x402 demo running on Arbitrum.

⭐ 9 TypeScript 🧱 TypeScript

Implemented HTTP 402 payment protocol with Thirdweb on Avalanche Fuji

⭐ 6 TypeScript 🧱 TypeScript

Gasless HTTP payments on NEAR - x402 protocol implementation using meta-transactions for pay-per-request APIs

⭐ 5 TypeScript 🧱 TypeScript

Browse all 87+ example projects in the directory →

Frequently asked questions

Where can I find official x402 examples?

The official coinbase/x402 repository contains runnable examples in its examples/ folder, covering simple paid endpoints, full-stack apps and client code in TypeScript, Python and Go. It’s the canonical place to start; the curated list above adds community starter kits and chain-specific demos.

What is the simplest x402 example?

The smallest working example is adding the official payment middleware to one route: set a price and a receiving wallet, and the route returns HTTP 402 until a USDC payment is made. See the minimal Express snippet on this page, then clone a starter kit for a complete project.

Are there x402 examples for Python, Go, Java and Rust?

Yes. Beyond TypeScript, the list includes a Java/Spring Boot starter, a Rust server template for Solana, and the official repo’s Python and Go examples. Pick the demo that matches your language and chain.

How do I run an x402 example?

Clone the repo, install dependencies, set environment variables (a receiving wallet address and a facilitator URL — the hosted Coinbase CDP one works on Base), then start the server and call the protected route. Most starter kits document the exact steps in their README.

Do x402 examples cost real money to test?

You can test on testnets (e.g. Base Sepolia) using free faucet USDC, so you don’t spend real funds while developing. Switch to mainnet and a real wallet only when you go live.

Next: SDKs & libraries · payment gateway · facilitators