Skip to content

IIITV-5G-and-Edge-Computing-Activity/2024GR15CS462_Blockchain-Based-5G-CDN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ Blockchain-Based 5G Content Delivery Network (CDN)

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


πŸ˜ƒ Team Members:

  • Devrikh Jatav 202211018

  • Chinchkar Sneha Achyut 202211013

  • Inarat Hussain 202211030

  • Suryansh Singh Raghuvansh 202211093


🧰 Tech Stack

🎨 Frontend

  • React.js (Vite)
  • Plyr (Video Player)
  • ethers.js
  • MetaMask

πŸ’‘ Backend

  • Node.js + Express.js
  • IPFS (via Pinata)
  • Docker (for edge node simulation)

πŸ› οΈ Blockchain

  • Solidity (Smart Contracts)
  • Hardhat (for development and local blockchain)
  • ethers.js (Frontend interaction)

✨ Features

  • βœ… 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

πŸ“ Project Structure

β”œβ”€β”€ 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                       

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/Devrikh/Blockchain-Based-5G-CDN.git
cd Blockchain-Based-5G-CDN
git checkout dev 

2. Install Dependencies

  • Root-level:
npm install
  • Frontend:
cd frontend
npm install
cd ..
  • Backend:
cd backend
npm install
cd ..

πŸ“¦ IPFS via Pinata

Create .env in both frontend/ and backend/ directories.

#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


βš™οΈ Setup Instructions

πŸ§ͺ Start Hardhat Local Blockchain

npx hardhat node --hostname 0.0.0.0

🧾 Deploy the Smart Contract

npx hardhat run scripts/deploy.js --network localhost

πŸ–₯️ Start Backend Server (😭 SKIP FOR NOW)

node backend/server.js

🌐 Start Edge Node Server

node backend/edgeNode.js

⚠️ Note: This will start a single edge node server locally for testing purposes. Also, Change the line const walletPrivateKey = process.env.EDGE_NODE_WALLET_PRIVATE_KEY; to const 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.

🎨 Start Frontend

cd frontend
npm run dev -- --host 0.0.0.0

πŸŽ₯ Deploy Videos

npx hardhat run scripts/uploadVideo.js --network localhost

⚠️ Note: Only for UI Testing , uses fake IPFS Hash.


🐳 Dockerizing Edge Nodes

πŸ“ Set Up .env File for Wallets

  • Inside the backend/ directory, make sure a file named .env exists:

πŸ› οΈ Build Docker Containers

  • From inside the backend/ directory:
docker-compose build
  • This will use the Dockerfile to build images for each edge node.

πŸš€ Start Edge Nodes

  • To start all edge node containers and see their output:
docker-compose up 
  • To run in detached/background mode:
docker-compose upm -d

πŸ” Monitor Logs

  • 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

πŸ›‘ Shut Down Edge Nodes

  • If you are done with simulation, run:
docker-compose down
  • This stops and removes containers (but not images or volumes).

About

A decentralized CDN using Ethereum, IPFS, and Dockerized edge nodes for video upload, purchase, caching, and delivery.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •