A proof-of-concept application, which demonstrates how a decentralised, automated and distributed Supply Chain Management (SCM) system can be built using the Blockchain technology.
Etherem blockchain and Smart Contracts are used, with the Solidity programming language and Ganache/Truffle framework.
Frontend is built using React JS, Redux and Tailwind CSS.
- Clone repository:
git clone https://github.com/ByWaleed/Decentralized-Supply-Chain.git
- Install packages:
npm install
- Install truffle:
npm install -g truffle
- Start local blockchain:
truffle develop
. This shows ten accounts (and their private keys) that can be used when interacting with the blockchain. - Compile and migrate smart contracts on the local blockahin by running:
migrate
in the truffle develop prompt.
- Change into app/src directory:
cd app/src
- Install npm packages:
npm install
- Start local server:
npm run start
To interact with the blockcahin, a digital wallet is required with a connected account.
Digital wallets can be installed as brower extensions such as MetaMask.
Step 3 of the backend installation provides 10 accounts. Import an account in the wallet and then connected with the site to start interacting with the blockchain.
There are two ways to interact with the blockchain: CLI and Web frontend.
First is through the CLI, which grants direct access to the CLI.
A detailed guide on interaction with truffle contracts is available here. Here are few steps to help you get started:
- Start a local blockchain and the truffle develop prompt:
truffle develop
. Commands listed below should be executed in the truffle develop prompt - Compile and deploy smart contract on the local blockcahin by running:
migrate
- Create an instance of the Smart Contract:
let instance = await Supplychain.deployed()
- Assign manufacturer role to account 1:
instance.addManufacturer(accounts[0])
. Runinstance.isManufacturer(accounts[0])
to confirm assigned role - Assign distributor role to account 2:
instance.addManufacturer(accounts[1])
. Runinstance.isManufacturer(accounts[1])
to confirm assigned role - Assign retailer role to account 3:
instance.addManufacturer(accounts[2])
. Runinstance.isManufacturer(accounts[2])
to confirm assigned role - Assign consumer role to account 4:
instance.addManufacturer(accounts[3])
. Runinstance.isManufacturer(accounts[3])
to confirm assigned role - [Manufacturer] Manufacture an item:
instance.manufactureItem(1, "Item name", "Item description", 500, { from: accounts[0] })
. Parameters are: SKU, name, description, price (int ETH) and optional parameter to associate user with the transaction - [Manufacturer] Pack the item:
instance.packItem(1, { from: accounts[0] })
- [Manufacturer] Mark the item for sale:
instance.sellItem(1, 500, { from: accounts[0] })
- [Distributer] Buy the item:
instance.buyItem(1, { from: accounts[1] })
- [Distributer] Ship the item:
instance.shipItem(1, { from: accounts[1] })
- [Retailer] Confirm receiving item:
instance.receiveItem(1, { from: accounts[2] })
- [Consumer] Purchase the item:
instance.purchaseItem(1, { from: accounts[3] })
- Confirm item history:
instance.fetchItem(1)
- List accounts addresse:
accounts
Second is through the web frontend, which handles the API calls to the contracts & blockchain.
Follow frontend installation to start the local server.
Simply run truffle test
.
Prerequisites:
- Clone repository:
git clone https://github.com/ByWaleed/Decentralized-Supply-Chain.git
- Install packages:
npm install
- Install truffle:
npm install -g truffle
Output:
This project is licensed under the MIT License - see the LICENSE.md file for details