A Supply Chain Management System with Solidity.
Origin Chain is a blockchain-based supply chain management system designed specifically for agricultural products, though it is adaptable to other types of supply chains. This system leverages smart contracts to ensure a transparent and secure transfer of products from the raw material supplier to the end customer. The use of blockchain technology reduces administrative overhead, increases transparency, and builds an efficient root of trust among all parties involved.
Origin.Chain.Demo.mp4
The smart contract is written in Solidity and is compiled, migrated, and deployed using Truffle.js on the Gode Testnet blockchain network. The frontend uses Web3.js to interact with the smart contract and the Gode Testnet blockchain network. MetaMask Wallet is used to perform transactions between each component in the supply chain.
This smart contract models various roles and stages involved in the supply chain of agricultural products:
- Raw Material Supplier: Provides the raw materials required for production.
- Manufacturer: Converts raw materials into finished products.
- Distributor: Distributes the products to retailers.
- Retailer: Sells the final products to customers.
- Customer: The end consumer of the products.
The contract owner deploys the contract and is responsible for authorizing various roles like retailer, manufacturer, etc. It stores information about the products, such as name, description, and current stage in the supply chain. Functions like addRMS()
, addManufacturer()
, addDistributor()
, and addRetailer()
are used by the contract owner to add new players to the supply chain, ensuring transparency and accountability.
- Registration: The raw material supplier, manufacturer, distributor, and retailer register on the blockchain.
- Owner Verification: The owner checks the addresses.
- Valid Address: Verified and registered.
- Invalid Address: Not registered.
- Ledger: Every transaction is recorded in the ledger, and any node can view the transaction.
- VSCode: Download from here.
- Node.js: Download the latest version from here and check the version using terminal:
node -v
. - Git: Download the latest version from here and check the version using terminal:
git --version
. - Ganache: Download the latest version from here.
- MetaMask: Install as a browser extension from the Chrome Web Store or Firefox Add-ons store.
-
Open VSCode and open the terminal by pressing
Ctrl + '
. -
Clone the project:
git clone https://github.com/Mohit6304/OriginChain.git
-
Install Truffle globally:
npm install -g truffle
-
Install dependencies:
npm install
-
Compile the smart contract:
truffle compile
-
Deploy the smart contract:
- Open Ganache and create a new Workspace. Copy the RPC Server Address.
- Add the RPC address in
truffle-config.js
and replace the host address and port address with your Ganache RPC. - Open terminal and run:
truffle migrate
-
Open a second terminal and enter the client folder:
cd client
-
Install all packages in the
package.json
file:npm install
-
Install Web3:
npm install --save web3
-
Run the app:
npm start
The app gets hosted by default at port 3000.
-
Start Ganache: Start the Ganache application and note the RPC server URL and port number.
-
Connect MetaMask:
- Open MetaMask in your browser and click on the network dropdown in the top-right corner.
- Select "Custom RPC" and enter the RPC server URL and port number for your Ganache instance. Click "Save".
-
Import an account:
- In Ganache, click on the "Accounts" tab and select the first account listed. Click on the "Copy" button next to the "Private Key" field to copy the private key.
- In MetaMask, click on the three dots in the top-right corner, select "Import Account", and paste the private key into the private key field. Click "Import".
This project uses an MIT license.