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.
-
⚙️ 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
- Node.js (v22 or higher)
- A EVM-compatible wallet with Base Sepolia USDC
-
Clone this repository:
git clone https://github.com/Benjamin-cup/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)