You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**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.
45
47
46
-
This repository is ideal for developers who want to learn:
47
48
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
51
49
52
50
<!-- ## Demo and Screenshots
53
51
@@ -100,6 +98,9 @@ This repository is ideal for developers who want to learn:
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:
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/).
213
266
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.
218
269
219
-
## Running the Project
270
+
<palign="center">
271
+
<imgsrc="assets/rpc-url.png"alt="Ganache RPC server URL"width="720">
272
+
</p>
220
273
221
-
### Start Ganache
274
+
**2. Add the network in MetaMask**
275
+
Network menu → **Add network** → **Add a network manually**, then set:
222
276
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`
226
281
227
-
### Deploy Contracts (if not already deployed)
282
+
Save and **select this network** before using the app.
228
283
229
-
```bash
230
-
npx hardhat run scripts/deploy.ts --network ganache
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.
234
290
235
-
```bash
236
-
cd client
237
-
npm run dev
238
-
```
291
+
<palign="center">
292
+
<imgsrc="assets/ganache-copy-private-key.jpg"alt="Copy private key from Ganache"width="720">
293
+
</p>
239
294
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.
241
297
242
-
### Build for Production
298
+
<palign="center">
299
+
<imgsrc="assets/import-account.png"alt="Import account in MetaMask"width="720">
300
+
</p>
243
301
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)**).
3. Frontend: `cd client && npm run dev` → [http://localhost:3000](http://localhost:3000)
323
+
324
+
**Production build:**`cd client && npm run build && npm start`
249
325
250
326
## Usage Guide
251
327
@@ -281,7 +357,8 @@ npm start
281
357
282
358
## Smart Contract Details
283
359
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.
0 commit comments