← Back to Docs

How It Works

A complete walkthrough of the x402 video payment flow.

The Payment Flow

When a viewer wants to watch a paid video, the following sequence occurs:

1

Manifest Request (Free)

The video player first requests the HLS manifest file (.m3u8). This is always free — it only contains metadata about the video structure, not actual video data.

GET /assets/playbackId.m3u8 → 200 OK
2

First Segment Request

When the player requests the first video segment, the server checks for a valid access token. If none exists, it returns HTTP 402 with payment details.

GET /assets/.../segment0.ts → 402 Payment Required
{
  "price": "$0.05",
  "network": "base-sepolia",
  "recipient": "0x...",
  "description": "Access to full video (5 segments)"
}
3

Payment Authorization

The wallet prompts the viewer to sign a payment authorization. This is a gasless signature that authorizes a USDC transfer.

Note: The viewer signs a message, not a transaction. The actual transfer happens via the x402 facilitator.
4

Payment Verification

The signed authorization is sent to the x402 facilitator, which verifies the signature and settles the payment on-chain.

5

JWT Token Issued

After successful payment, the server issues a JWT (JSON Web Token) stored in a cookie. This token grants access to all segments of the video.

Set-Cookie: x402-playbackId=eyJhbGc...
6

Video Playback

All subsequent segment requests include the JWT cookie. The server validates the token and streams the video without requiring additional payments.

GET /assets/.../segment1.ts + Cookie → 200 OK

Why This Approach?

🎯 Single Payment

Viewers pay once for the entire video, not per-segment. No wallet popup spam.

⚡ Stateless Validation

JWT tokens are self-contained. No database lookups needed to verify access.

🔄 Replay Friendly

Token is valid for 24 hours. Viewers can rewatch without paying again.

📱 Works Everywhere

Standard HTTP cookies work with any video player that supports credentials.

Dynamic Pricing

The payment amount is calculated based on the video segment count:

Total Price = Segment Count × Price Per Segment

For example, a 5-segment video at $0.01/segment costs $0.05 total. This ensures fair pricing — longer videos cost more.