Skip to content

Supply-chain-dapp is such an implementation of a supply chain management system which uses blockchain to ensure a transparent and secure transfer of product from the manufacturer to the customer via the online e-commerce websites.

License

Notifications You must be signed in to change notification settings

divyamsavsaviya/supplychain

Repository files navigation

supply Chain

          

A simple Supply Chain setup with Solidity.

DescriptionArchitectureFlowContract Diagrams

Description

Supply chain is always hard to manage and requires a lot of admistrative machinery. However, when managed with smart contracts using blockchain, a lot of the paperwork is reduced. Also it leads to an increase in the transparency and helps to build an efficient Root of Trust. Supply-chain-dapp is such an implementation of a supply chain management system which uses blockchain to ensure a transparent and secure transfer of product from the manufacturer to the customer via the online e-commerce websites.

Architecture

The smart contract is being written with Solidity which is then compiled, migrated and deployed using Truffle.js on the local blockchain network created using Ganache-cli.The frontend uses Web3.js to communicate with the smart contract and local blockchain network and is written using React.js framework for better component and state lifecycle management.The requests from user are forwarded to frontend through Nginx(load balancer) and Express.js for dynamic routing.

Flow

The lifecycle of a product starts when manufactureProduct() is called(while making an entry) after the final product is manufactured and the product and manufacturer details are entered in the blockchain. The productHistory[] gets initialized and the current product data is stored with the current owner(manufacturer).

Now this product shall be available to the Third Party for purchase. On being purchased by a third party seller, the purchasedByThirdParty() gets called where the owner is set to thirdParty and the present data gets pushed to the productHistory[] (which helps us to track the origin and handling of the product). Simultaneously, the product is shipped by the manufacturer (shipToThirdParty()) and is received by the Third Party where receivedByThirdParty() is called and the details of the Third Party seller are entered. Each of these checkpoint's data is stored in product history with the state being updated at each step.

The online purchase of the product takes place from the Third Party. When the customer orders the product, it is shipped by the Third Party (shipByThirdParty()) and received by the delivery hub where the receivedByDeliveryHub() is called. Here the customer address is stored, owner is set to Delivery Hub, details of the Delivery Hub are fed and the current data state gets pushed to the productHistory[].

Finally the product is shipped by the Delivery Hub (shipByDeliveryHub()) and received by the customer where the receivedByCustomer() is called and the current and final state gets pushed to the productHistory[].

All of these juncture functions shall be called only after complete verification of product and productHistory[] while entering a checkpoint. (eg:- Customer accepts and confirms the product by clicking the receive button from his account only after it verifies the product).

fetchProductPart1(), fetchProductPart2(), fetchProductPart3(), fetchProductHistoryLength(), fetchProductCount(), fetchProductState() are the functions to retreive data of a product queried with UID and data type as product(current state) or history.

The hashes(read certificates) are generated using the Solidity cryptographic function keccak256() which implements a SHA-3 hash in the blockchain setup. keccak256() generates a secure 256-bit hash which is the main basis of security in the entire mainnet apart from the smart contracts being immutable. In our supply chain setup certificates are generated at every stage of shipping of the product.

Contract Diagrams

Activity Diagram

The overall flow of the project is described as follows.

Sequence Diagram

The flow of the functions in the smart contracts.

Data Flow Diagram

The entire structure of the code.

Run Locally

Configure ganache-cli for 10 accounts and extend gasLimit to 6721975000 and beyond, so as to have enough gas for migrating the smart contracts and a data flow for the prototype.

ganache-cli --accounts 10 --gasLimit 6721975000

If you want to run the ganache-cli on docker then use the following command

sudo docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -h 0.0.0.0 --accounts 10 --gasLimit 6721975000

Migrate the contracts

truffle migrate --network=develop --reset

Open a second terminal and enter the client folder

cd client

Run the app

npm start

The app gets hosted by default at port 3000.

License

This project uses an MIT license.

Documentation to help with Solidity

https://docs.soliditylang.org/en/v0.8.4/

Documentation to help with React

https://reactjs.org/docs/getting-started.html

Documentation to help with Truffle

https://www.trufflesuite.com/docs/truffle/reference/configuration

Documentation to help with Ganache-cli

https://www.trufflesuite.com/docs/ganache/overview

About

Supply-chain-dapp is such an implementation of a supply chain management system which uses blockchain to ensure a transparent and secure transfer of product from the manufacturer to the customer via the online e-commerce websites.

Resources

License

Stars

Watchers

Forks