Skip to content

Commit 222b967

Browse files
committed
update reamde with step by step and added images
1 parent 6d0e984 commit 222b967

11 files changed

Lines changed: 125 additions & 46 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- 'CONTRIBUTING.md'
1010
- 'docs/**'
1111
- '*.md'
12+
- 'assets/**'
1213
pull_request:
1314
branches: [ master, main ]
1415
paths-ignore:
@@ -17,7 +18,7 @@ on:
1718
- 'CONTRIBUTING.md'
1819
- 'docs/**'
1920
- '*.md'
20-
21+
- 'assets/**'
2122
jobs:
2223
backend:
2324
name: Backend (Hardhat)

README.md

Lines changed: 121 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Watch the demo video: [Canva Design Demo](https://www.canva.com/design/DAFb-i9v_
3333
- [Technology Stack](#-technology-stack)
3434
- [Architecture](#-architecture)
3535
- [Installation](#-installation)
36+
- [Setting up Ganache (step by step)](#setting-up-ganache-step-by-step)
37+
- [Troubleshooting](#troubleshooting)
3638
- [Running the Project](#-running-the-project)
3739
- [Usage Guide](#-usage-guide)
3840
- [Smart Contract Details](#-smart-contract-details)
@@ -43,11 +45,7 @@ Watch the demo video: [Canva Design Demo](https://www.canva.com/design/DAFb-i9v_
4345

4446
**Supply Chain Blockchain DApp** is an open-source, blockchain-based supply chain management application built with Solidity smart contracts, Hardhat, Next.js, Web3.js, and MetaMask. It demonstrates how to build an end-to-end Ethereum decentralized application (dApp) for transparent, secure, and traceable pharmaceutical supply chains.
4547

46-
This repository is ideal for developers who want to learn:
4748

48-
- How to build a full-stack Ethereum dApp with **Solidity**, **Hardhat**, **Next.js**, and **Web3.js**
49-
- How to design **role-based access control** and **product lifecycle tracking** on the blockchain
50-
- How to integrate a smart contract backend with a modern React/Next.js frontend
5149

5250
<!-- ## Demo and Screenshots
5351
@@ -100,6 +98,9 @@ This repository is ideal for developers who want to learn:
10098

10199
## Architecture
102100

101+
102+
![System Architecture](assets/system%20design.png)
103+
103104
The application follows a decentralized architecture where:
104105

105106
1. **Smart Contracts** (Solidity) handle all business logic and data storage on the blockchain
@@ -113,7 +114,7 @@ The application follows a decentralized architecture where:
113114
User → Next.js Frontend → Web3.js → MetaMask → Ethereum Network → Smart Contract
114115
```
115116

116-
![Architecture Diagram](https://raw.githubusercontent.com/faizack619/Supply-Chain-Gode-Blockchain/master/client/public/Blank%20diagram.png)
117+
117118

118119
### Supply Chain Flow
119120

@@ -164,13 +165,68 @@ cd ..
164165

165166
### Step 3: Configure Ganache
166167

167-
1. Open Ganache and create a new workspace
168-
2. Note the RPC Server URL (usually `http://127.0.0.1:7545` or `http://127.0.0.1:8545`)
169-
3. Copy the Chain ID (usually `1337` or `5777`)
168+
Follow the detailed walkthrough: **[Setting up Ganache (step by step)](#setting-up-ganache-step-by-step)**. In short, use **RPC** `http://127.0.0.1:7545` and **chain ID** **1337** so they match `backend/hardhat.config.ts` (`networks.ganache`) and the keys in `client/src/deployments.json`.
169+
170+
## Setting up Ganache (step by step)
171+
172+
This project’s default Hardhat network `ganache` uses **`http://127.0.0.1:7545`** and **chain ID `1337`**. MetaMask, Ganache, and Hardhat must all use the **same** RPC URL and **chain ID** (EIP-155), or you will see “wrong network” or “contract not found”.
173+
174+
### A. Ganache Desktop (recommended)
175+
176+
1. **Install Ganache**
177+
Download and install [Ganache](https://trufflesuite.com/ganache/) (Truffle Suite).
178+
179+
2. **Create a workspace**
180+
Open Ganache → **New Workspace** (or open an existing workspace). A workspace persists accounts and settings across restarts; **Quickstart** resets when you close the app.
181+
182+
3. **Open workspace settings**
183+
Click the **gear / Settings** icon for the workspace.
184+
185+
4. **Server (host and port)**
186+
In **Server** (sometimes **HOST & PORT**):
187+
- **HOSTNAME**: `127.0.0.1` (use this in MetaMask on the same machine).
188+
- **PORT**: `7545`
189+
This must match `networks.ganache.url` in `backend/hardhat.config.ts` (`http://127.0.0.1:7545`).
190+
191+
5. **Chain ID**
192+
Set **Chain ID** (or **EIP-155 Chain ID**, depending on your Ganache version) to **`1337`**.
193+
If the UI only shows **NETWORK ID**, set it to **`1337`** for this repo so it stays consistent with Hardhat’s `ganache` network and the frontend’s default deployment entry.
194+
195+
6. **Save and restart**
196+
Save settings and **restart** the workspace if Ganache prompts you.
197+
198+
7. **Confirm RPC**
199+
On the main **Accounts** (or **CONTRACTS**) screen, check that the **RPC SERVER** is `http://127.0.0.1:7545` (or equivalent with `127.0.0.1` and port `7545`).
200+
201+
8. **Deployer account**
202+
Hardhat uses Ganache’s **first account** by default when you deploy without a custom `accounts` config. In MetaMask, import that account’s **private key** (key icon in Ganache) if you need to act as the contract **owner**.
203+
204+
**After you change chain ID or reset the chain:** redeploy the contract (`npx hardhat run scripts/deploy.ts --network ganache` from `backend`) so `client/src/deployments.json` gets a valid address for the current chain.
205+
206+
### B. Ganache CLI (optional)
207+
208+
If you use the [Ganache CLI](https://github.com/trufflesuite/ganache) instead of the desktop app, start a node that matches the same host, port, and chain ID:
209+
210+
```bash
211+
npx ganache --host 127.0.0.1 --port 7545 --chain.chainId 1337
212+
```
213+
214+
Leave this process running, then deploy from `backend` with `--network ganache` as usual.
215+
216+
### Using chain ID 5777 instead
217+
218+
If your Ganache instance must use **chain ID `5777`**, use Hardhat’s `ganache5777` network and deploy with:
219+
220+
```bash
221+
cd backend
222+
npx hardhat run scripts/deploy.ts --network ganache5777
223+
```
224+
225+
Ensure MetaMask’s **Chain ID** is **5777** and that `client/src/deployments.json` includes a `"5777"` entry after deploy.
170226

171227
### Step 4: Configure Hardhat
172228

173-
Update `hardhat.config.ts` with your Ganache network settings:
229+
Update `backend/hardhat.config.ts` with your Ganache network settings (default RPC `http://127.0.0.1:7545` and chain ID **1337**):
174230

175231
```typescript
176232
networks: {
@@ -186,66 +242,86 @@ networks: {
186242

187243
### Step 5: Deploy Smart Contracts
188244

245+
All Hardhat commands must be run from the **`backend`** folder (where `hardhat.config.ts` lives).
246+
189247
Compile the smart contracts:
190248

191249
```bash
250+
cd backend
192251
npx hardhat compile
193252
```
194253

195254
Deploy to Ganache:
196255

197256
```bash
257+
cd backend
198258
npx hardhat run scripts/deploy.ts --network ganache
199259
```
200260

201261
The deployment script will automatically update `client/src/deployments.json` with the contract address.
202262

203-
### Step 6: Configure MetaMask
263+
### Step 6: Ganache RPC & MetaMask setup (with screenshots)
204264

205-
1. Open MetaMask and click the network dropdown
206-
2. Select "Add Network" → "Add a network manually"
207-
3. Enter the following details:
208-
- **Network Name**: Ganache Local
209-
- **RPC URL**: `http://127.0.0.1:7545` (or your Ganache URL)
210-
- **Chain ID**: `1337` (or your Ganache Chain ID)
211-
- **Currency Symbol**: ETH
212-
4. Click "Save"
265+
Use the same **RPC URL** and **chain ID** everywhere: Ganache, `backend/hardhat.config.ts`, MetaMask, and `client/src/deployments.json` (defaults: `http://127.0.0.1:7545`, chain ID **1337**). Images are in [`assets/`](assets/).
213266

214-
5. Import an account from Ganache:
215-
- In Ganache, click the key icon next to an account to reveal the private key
216-
- In MetaMask, click the account icon → "Import Account"
217-
- Paste the private key and click "Import"
267+
**1. Read the RPC server URL from Ganache**
268+
You will paste this into MetaMask in the next step.
218269

219-
## Running the Project
270+
<p align="center">
271+
<img src="assets/rpc-url.png" alt="Ganache RPC server URL" width="720">
272+
</p>
220273

221-
### Start Ganache
274+
**2. Add the network in MetaMask**
275+
Network menu → **Add network****Add a network manually**, then set:
222276

223-
1. Open Ganache application
224-
2. Create or open a workspace
225-
3. Ensure the server is running
277+
- **Network name:** e.g. `Ganache Local`
278+
- **RPC URL:** same as Ganache (e.g. `http://127.0.0.1:7545`)
279+
- **Chain ID:** `1337` (must match Ganache and Hardhat `networks.ganache`)
280+
- **Currency symbol:** `ETH`
226281

227-
### Deploy Contracts (if not already deployed)
282+
Save and **select this network** before using the app.
228283

229-
```bash
230-
npx hardhat run scripts/deploy.ts --network ganache
231-
```
284+
<p align="center">
285+
<img src="assets/add-network-wallet.png" alt="MetaMask add custom network" width="720">
286+
</p>
232287

233-
### Start the Frontend
288+
**3. Copy the deployer private key from Ganache**
289+
Hardhat deploys with Ganache’s **first account** by default. That address is the contract **owner** (Register Roles, Order Materials). Copy its private key from the key icon.
234290

235-
```bash
236-
cd client
237-
npm run dev
238-
```
291+
<p align="center">
292+
<img src="assets/ganache-copy-private-key.jpg" alt="Copy private key from Ganache" width="720">
293+
</p>
239294

240-
The application will be available at [http://localhost:3000](http://localhost:3000)
295+
**4. Import the account in MetaMask**
296+
Account menu → **Import account** → paste the private key → **Import**. Keep this account selected when acting as owner.
241297

242-
### Build for Production
298+
<p align="center">
299+
<img src="assets/import-account.png" alt="Import account in MetaMask" width="720">
300+
</p>
243301

244-
```bash
245-
cd client
246-
npm run build
247-
npm start
248-
```
302+
**5. Run the app**
303+
From `client`: `npm run dev` → open [http://localhost:3000](http://localhost:3000). The deploy log line `Deploying with account: 0x...` must match the **active** MetaMask account for owner-only actions.
304+
305+
## Troubleshooting
306+
307+
**Chain ID `5777` vs `1337`:** Some docs confuse **network ID** with **chain ID** (EIP-155). This project expects **chain ID** to match everywhere. If Ganache uses **5777**, deploy with `npx hardhat run scripts/deploy.ts --network ganache5777` from `backend` and ensure `client/src/deployments.json` has a `"5777"` entry after deploy.
308+
309+
| Symptom | What to check |
310+
|--------|----------------|
311+
| **Only owner can do this** | Active MetaMask account must be the **same address** that deployed the contract (see deploy log). Import that account from Ganache if needed. |
312+
| **Contract not found** / wrong network banner | Chain ID in MetaMask must match the key in `client/src/deployments.json`. After resetting Ganache, **redeploy** — old addresses are invalid. |
313+
| **1337 in settings but 5777 in console** | You were likely reading **network ID** vs **chain ID**. Align **chain ID** everywhere; redeploy after changing Ganache. |
314+
| **Transaction fails or wrong balance** | RPC URL in MetaMask must point to the **same** Ganache instance (correct host/port). |
315+
316+
## Running the Project
317+
318+
If you already followed **Installation**, you only need:
319+
320+
1. Ganache running with the same RPC/chain ID as **`backend/hardhat.config.ts`** (see **[Setting up Ganache (step by step)](#setting-up-ganache-step-by-step)**).
321+
2. Deploy (if needed): `cd backend && npx hardhat run scripts/deploy.ts --network ganache`
322+
3. Frontend: `cd client && npm run dev`[http://localhost:3000](http://localhost:3000)
323+
324+
**Production build:** `cd client && npm run build && npm start`
249325

250326
## Usage Guide
251327

@@ -281,7 +357,8 @@ npm start
281357

282358
## Smart Contract Details
283359

284-
The `SupplyChain.sol` smart contract implements a comprehensive supply chain management system with the following features:
360+
The `SupplyChain.sol` smart contract implements a supply chain for the **pharmaceutical** domain: it tracks medicine **stages**, stores names, descriptions, and current stage, and defines **roles** (raw material supplier, manufacturer, distributor, retailer). The **owner** registers participants and creates orders; other functions advance the product and **read** stage and history.
361+
285362

286363
### Roles
287364

assets/add-network-wallet.png

35.6 KB
Loading

assets/contract-working-flow.png

211 KB
Loading
6.34 KB
Loading

assets/import-account.png

231 KB
Loading

assets/rpc-url.png

36 KB
Loading

assets/smart-contract-design.png

87.1 KB
Loading

assets/supply-chain-stages.png

112 KB
Loading

assets/system design.png

58.9 KB
Loading

0 commit comments

Comments
 (0)