Skip to content

deadlycoder07/eth-supplychain-dapp

Repository files navigation



Supply-Chain-Dapp

          

A simple Supply Chain setup with Solidity.

DescriptionArchitectureFlowWorkingContract DiagramsInstallation and SetupLicense

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 transparency and helps to build an efficient Root of Trust. Spply-chain-dapp is such an implementation of a supply chian management system wich 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

Working

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.

Installation and Setup

Prerequisites : npm, git, docker(optional)

Clone the repository

git clone https://github.com/rishav4101/eth-supplychain-dapp.git && cd eth-supplychain-dapp

Install dependencies

npm i

Install ganache-cli

npm i -g ganache-cli

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

Open a second terminal and enter the client folder

cd client

Install all packages in the package.json file

npm i

Setup an .env file using the nano .env command and enter the google maps api key and set the react rpc port to 8545 since the ganache-cli runs on the same port by default. The final .env file must look like this

REACT_APP_GOOGLE_MAP_API_KEY=*************************
REACT_APP_RPC=http://127.0.0.1:8545/

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

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •