Blockchain Laboratory Manual for IT Students
Blockchain Laboratory Manual for IT Students
Blockchain
(3171618)
B.E. Semester 7
(Information Technology)
1
CERTIFICATE
Date: __________
2
Experiment:1
Create Private Blockchain.
Introduction:
A private blockchain, often referred to as a permissioned
blockchain, is a type of blockchain network that is accessible only to authorized
participants or entities.
• Unlike public blockchains, where anyone can join and participate, private
blockchains restrict access to a defined group of users who are granted
permission to interact with the network.
• These users are typically known and trusted entities, such as organizations
or consortium members.
• Private blockchains are designed to provide enhanced privacy, control,
and scalability while maintaining the fundamental principles of blockchain
technology, including distributed ledger, immutability, and transparency.
• These networks are commonly used for various business and enterprise
applications, such as supply chain management, financial transactions,
and internal data sharing, where participants require a high degree of
control over access and governance.
3
[Link]
const SHA256 = require("crypto-js/sha256");
class Block {
constructor(index, timestamp, data, previousHash = "") {
[Link] = index; [Link] = timestamp;
[Link] = data; [Link] = previousHash;
[Link] = [Link]();
}
// Class of Blockchain
class Blockchain {
createGenesisBlock() {
return new Block(0, [Link](), "Genesis Block", "0");
}
constructor() {
[Link] = [[Link]()];
[Link] = 100; // Adjust the difficulty for mining
[Link] = [];
}
getLatestBlock() {
return [Link][[Link] - 1];
}
4
timestamp;
const prevHash = [Link];
const index = [Link] + 1;
let { difficulty } = prevBlock;
const nonce = [Link]([Link]() * 100) + 1;
[Link](nonce);
let temp = -1;
do {
temp++; timestamp = [Link]();
hash = SHA256(
hash, timestamp, nonce, difficulty, data, prevHash ).toString();
} while (temp != nonce);
[Link]("mining");
return {
index, timestamp, prevHash, nonce, data, hash,
};
}
5
Redis:
Redis, which stands for REmote DIctionary Server, is an open-source,
in-memory data structure store and caching system. It is often referred to as a
"data structure server" because it allows you to store various data structures
such as strings, hashes, lists, sets, and more. Redis is known for its exceptional
speed, high performance, and versatility, and it is widely used in various
applications and use cases.
[Link]
The "PubSub" class is a messaging system that enables communication between
different parts of a blockchain application. It uses the Redis library for messaging.
The class provides the ability to publish and subscribe to specific message
channels.
const CHANNEL = {
TEST: "TEST", BLOCKCHAIN: "BLOCKCHAIN",
};
class PubSub {
constructor(blockChain) {
[Link] = blockChain;
[Link] = [Link]();
[Link] = [Link]();
[Link]([Link]);
[Link]([Link]);
6
[Link]("message", (channel, message) =>
[Link](channel, message)
);
}
handleMessage(channel, message) {
[Link](`Message "${message}" received on channel "${channel}"`);
const parseMessage = [Link](message);
}
broadcastChain() {
[Link]({
channel: [Link],
message: [Link]([Link]),
});
}
}
[Link] = PubSub;
[Link]
This file have all the “accessKey” so when any one what’s to access the
blockchain he/she will need his/her own accesskey. It works same as the
password for authorizing the user for accessing the blockchain.
const keyList = [
{
name: "Aashutosh",
key: "R220",
},
{
name: "Uttam",
key: "123455",
},
{
name: "Divyesh",
key: "098765",
},
];
[Link] = keyList;
7
[Link]
For creating the APIs for storing and retrieving blockchain data.
This file uses the blockchain instance for storing the data.
Uses a publishSubciber class for publishing the blockchain data to all the nodes
with the help of Redis server.
[Link]([Link]());
8
const rootChain = [Link](body);
[Link](rootChain);
[Link]("Rootchain:", rootChain);
}
});
};
let PEER_PORT;
if ([Link].GENERATE_PEER_PORT === "true") {
PEER_PORT = DEFAULT_PORT + [Link]([Link]() * 1000);
}
const PORT = PEER_PORT || DEFAULT_PORT;
[Link](PORT, () => {
[Link]("Server is listening at :", PORT);
synChains();
});
These are the dependencies that you will need to execute the
program:
[Link]
{
"name": "bc-2",
"version": "1.0.0",
"description": "",
"main": "[Link]",
"scripts": {
"dev-peer": "cross-env GENERATE_PEER_PORT='true' nodemon [Link]",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"cross-env": "^5.2.0",
"crypto": "^1.0.1",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"hex-to-binary": "^1.0.1",
"redis": "^2.8.0",
"request": "^2.88.2"
}
}
9
OUTPUT:
Step-1: Start the server.
Node [Link]
Step-2: Open postman and send a request to API which is mention is [Link].
In a request there are two fields one is accesskey for accessing and authorizing
the user and second is data which you want to add.
When you send a request first it will check for the correct acesskey then if it is
correct then it will do mining using normal function and add a data to blockchain
else it will send you a message like access denied.
For example:
With wrong accesskye:
10
With correct accesskey:
After successful mining data is added to blockchain and new block is broadcast
to all the nodes.
11
Observations:
1. The parameters defined in Genesis file.
index, timestamp, data, previousHash, hash, nonce.
2. The parameters defined in Nodes
index, timestamp, data, previousHash, Hash, nonce
Quiz:
1) Which actors are involved in private networks?
In private networks, the actors involved are typically known and trusted
entities or participants, such as organizations, businesses, or consortium
members. Access to the network is restricted to these authorized participants,
ensuring that only approved parties can participate.
2) Which consensus algorithm is used?
The code seems to simulate a simplified mining process to find a valid
nonce, which is the proof-of-work (PoW) consensus algorithm.
3) What is the cost involved in each Transaction?
This is a simple representation of a blockchain. It does not specify any
cost associated with transactions. In a real blockchain network, the cost of each
transaction can vary and typically involves a transaction fee paid to miners or
validators for processing the transaction.
12
Experiment:2
Create Public Blockchain.
13
class Block {
constructor(index, timestamp, data, previousHash = "") {
[Link] = index; [Link] = timestamp;
[Link] = data; [Link] = previousHash;
[Link] = [Link]();
}
// Class of Blockchain
class Blockchain {
createGenesisBlock() {
return new Block(0, [Link](), "Genesis Block", "0");
}
constructor() {
[Link] = [[Link]()];
[Link] = 100; // Adjust the difficulty for mining
[Link] = [];
}
getLatestBlock() {
return [Link][[Link] - 1];
}
14
let { difficulty } = prevBlock;
const nonce = [Link]([Link]() * 100) + 1;
[Link](nonce);
let temp = -1;
do {
temp++; timestamp = [Link]();
hash = SHA256(
hash, timestamp, nonce, difficulty, data, prevHash ).toString();
} while (temp != nonce);
[Link]("mining");
return {
index, timestamp, prevHash, nonce, data, hash,
};
}
15
Redis:
Redis, which stands for REmote DIctionary Server, is an open-source,
in-memory data structure store and caching system. It is often referred to as a
"data structure server" because it allows you to store various data structures
such as strings, hashes, lists, sets, and more. Redis is known for its exceptional
speed, high performance, and versatility, and it is widely used in various
applications and use cases.
[Link]
The "PubSub" class is a messaging system that enables communication between
different parts of a blockchain application. It uses the Redis library for messaging.
The class provides the ability to publish and subscribe to specific message
channels.
const CHANNEL = {
TEST: "TEST", BLOCKCHAIN: "BLOCKCHAIN",
};
class PubSub {
constructor(blockChain) {
[Link] = blockChain;
[Link] = [Link]();
[Link] = [Link]();
[Link]([Link]);
[Link]([Link]);
16
[Link]("message", (channel, message) =>
[Link](channel, message)
);
}
handleMessage(channel, message) {
[Link](`Message "${message}" received on channel "${channel}"`);
const parseMessage = [Link](message);
}
broadcastChain() {
[Link]({
channel: [Link],
message: [Link]([Link]),
});
}
}
[Link] = PubSub;
[Link]
For creating the APIs for storing and retrieving blockchain data.
This file uses the blockchain instance for storing the data.
Uses a publishSubciber class for publishing the blockchain data to all the nodes
with the help of Redis server.
[Link]([Link]());
17
[Link]("/blockchainData", (req, res) => {
[Link]([Link]);
});
let PEER_PORT;
if ([Link].GENERATE_PEER_PORT === "true") {
PEER_PORT = DEFAULT_PORT + [Link]([Link]() * 1000);
}
const PORT = PEER_PORT || DEFAULT_PORT;
[Link](PORT, () => {
[Link]("Server is listening at :", PORT);
synChains();
});
These are the dependencies that you will need to execute the
program:
[Link]
{
"name": "bc-2",
"version": "1.0.0",
"description": "",
"main": "[Link]",
"scripts": {
"dev-peer": "cross-env GENERATE_PEER_PORT='true' nodemon [Link]",
"test": "echo \"Error: no test specified\" && exit 1"
18
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"cross-env": "^5.2.0",
"crypto": "^1.0.1",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"hex-to-binary": "^1.0.1",
"redis": "^2.8.0",
"request": "^2.88.2"
}
}
OUTPUT:
Step-1: Start the server.
Node [Link]
Step-2: Open postman and send a request to API which is mention is [Link].
For example:
19
You can create a peer node using Redis in [Link] file a one script is
mention of dev-peer this script is helpful to create a peer-node and it is in sync
with the original blockchain.
Command: npm run dev-peer
20
Observations:
3. The parameters defined in Genesis file.
index, timestamp, data, previousHash, hash, nonce.
4. The parameters defined in Nodes
index, timestamp, data, previousHash, Hash, nonce
Quiz:
1. Which actors are involved in public networks?
In public blockchain networks, there are two primary actors:
Miners/Validators: These participants validate transactions, add new
blocks to the blockchain, and secure the network.
Users: Anyone can be a user in a public blockchain network. They can send
and receive transactions and interact with smart contracts.
2. Which consensus algorithm is used?
It uses a simplified mining process to find a valid nonce, which is similar to
the proof-of-work (PoW) consensus algorithm. In real public blockchain
networks like Bitcoin and Ethereum, PoW is commonly used for
consensus.
3. What is the cost involved in each Transaction?
The provided code does not specify any cost associated with transactions.
In a real blockchain network, the cost of each transaction can vary and
typically involves a transaction fee paid to miners or validators for
processing the transaction.
21
Experiment:3
Create Consortium Blockchain.
Introduction:
A consortium blockchain is a type of blockchain network that is
jointly operated and maintained by a consortium or group of organizations.
Unlike public blockchains, which are open to anyone, consortium blockchains are
permissioned, meaning that only a select group of participants have the
authority to validate and record transactions on the network.
• It's a bit like having a group of friends who all agree on the rules and can
play together in their own sandbox, making it faster and more controlled
compared to public blockchains like Bitcoin or Ethereum.
• Consortium blockchains are often used by organizations and businesses to
maintain a degree of privacy and control over their blockchain network
while still benefiting from the security and transparency of blockchain
technology.
• Consortium blockchains involve multiple trusted organizations
collaborating on a permissioned blockchain, sharing governance and
control, making them more decentralized than fully private blockchains.
• Private blockchains, on the other hand, are controlled by a single entity
with centralized governance, typically used for internal or proprietary
purposes, whereas consortium blockchains are often employed in
scenarios where multiple organizations need to securely collaborate and
share data.
Hyperledger Fabric:
Hyperledger Fabric is a popular platform for creating consortium
blockchains. Hyperledger Fabric is a permissioned blockchain framework that
provides the tools and infrastructure for building and deploying private or
consortium blockchains for business and enterprise use cases.
We are using Hyperledger Fabric for creating a Consortium blockchain.
Platform: Kali Linux/Ubuntu/Any Linux System.
Prerequisites: Download docker, docker-compose, curl, Golang-go.
22
To carry out Environment set up
Step 1: Enable for Virtual Machine Platform and Windows subsystem for Linux in
Windows.
23
Step 5: Move to the test-network folder in fabric-samples.
Step 6:
./[Link] generate
24
Genesis file will be created, org1, org2, orderer would be created. And then
peers would be added.
[Link] Genesis block is typically created when you initialize the channel. If
you've already created the channel "mychannel," the Genesis block should be
generated.
[Link] configuration for the Genesis block is usually defined in a file called
[Link] in your Hyperledger Fabric network's configuration directory.
You may need to update this file to make changes to the Genesis block. For
example, you can define the initial consortium configuration.
25
(d) To Nodes/Peers:
Adding Org1 and Adding Org2:
26
Network is ready and running, here are the default network characteristics
Observations:
27
Experiment:4
Take Top 9 student data- Name, Semester, Branch, SPI, Mobile
number. Create Block for each student. Prepare Blockchain of this
student’s data in GO language pro0f of work (POW).
Introduction:
GO language:
Go, often referred to as Golang, is a statically typed, compiled
programming language designed for simplicity and efficiency. Created by Google
in 2007, Go has gained popularity for its clean and concise syntax, strong support
for concurrent and parallel programming, and its suitability for building scalable
and high-performance applications.
• Go's design focuses on developer productivity, making it a versatile
language for a wide range of applications, from web servers and
microservices to system-level programming.
Consensus Mechanisms:
Consensus mechanisms like PoW are vital in blockchain networks to
achieve agreement among participants. These mechanisms ensure that all nodes
in the network reach a common understanding of the blockchain's history and
transactions.
• Besides PoW, other consensus mechanisms include Proof of Stake (PoS).
Each has its advantages and trade-offs, catering to different use cases and
priorities, such as security, decentralization, and energy efficiency.
28
• PoW is the underlying mechanism behind Bitcoin and various other
cryptocurrencies, ensuring the network's security by making it
computationally expensive to attack or manipulate.
[Link]
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"time"
)
29
Timestamp: [Link]().Unix(),
Student: StudentData{
Name: "Genesis",
Semester: "N/A",
Branch: "N/A",
SPI: 0.0,
MobileNumber: "N/A",
},
PrevHash: "0",
Hash: "",
Nonce: 0,
}
}
func main() {
difficulty := 4 // Adjust the difficulty level as needed
blockchain := []Block{createGenesisBlock()}
30
var students []StudentData
OUTPUT:
I am using online GO language compiler for executing the code.
We need to enter the total number of students and all student data.
31
32
Observations:
1) The parameters defined in Genesis file.
Index, time-stamp, hash, previoushash, data, nonce.
2) The parameters defined in Nodes are
Index, time-stamp, hash, previoushash, data, nonce.
Quiz:
1) How nodes are connected to each other?
In the provided code, there is no network or node connectivity involved.
The code represents a simplified, single-node blockchain running as a standalone
program. In a real blockchain network, nodes are typically connected to each
other through a peer-to-peer network where they communicate using protocols
such as the Bitcoin protocol or Ethereum's Whisper protocol.
33
Experiment-5:
Blockchain Ethereum Platform using solidity.
Write a “CrowdSource” Program to collect 2 ethers from Accounts until
it reaches 20 ethers. Once it reaches 10 transfer ethers fund to the
owner.
Introduction:
Solidity:
Solidity is a high-level programming language specifically designed
for developing smart contracts on the Ethereum blockchain. It is a fundamental
component of the Ethereum ecosystem, enabling the creation of decentralized
applications (DApps) and self-executing agreements.
• Smart contracts are self-executing contracts with the terms of the agreement
between buyer and seller directly written into code.
• Solidity is the language used to write and deploy these contracts, allowing
developers to define the rules and behaviours of these contracts, which are
then executed on the Ethereum Virtual Machine (EVM).
34
contracts. It offers a user-friendly interface and a comprehensive set of features,
making it an ideal choice for blockchain developers, especially those who are
new to Ethereum development.
• [Link]
• For "CrowdSource" program, Remix IDE will be an invaluable tool. You can
write the Solidity code for your program directly in the IDE, compile it, and
test it on various Ethereum networks to ensure it behaves as expected.
• Together, Remix and Solidity form a powerful combination for Ethereum
smart contract development, allowing developers to bring their
blockchain ideas to life efficiently and securely.
Implementation:
Here are the steps for performing the practical project of creating a
"CrowdSource" program to collect 2 ethers from accounts until it reaches 20
ethers, transferring funds to the owner when it reaches 10 ethers using Remix
IDE:
• Set Up Remix IDE: Open Remix IDE in your web browser using
[Link]
• Create a New Smart Contract: Write the Solidity code for "CrowdSource"
program in Remix.
• Compile Your Smart Contract: Use the Solidity compiler in Remix to check
for errors.
• Deploy Your Smart Contract: Choose an environment and deploy your
smart contract.
• Interact with Your Smart Contract: Use the Remix user interface to
contribute ethers and test the program.
• Test and Monitor: Verify that funds are transferred to the owner when the
condition is met.
These steps will help you create and test your "CrowdSource" program using
Remix IDE.
35
[Link]
//Crowdfunding
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;
contract Crowdfunding{
// creating a variables
address public creator; //address of the creator
uint256 public goal; // Goal amount
uint256 public deadline; // Deadline
mapping (address=>uint256) public contributions; //Contributions list
uint256 public totalContributions; //number of total contrubution
bool public isGoalAchived;
bool public isCompleted;
// Modifiers for rectrices the access like onlyOwner can withdraw the money
modifier onlyCreator() {
require([Link] ==creator, "Only the creator can allow to perform this task");
_;
}
if(totalContributions >=goal){
isGoalAchived = true;
// Calling the event
emit GoalReached(totalContributions);
}
emit FundTransfer(([Link]), contribution);
}
isCompleted = true;
payable(creator).transfer(withdrawEthers);
}
function getCurrentBalance() public view returns(uint256) {
return address(this).balance;
}
}
OUTPUT:
Step-1:
• Compile above code.
• Select any account as a creator/owner.
• Enter Goal Ethers and duration of a contract.
• Deploy the contract using deploy/transact button.
• Initially the amount in contract is Zero as show in image.
• Now you are able to see the Deployed contracts as showed in image. Click
on that deployed contract to interact.
Step-2:
• Select another account for contributing the Ethers.
• Enter VALUE field for how much amount of cryptocurrency you want to
contribute in the contract and select type of cryptocurrency.
• Click on contribute button for transferring the Ethers to contract.
37
Step-3:
• Now select the same account which you used to deployed the contract
(Owner’s account).
• Enter the amount Ether for withdrawing that much ether from the
contract after reaching at the goal.
38
Observations:
1) The structure of Smart Contract Program.
The provided code is a Solidity smart contract program designed for
crowdfunding. It includes state variables, a constructor, functions, and events.
The program allows users to contribute funds to a crowdfunding campaign and
the contract creator to withdraw the funds once the goal is reached.
2) Solidity state variables:
o creator: An address variable representing the address of the contract
creator.
o goal: A uint256 variable representing the fundraising goal amount.
o deadline: A uint256 variable representing the deadline for the
crowdfunding campaign.
o isGoalAchieved: A Boolean variable indicating whether the fundraising
goal has been achieved.
o isCompleted: A Boolean variable indicating whether the crowdfunding
campaign is completed.
Quiz:
1) What is to be mentioned in Pragma statement?
The pragma statement in a Solidity contract specifies the compiler
version to be used for compiling the contract code. It helps ensure that the code
is compatible with a specific version of the Solidity compiler.
2) Explain the concept of Modifier.
A modifier in Solidity is a reusable piece of code that can be applied to
functions in a contract to add or restrict certain behaviour. It allows you to
encapsulate common logic or conditions that multiple functions should share.
• When a modifier is used, it is placed before the function definition, and
the code in the modifier is executed before the function's code. For
example, a common modifier is onlyOwner, which restricts access to a
function to the contract owner.
39
Experiment:6
Prepare a smart contract between you and your professor and submit
the practical performed by you. Your professor should be able to check
your identity.
Introduction:
Our objective is to develop a blockchain-based smart contract that
facilitates the submission of practical work from a student to their professor. The
key requirement is to ensure that the professor can securely verify the student's
identity as the legitimate submitter.
o For this first we need a platform for student login and registration for
taking students details like name, enrolment, email and password.
o Also, only the authorize student can submit the practical.
o After this student now able to submit their practical file.
o This file is stored in blockchain with student data like enrolment, name etc
and it will access by only a professor.
Prerequisites:
To get started, ensure that you have the following prerequisites in place:
o [Link]: The project requires [Link] to run the backend server.
o Vite: Vite is used for creating the frontend interface for submitting and
checking the identity and practical.
o MongoDB: We utilize MongoDB to store student and professor credentials
so only authorize user can submit the task.
o Postman: Postman is used for testing API requests and viewing blockchain
data.
40
o Set up Frontend (Vite): Configure the frontend using Vite. Create user
interfaces to interact with the blockchain.
o Set up Backend ([Link]): The backend handles blockchain transactions
and manages MongoDB data.
Blockchain Implementation:
The blockchain is a fundamental component of the project. It
enables secure smart contract transactions between students and professors. It
stores the student information like enrolment number which is unique identity
of the student. Only the professor has to access of this blockchain for checking
the work submitted by the student.
Here, we briefly outline key components:
o Blocks: The structure of blocks in blockchain, including timestamp, data,
previous hash, hash.
o Mining: It uses a simplified mining process to find a valid nonce, which is
similar to the proof-of-work (PoW) consensus algorithm.
o Smart Contracts: When the use login in the portal with the help of its email
and password then it checks for the authorization so student is able to
submit his/her practical.
o When the professor login with his/her credentials so they can access the
blockchain.
o We are using the Public blockchain which we created in our practical 2.
User Interface:
[Link]
import React, { useEffect, useState } from "react";
import SubmissionForm from "../../src/Components/SubmissionForm/SubmissionForm";
import Intro from "../../src/Components/Intro/[Link]";
import Login from "../../src/Components/Auth/Login/Login";
import CheckPractial from "../../src/Components/CheckPractical/CheckPractial";
import "./[Link]";
41
if (page == name) {
setPage("");
} else {
setPage(name);
}
};
<div className="details">
<div className="details-field">
<span>Email:</span>
<input type="email" onChange={(e) => setEmail([Link])} />
</div>
<div className="details-field">
<span>Password:</span>
<input
type="password"
onChange={(e) => setPassword([Link])}
/>
</div>
</div>
<button className="submit-button" onClick={loginStudent}>
Login
</button>
</div>
</div>
);
}
43
Note: Student have to login first then submit the actical.
</div>
</div>
);
}
45
enrollment: [Link]("enrollment"),
practical: base64String,
},
})
.then((responce) => {
alert([Link]);
[Link]([Link]);
});
};
return (
<div className="register-form-container">
<div className="details">
<div className="title">Submit Your Practicals:</div>
<div> <div>Name:</div> <input type="text" value={[Link]("name")} />
</div>
<div> <div>Enrollment:</div>
<div> <input type="text" value={[Link]("enrollment")} /> </div>
</div>
<input type="file" onChange={(e) => handleFileChange(e)} />
</div>
<button onClick={submitPractical} className="submit-button">
Submit
</button>
</div>
);
}
46
// Create a URL for the Blob and open it in a new tab
const url = [Link](blob);
[Link](url);
};
return (
<div>
<button onClick={downloadPDF} className="submit-button">
View Practical
</button>
</div>
);
}
class Block {
constructor(index, timestamp, data, previousHash = "") {
[Link] = index; [Link] = timestamp;
[Link] = data; [Link] = previousHash; [Link] = [Link]();
}
calculateHash() {
return SHA256(
[Link] + [Link] + [Link]([Link]) + [Link]
).toString();
}
}
class Blockchain {
createGenesisBlock() {
return new Block(0, [Link](), "GENESIS_BLOCK", "0");
}
constructor() {
[Link] = [[Link]()];
[Link] = 100; // Adjust the difficulty for mining
}
getLatestBlock() {
47
return [Link][[Link] - 1];
}
addBlock({ data }) {
const newBlock = [Link]({
prevBlock: [Link][[Link] - 1],
data,
});
[Link](newBlock);
}
isChainValid() {
for (let i = 1; i < [Link]; i++) {
const currentBlock = [Link][i];
const previousBlock = [Link][i - 1];
if ([Link] !== [Link]()) {
return false;
}
if ([Link] !== [Link]) {
return false;
}
}
return true;
}
replaceChain(chain) {
if ([Link] <= [Link]) {
[Link]("The incoming chain is not longer");
48
return;
}
if () {
[Link]("The incoming chain is not valid");
return;
}
[Link] = chain;
}
}
const blockChain = new Blockchain();
[Link] = Blockchain;
[Link](cors());
setTimeout(() => [Link](), 1000);
[Link]([Link]());
49
[Link]("Done added");
[Link]({ myChain, message: "Your submission is sucessful." });
});
let PEER_PORT;
if ([Link].GENERATE_PEER_PORT === "true") {
PEER_PORT = DEFAULT_PORT + [Link]([Link]() * 1000);
}
const PORT = PEER_PORT || DEFAULT_PORT;
[Link](PORT, () => {
[Link]("Server is listening at :", PORT);
synChains();
});
User login:
[Link]
const express = require("express");
const cors = require("cors");
const Dbconnect = require("./config/[Link]");
const app = express();
[Link](cors());
[Link]([Link]());
const PORT = 3000;
Dbconnect();
// routes
[Link]("/api/users", require("./routes/[Link]"));
50
Database connection for storing User information
[Link]
const mongoose = require("mongoose");
const url = "mongodb://[Link]:27017/BCPR6";
[Link] = Dbconnect;
[Link]("/userRegister", userRegister);
[Link]("/userLogin", userLogin);
[Link] = router;
51
data: "Login SuccessFull",
name: [Link],
enrollment: [Link],
role: [Link],
});
} else {
[Link](400).json({
data: "Wrong Credentials",
});
}
} else {
[Link](201).json({ data: "User Does not exists" });
}
};
[Link] = {
userRegister,
userLogin,
};
Mongo dB database:
52
OUTPUT:
At student Side:
1. Simple user interface: 2. Login User:
At professor side:
Professor Login:
53
When professor click on view practical:
54
How the data store in blockchain:
55