Skip to content

Benjamin-cup/Coinbase-x402

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402 Video Paywall Demo

This project provides a practical demonstration of how to build a cryptocurrency-based video paywall using the x402 Payment Protocol It showcases how developers can integrate secure, on-chain micropayments (in USDC) to grant users access to premium video content. The application is built with Express.js and designed for easy testing on the Base Sepolia network.

Features

  • ⚙️ Express.js backend with x402-express middleware

  • 🔒 Paywalled route for gated video content

  • 💳 Client-side payment flow for seamless checkout

  • 🧪 Base Sepolia testnet integration for easy testing

Prerequisites

  • Node.js (v22 or higher)
  • A EVM-compatible wallet with Base Sepolia USDC

Getting Started

  1. Clone this repository:

      git clone https://github.com/Benjamin-cup/Coinbase-x402.git
  2. Install dependencies:

    npm install
  3. Rename .env.local to .env and add the following variables (remember to replace WALLET_ADDRESS with your actual wallet address you want to receive payments for)

    WALLET_ADDRESS=your_ethereum_wallet_address
    NODE_ENV=development
    PORT=4021
    
  4. Get Base Sepolia USDC for testing:

  5. Start the development server:

    npm run dev
  6. Open your browser and navigate to http://localhost:4021

How It Works

  1. The server uses the x402-express middleware to protect the /authenticate endpoint
  2. When a user tries to access the protected endpoint, they are required to make a payment
  3. After successful payment, the user is redirected to /video-content, where the premium video content is served

Customizing

  • To change the price of the video, modify the price parameter in api/index.js
  • To use a different video, update the video source in public/video-content.html
  • To deploy on Base mainnet, update the network configuration in api/index.js (you will need also need CDP API Keys and need to use a different Facilitator)

About

This is demo for Coinbase x402 payment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published