Skip to content

andrzimin72/supply-chain-management-contract

Repository files navigation

Supply chain management contract

In recent years, compared to traditional supply chain systems blockchain technology provides countless opportunities and potential to improve and develop the framework in a supply chain management model. I’v developed a supply chain management contract built using blockchain technology that provides access to services which include inventory tracking, order placement and product attribute information log. This decentralized technology is spread across many computers and records every transaction. The contract provides secure and authentic information to its users at all stages using a dApp to ensure a seamless experience for verifying and maintaining data regarding all orders. May be this solidity contract is quite universal and covers a basic supply chain or e-commerce use case with producers, products, and orders. However, additional functionalities can be added in the future with enhanced compatibility: adding NFTs for products (ERC721); storing product metadata on IPFS; building a marketplace UI; writing a whitepaper or documentation; creating a token (ERC20) for rewards.

Setup

  1. Create Project Root
mkdir farm-to-chain-dapp && cd farm-to-chain-dapp
  1. Initialize Node.js & Install Dependencies
npm init -y
npm install --save-dev hardhat
npx hardhat
# Choose "Create an empty hardhat.config.js"

Install dependencies:

npm install @nomicfoundation/hardhat-toolbox
npm install dotenv
  1. Add Contract (contracts/MyContract.sol) Create folder:
mkdir contracts

Paste in the updated contract from earlier.

  1. Add Deployment Script (scripts/deploy.js)
mkdir scripts
touch scripts/deploy.js

Paste the deploy script code from above.

  1. Add Test File (test/mycontract.test.js)
mkdir test
touch test/mycontract.test.js

Paste in the test code.

  1. Add Frontend App
npx create-react-app frontend
cd frontend
npm install ethers wagmi viem web3modal

Replace contents of src/App.jsx and index .js with the React code provided earlier.

  1. Configure Hardhat Edit hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

module.exports = {
  solidity: "0.8.24",
  networks: {
  goerli: {
  url: process.env.ALCHEMY_GOERLI_URL || "",
      accounts:
        process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    },
  },
};
  1. Add .env File
ALCHEMY_GOERLI_URL=https://eth-goerli.g.alchemy.com/v2/YOUR_API_KEY
PRIVATE_KEY=your_wallet_private_key
  1. Compile contract:
npx hardhat compile
  1. Deploy:
npx hardhat run scripts/deploy.js --network goerli
  1. Run tests:
npx hardhat test
  1. Start frontend:
cd frontend
npm start

Deploy to Goerli Testnet

  1. Get Goerli ETH Go to a faucet like:
  1. Set Up Alchemy / Infura Sign up at:
1 ALCHEMY_GOERLI_URL=https://eth-goerli.g.alchemy.com/v2/YOUR_API_KEY
2 PRIVATE_KEY=your_wallet_private_key
  1. Deploy Contract
npx hardhat run scripts/deploy.js --network goerli

Save the deployed contract address.

  1. Update Frontend with Contract Address In frontend/src/App.jsx, replace:
const contractAddress = "YOUR_CONTRACT_ADDRESS";

with your actual deployed address.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors