GithubHelp home page GithubHelp logo

onesco / eth-supplychain-dapp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rishav4101/eth-supplychain-dapp

0.0 0.0 0.0 3.67 MB

A supply chain management system based on block-chain network.

License: MIT License

Shell 0.06% JavaScript 84.71% CSS 0.42% HTML 1.08% Solidity 13.73%

eth-supplychain-dapp's Introduction



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 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

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

Migrate the contracts

truffle migrate --network=develop --reset

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

eth-supplychain-dapp's People

Contributors

rishav4101 avatar deadlycoder07 avatar archi-007 avatar abhinavkrishna26 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.