Quick Start Guide

Get up and running with x402 on XRPL in minutes.

Prerequisites

  • • Python 3.11+
  • • An XRPL wallet (you can create one on XRPL Testnet Faucet)
  • • Basic understanding of HTTP APIs

Choose one environment

Keep the facilitator URL, XRPL_NETWORK, and XRPL RPC/WS endpoint from the same row. Server middleware uses the facilitator URL. Buyer clients call your protected resource URL and use XRPL RPC/WS plus a network filter. The RPC/WS endpoints below are references; each client guide shows the exact env var or option it reads.

EnvironmentServer middlewareBuyer network guard + XRPL endpointsNotes
Hosted mainnet
XRPL_FACILITATOR_URL=https://xrpl-facilitator-mainnet.t54.ai
XRPL_NETWORK=xrpl:0

Network guard: xrpl:0

JSON-RPC: https://s1.ripple.com:51234/

WebSocket: wss://s1.ripple.com:51233

Use funded mainnet wallets. Do not use a faucet.
Hosted testnet
XRPL_FACILITATOR_URL=https://xrpl-facilitator-testnet.t54.ai
XRPL_NETWORK=xrpl:1

Network guard: xrpl:1

JSON-RPC: https://s.altnet.rippletest.net:51234/

WebSocket: wss://s.altnet.rippletest.net:51233

Use XRPL testnet wallets and the testnet faucet.
Local dev
XRPL_FACILITATOR_URL=http://127.0.0.1:8011
XRPL_NETWORK=xrpl:1

Network guard: xrpl:1

JSON-RPC: https://s.altnet.rippletest.net:51234/

WebSocket: wss://s.altnet.rippletest.net:51233

Default local setup still targets testnet unless you change every network value together.

Set up a FastAPI server that accepts x402 payments. When clients request your protected endpoints, they'll automatically be prompted to pay before accessing the resource. Server middleware uses the facilitator URL; keep it on the same network as XRPL_NETWORK.

Step 1: Install dependencies

pip install fastapi uvicorn x402-xrpl python-dotenv

Step 2: Configure environment

Create a .env file with your configuration:

XRPL_FACILITATOR_URL=https://xrpl-facilitator-testnet.t54.ai
XRPL_NETWORK=xrpl:1
XRPL_PAY_TO=rYourWalletAddress  # your wallet address to receive funds
XRPL_PRICE_DROPS=1000           # price in drops (1 XRP = 1,000,000 drops)

Tip: Get a testnet wallet from the XRPL Testnet Faucet

Step 3: Create your server

Create a file called server.py:

server.py
import os
from dotenv import load_dotenv
from fastapi import FastAPI
from x402_xrpl.server import require_payment

load_dotenv()

app = FastAPI()

# Configure the x402 middleware
# This protects specific paths and handles the 402 Payment Required flow.
app.middleware("http")(
    require_payment(
        path="/hello",  # Protect only the /hello endpoint
        price=os.getenv("XRPL_PRICE_DROPS", "1000"),
        pay_to_address=os.getenv("XRPL_PAY_TO"),
        facilitator_url=os.getenv("XRPL_FACILITATOR_URL"),
        network=os.getenv("XRPL_NETWORK", "xrpl:1"),
        asset="XRP",
        description="A paid hello world endpoint",
    )
)

# Protected endpoint - requires payment
@app.get("/hello")
async def hello():
    return {"message": "Hello World! Thanks for the payment."}

# Free endpoint - no payment required
@app.get("/health")
async def health():
    return {"status": "ok"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Step 4: Run the server

python server.py

Try visiting http://localhost:8000/hello. You'll receive a 402 Payment Required response with payment instructions.

Next Step

Learn more about the XRPL Exact payment scheme and how payments are verified and settled.

Go to XRPL Exact Scheme