Blockchain_In_Retail

🚀 Retail Blockchain System

📌 Demo & Code

Live Demo View on GitHub

A decentralized, transparent, and secure platform for managing retail transactions and loyalty points using blockchain technology.


📌 1️⃣ Problem Statement

Traditional retail systems often suffer from:

✅ Solution: Leverage blockchain to provide decentralized, transparent, and tamper-proof retail transaction management.


📌 2️⃣ Technology Stack & Rationale

Technology Purpose Why?
Solidity Smart contract programming language. Standard for EVM-based blockchains.
Ethereum/Ganache Blockchain platform for transaction and loyalty records. Decentralized ledger with local dev support via Ganache.
FastAPI Web API framework (Python 3.7+). High-performance, async support, automatic interactive docs.
Web3.py Ethereum blockchain interaction library. Connects to Ethereum nodes, manages smart contracts and transactions.
Pydantic Data validation and management. Robust validation for API requests and responses.
python-dotenv Environment variable management. Safely handles sensitive config like private keys.
solcx Solidity compiler wrapper for Python. Compiles smart contracts programmatically.
Docker Containerization platform. Consistent, portable deployment environment.

📌 3️⃣ High-Level Design (HLD)

+--------------------+         +----------------------------+         +-----------------------+
| Frontend (Optional)|         |   FastAPI Backend (Python) |         | Ethereum Blockchain   |
| (e.g., React/Vue)  |         |                            |         | (Ganache for Dev)     |
+--------+-----------+         +------------+---------------+         +-----------+-----------+
         |                                  |                                      |
         |  HTTP Requests (API Calls)       | REST Endpoints                       | Smart Contract Calls
         |--------------------------------->+--(/transactions, /loyalty, /status)--|--------------------------->
         |                                  |                                      |  - RetailTransaction.sol
         |                                  |                                      |  - LoyaltyPoints.sol
         |                                  |                                      |
         |<---------------------------------| API Responses                        |<---------------------------
         |  Data / Status                   |                                      |  Transaction Receipts
         |                                  |                                      |  Loyalty Balances
         |                                  |                                      |
+--------+---------+           +------------+---------------+         +-----------+-----------+
                                            |
                                            | Services:
                                            | - Contracts Manager (compile, deploy, load)
                                            | - Currency Converter (INR <-> Wei)
                                            | - Loyalty Manager (calculate, award, redeem, check)
                                            | - Transaction Manager (match off-chain IDs)
                                            |
                                            | Startup:
                                            | - Initializes/Deploys Contracts
                                            |
                                            | Models:
                                            | - Pydantic Schemas

Services:

Workflow:

  1. Startup: Compile & deploy smart contracts or load existing ones.
  2. Transactions: Record retail transactions & award loyalty points.
  3. Loyalty Management: Fetch balance, redeem points.
  4. Data Storage: Immutable records on the blockchain.

📌 4️⃣ Features


📌 5️⃣ API Usage

Base URL: http://localhost:8000

🔸 API Documentation

Available at:

🔹 Key Endpoints & Examples:

Check API Status

curl -X GET "http://localhost:8000/"

Record a Retail Transaction

curl -X POST "http://localhost:8000/transactions/record" -H "Content-Type: application/json" -d '{ "customer_address": "0xCustomerEthAddress", "retailer_address": "0xRetailerEthAddress", "amount_INR": 1500.75, "product_id": "PROD123", "quantity": 2, "description": "Purchase of electronics" }'

Get Transaction Details

curl -X GET "http://localhost:8000/transactions/1"

Get Loyalty Balance

curl -X GET "http://localhost:8000/loyalty/balance/0xCustomerEthAddress"

Redeem Loyalty Points

curl -X POST "http://localhost:8000/loyalty/redeem" -H "Content-Type: application/json" -d '{ "customer_address": "0xCustomerEthAddress", "points_amount": 100 }'

📌 6️⃣ Local Setup

Prerequisites:

Steps:


📌 7️⃣ Deployment on Render


📌 8️⃣ Important Notes


📌 9️⃣ Project Outcomes

📌 Demo & Code

Live Demo View on GitHub