Skip to content

g0drlc/Coinbase-x402

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402 Video Paywall Demo

This project demonstrates how to implement a paywall for video content using the x402 payment protocol. The web app allows users to pay a small amount of cryptocurrency (USDC) to access a paywalled video.

Features

  • Simple Express.js server with x402 payment middleware
  • Paywalled endpoint for accessing premium video content
  • Client-side implementation for making payments
  • 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/g0drlc/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