Commit a18a8a33 authored by Hammad ul Azeem's avatar Hammad ul Azeem

Upload New File

parent e0b17420
const express = require('express');
const Web3 = require('web3');
const contractAbi = [/* Paste the ABI of the SupplyChain contract here */];
const contractAddress = '0x...'; // Paste the address of the deployed contract here
const web3 = new Web3('http://localhost:8545'); // Update the URL if using a different Ethereum node
const supplyChainContract = new web3.eth.Contract(contractAbi, contractAddress);
const app = express();
app.set('view engine', 'ejs');
app.use(express.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.render('index');
});
app.post('/create-item', async (req, res) => {
const { name, quantity } = req.body;
const accounts = await web3.eth.getAccounts();
await supplyChainContract.methods.createItem(name, quantity).send({ from: accounts[0] });
res.redirect('/');
});
app.post('/mark-in-transit', async (req, res) => {
const { itemId } = req.body;
const accounts = await web3.eth.getAccounts();
await supplyChainContract.methods.markItemInTransit(itemId).send({ from: accounts[0] });
res.redirect('/');
});
app.post('/mark-delivered', async (req, res) => {
const { itemId } = req.body;
const accounts = await web3.eth.getAccounts();
await supplyChainContract.methods.markItemDelivered(itemId).send({ from: accounts[0] });
res.redirect('/');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment