Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nisum-hackathon-2023
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hammad ul Azeem
nisum-hackathon-2023
Commits
a18a8a33
Commit
a18a8a33
authored
Jun 08, 2023
by
Hammad ul Azeem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
e0b17420
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
app.js
app.js
+41
-0
No files found.
app.js
0 → 100644
View file @
a18a8a33
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment