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.
- 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
- Node.js (v22 or higher)
- A EVM-compatible wallet with Base Sepolia USDC
-
Clone this repository:
git clone https://github.com/g0drlc/Coinbase-x402.git
-
Install dependencies:
npm install
-
Rename
.env.localto.envand add the following variables (remember to replaceWALLET_ADDRESSwith your actual wallet address you want to receive payments for)WALLET_ADDRESS=your_ethereum_wallet_address NODE_ENV=development PORT=4021 -
Get Base Sepolia USDC for testing:
- Visit https://faucet.circle.com/
- Select Base Sepolia in the network dropdown
- Request test USDC
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:4021
- The server uses the
x402-expressmiddleware to protect the/authenticateendpoint - When a user tries to access the protected endpoint, they are required to make a payment
- After successful payment, the user is redirected to
/video-content, where the premium video content is served
- To change the price of the video, modify the
priceparameter inapi/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)