This project is a decentralized content delivery network (CDN) built on the Ethereum blockchain. It allows users to upload and purchase videos via smart contracts, store video files on IPFS, and distribute them through Dockerized edge nodes that simulate caching and content delivery.
Demo Video: https://drive.google.com/file/d/1tABikMlixjKA2G1AqwFDcUUAC4eXL7CT/view?usp=sharing
- React.js (Vite)
- Plyr (Video Player)
- ethers.js
- MetaMask
- Node.js + Express.js
- IPFS (via Pinata)
- Docker (for edge node simulation)
- Solidity (Smart Contracts)
- Hardhat (for development and local blockchain)
- ethers.js (Frontend interaction)
- β Upload videos to IPFS
- β Store video metadata on the blockchain
- β Buy videos with crypto (ETH)
- β Play purchased videos
- β Register as an edge node
- β Claim earnings as edge node
- β Dockerized edge node server (caching simulation)
- πΆ 5G integration is planned
βββ artifacts/ # Auto-generated artifacts after compiling contracts (by Hardhat)
βββ backend/ # Backend services
β βββ cache/ # Local cache for video caching
β βββ src/ # Contract ABI and other sources
β βββ .env # Environment variables for backend config (e.g., ports, IPFS keys)
β βββ compose.yaml # Docker Compose file for edge nodes
β βββ Dockerfile # Dockerfile to containerize the edge node
β βββ edgeNode.js # Edge node server that caches and serves video content
β βββ server.js # WebSocket server (Express)
βββ cache/ # Hardhat's compilation cache
βββ contracts/
β βββ VideoCDN.sol # Smart contract for video purchases, edge node registration, etc.
βββ frontend/ # Frontend client (React + Vite)
β βββ src/
β β βββ assets/ # Static assets like edgenodeMapping, etc
β β βββ config.js # IPFS, blockchain, or API configuration constants
β β βββ main.jsx # React entry point
β β βββ VideoPlayer.jsx # Video player component with playback and routing logic
β βββ .env # Environment variables for Vite frontend (e.g., Contract Address, API, Secrets, etc)
βββ scripts/
β βββ deploy.js # Script to deploy smart contracts to Hardhat local blockchain
β βββ uploadVideo.js # Script to upload videos to blockchain
βββ test/ # Smart contract test cases to verify functions of smart contract
βββ hardhat.config.js # Hardhat configuration file
βββ README.md
git clone https://github.com/Devrikh/Blockchain-Based-5G-CDN.git
cd Blockchain-Based-5G-CDN
git checkout dev
- Root-level:
npm install
- Frontend:
cd frontend
npm install
cd ..
- Backend:
cd backend
npm install
cd ..
- Get API Keys from Pinata.
#FRONTEND
VITE_CONTRACT_ADDRESS=your_contract_address
VITE_PINATA_API_KEY=your_pinata_api_key
VITE_PINATA_SECRET_API_KEY=your_pinata_secret_key
VITE_WALLET_ONE=wallet_one
VITE_WALLET_TWO=wallet_two
VITE_WALLET_THREE=wallet_three
#BACKEND
PINATA_API_KEY=your_pinata_api_key
PINATA_SECRET_KEY=your_pinata_secret_key
DOCKER_WALLET_ONE=your_private_key_for_edge_node_1
DOCKER_WALLET_TWO=your_private_key_for_edge_node_2
DOCKER_WALLET_THREE=your_private_key_for_edge_node_3
CONTRACT_ADDRESS=contract_address
JSONPROVIDERURI=RPC_URL
β οΈ Note: Obtain your wallet addresses and RPC from Hardhat Blockchain
npx hardhat node --hostname 0.0.0.0
npx hardhat run scripts/deploy.js --network localhost
node backend/server.js
node backend/edgeNode.js
β οΈ Note: This will start a single edge node server locally for testing purposes. Also, Change the lineconst walletPrivateKey = process.env.EDGE_NODE_WALLET_PRIVATE_KEY;
toconst walletPrivateKey = process.env.DOCKER_WALLET_PRIVATE_KEY_ONE;
- If you want to simulate multiple edge nodes, skip this step and follow the instructions in the π³ Dockerizing Edge Nodes section. Before that, change IPs and Ports in
/frontend/src/assets/edgeNodeMap.js
accordingly.
cd frontend
npm run dev -- --host 0.0.0.0
npx hardhat run scripts/uploadVideo.js --network localhost
β οΈ Note: Only for UI Testing , uses fake IPFS Hash.
- Inside the
backend/
directory, make sure a file named.env
exists:
- From inside the
backend/
directory:
docker-compose build
- This will use the
Dockerfile
to build images for each edge node.
- To start all edge node containers and see their output:
docker-compose up
- To run in detached/background mode:
docker-compose upm -d
- To see logs for all services:
docker-compose logs -f
- To see logs for a specific edge node (e.g. edge_node_2):
docker-compose logs -f edge_node_2
- If you are done with simulation, run:
docker-compose down
- This stops and removes containers (but not images or volumes).