Internship Report
Internship Report
CHAPTER 1
BLOCKCHAIN TECHNOLOGY
A blockchain was created by a person named Satoshi Nakamoto in 2008 to serve as the
public distributed ledger for bitcoin cryptocurrency transactions, based on previous work
by Stuart Haber, W. Scott Stornetta and Dave Bayer.
1
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
4 Peer to peer: The direct exchange of an asset, such as virtual currency, between individual
parties without the involvement of a central authority.
5 Distributed ledger technology: Digital system for recording the transaction of assets
in which the transactions and their details are recorded in multiple places at the same time.
In the blockchain, the concept of centralization refers to a system whereby all the
planning, decision making and action taking activities are controlled by a particular or single
authority or platform.
2
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
2 Security: Each new block connects to all the blocks before it in a cryptographic chain in
such a way that it’s nearly impossible to tamper with. All transactions within the blocks are
validated and agreed upon by a consensus mechanism, ensuring that each transaction is true
and correct and cannot be tampered.
Encryption: This is used to protect data from being stolen, changed or compromised and
works by scrambling data into a secret code that can only be unlocked with a unique digital
key.
1 Private key: A private key is a cryptographic variable that is used in conjunction with an
algorithm to encrypt and decrypt data. Private keys should be shared only with key’s generator
or parties authorized to decrypt the data.
2 Public key: Public key cryptography is a method of encrypting or signing data with two
different keys and making one of the keys, the public key, available for any-one to use.
Hash
3
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Properties of Hash
1 Same data have same hash value, different data have different hash value.
Block
Blocks are files stored by a blockchain, where transaction data are permanently recorded. A
block records some or all of the most recent transactions not yet validated by the network. Once
the data are validated, the block is closed. Then, a new block is created for new transactions to
be entered into and validated.
Blockchain
Blockchain is a shared, immutable ledger that facilitates the process of recording transactions
and tracking assets in a business network.
An asset can be tangible (a house, car, cash, land) or intangible (intellectual property, patents,
copyrights, branding). Virtually anything of value can be tracked and traded on a blockchain
network, reducing risk and cutting costs for all involved.
4
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
5
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
2 Private block chain: Private blockchains control who is allowed to participate in the
network. The owner or operator has the right to override, edit, or delete the necessary entries
on the blockchain as required or as they see fit or make changes to the programming.
3 Hybrid block chain: It is the combination of public and private block chains.
4 Consortium block chain: Consortium blockchains are managed and run by a number
of organizations or entities. As a permissioned blockchain, users must be asked to join and
have authorization before they can access the network.
3 Public ledger: A public ledger is a digital record of transactions and data stored in a
distributed manner across several computers globally (decentralized). This ledger is a chain of
blocks, with each block containing a list of transactions.
6
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Types of nodes
1 Full node: Full Nodes are the most essential type of node in the Blockchain network. These
nodes are able to independently verify the entire Blockchain history since they download and
store copies of every transaction and block that occurs on the network.
2 Light weight nodes: Light Nodes are a more lightweight variation of Full Nodes,
sometimes referred to as SPV (Simplified Payment Verification) nodes. They are designed to
operate on mobile devices such as smartphones and tablets with limited storage and processing
power.
3 Miner nodes: Miner Nodes are responsible for validating transactions and generating new
blocks on the Blockchain. These nodes execute complex calculations to solve mathematical
problems, allowing them to create new blocks and receive rewards in the form of
cryptocurrency. Miner Nodes require specialized hardware and software to perform mining
calculations.
7
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Installation of Node.js
8
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
ganache-cli
9
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Paste these words in the meta mask and click on confirm secret recovery phase.
10
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Now in the command prompt copy any one of the private key and paste it in the above place
provided. And click on import
Similarly, you can import ten accounts and private key are available in the command prompt.
Each account will have 1000ETH, now you can transfer the digital currency from one account
to another.
11
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
12
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
It provides the tools needed to encrypt data, record transactions, and send cryptocurrency
securely, all without a centralised authority.
Cryptography is a technique or a set of protocols that secure information from any third party
during a process of communication.
2 Key: A Key is a numeric or alpha numeric text or can be a unique symbol. The Key can be
used at the time of encryption takes place on the Plain Text and at the time of decryption create
place on the Cipher text. The selection of key in Cryptography is essential because the security
of encryption algorithm depends precisely on it.
4 Cipher: The message that cannot be learned by anyone or meaningless message is what it
can call as Cipher Text. In Cryptography the original message is changed into non-readable
message before the communication of actual message.
Types of cryptography
2 Asymmetric key cryptography: In asymmetric Key cryptography, there are two keys,
also known as key pairs: a public key and a private key. The public key is publicly distributed.
Anyone can use this public key to encrypt messages, but only the recipient, who holds the
13
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
corresponding private key, can decrypt those messages. “Public-key cryptography” is another
representation used to refer to Asymmetric Key cryptography.
RSA Algorithm
1 Key generation
2 Key distribution
3 Encryption
4 Decryption
Key generation
Encryption
Decryption
n=3*11=33
ϕ(n)=(3-1)*(11-1)=2*10=20
14
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Encryption of m = 2 C=27%33=29
Decryption of c = 29 M=293%33=2
p=3
q=11
n=p*q
phi=(p-1)*(q-1)
e=2
while (e<phi):
if (math.gcd(e,phi)==1):
break
else:
e+=1
print(f'e={e}')
d=pow(e,-1,phi)
m=2
print(f'Original message={m}')
c=m**e%n
15
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
M=c**d%n
This is a mathematical scheme that is used to verify the integrity and authenticity of
digital messages and documents. Digital signature in block chain is considered as digital
version of the handwritten signature or stamped seal. Digital signature uses asymmetric key
cryptography.
Digital signature is used to validate the origin of a transaction and prevent non-repudiation
16
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
After downloading the ganache app Install it and open the app and click on quick start
17
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
18
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
19
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Smart contracts are digital contracts stored on a blockchain that are automatically executed
when predetermined terms and conditions are met.
2 Verifiability: Due to the immutable nature of blockchain, any bugs or errors will become
permanent once published and could lead to huge economic losses. To avoid such
problems, verification is required to check the correctness and the security of the smart
contract.
4 Enforceability: Smart contract code must be unambiguous and accurately reflect the
parties' intentions. Ambiguities or errors in the code can lead to unintended consequences,
challenging the enforceability of the contract.
1 Smart legal contract: There are legal guarantees for smart contracts. They follow the
format seen in contracts: “If this occurs, then this will occur.” Legal smart contracts provide
more openness between contracting entities than traditional documents because they are stored
on blockchain and cannot be altered. Contracts are executed by the parties using digital
signatures. If certain conditions are met, such as paying a debt when a predetermined date is
reached, smart legal contracts may operate on their own. If stakeholders don’t comply, there
may be serious legal ramifications.
20
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
1 Mist browser: If you are looking for the best Ethereum wallet in the existing market, Mist
would be one of the top picks for you. The best part about Mist that helped it to make it to the
list is the tag of Ethereum with it. However, you must have a designated place to store your
ETH tokens and smart contracts before using Mist. You need to remember your password
always because it’s one-time, you can never change it.
2 Truffle framework: Truffle is surely one of the best smart contract development tools
for deploying and developing Ethereum applications. Simply put, this tool offers a complete
ecosystem for your dApp development. Here you can code, create projects, run automated tests,
compile smart contracts, migrate, and interact with the contracts.
3 Meta mask: Meta mask has gained much popularity among common users over the past
few years. Convenience and simplicity are the two key features that made Meta mask one of
the most popular smart contract development tools. It offers login security, key vault, exchange
facilities, and token wallet- all under one roof. Moreover, you can also connect with the
21
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
blockchain application and browse things without threatening their privacy and security.
Additionally, this blockchain application gateway serves as a web browser extension and it also
has a mobile app. So you can easily have a handy little extension on your mobile or computer
browsers- Firefox, Opera, Chrome, Brave, and others.
4 Remix: Remix IDE will be the ultimate ETH development. It is a JavaScript-based, open-
source compiler that lets you code straight from your mobile web browser. If you are
wondering, it has a different desktop application as well. You can use this tool for writing,
testing, unravelling, and deploying smart contracts either in the browser or locally. While using
Remix, you can seamlessly connect to the ETH blockchain through Meta mask as well. If the
process seems too complicated, you can always enrol in a smart contracts course for in-depth
understanding and knowledge.
Solidity
Serpent
Viper
Lisk
Chain
What is consensus?
In the blockchain, a consensus mechanism is a system that validates a transaction and marks it
as authentic. This mechanism lists all valid transactions of a coin in a blockchain to build trust
in the coin among traders. Several currencies, such as Bitcoin, Ethereum etc., use this system
for security purposes.
Need of consensus
22
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Unified agreement
Align economic incentre
Fair and equitable
Prevent double spending
Fault tolerant
1 Proof of Work (PoW): This consensus algorithm is used to select a miner for the next
block generation. Bitcoin uses this PoW consensus algorithm. The central idea behind this
algorithm is to solve a complex mathematical puzzle and easily give out a solution. This
mathematical puzzle requires a lot of computational power and thus, the node who solves the
puzzle as soon as possible gets to mine the next block. For more details on PoW,
2 Proof of stake (PoS): This is the most common alternative to PoW. Ethereum has shifted
from PoW to PoS consensus. In this type of consensus algorithm, instead of investing in
expensive hardware to solve a complex puzzle, validators invest in the coins of the system by
locking up some of their coins as stakes. After that, all the validators will start validating the
blocks. Validators will validate blocks by placing a bet on them if they discover a block that
they think can be added to the chain. Based on the actual blocks added in the Blockchain, all
the validators get a reward proportionate to their bets, and their stake increase accordingly. In
the end, a validator is chosen to generate a new block based on its economic stake in the
network. Thus, PoS encourages validators through an incentive mechanism to reach to an
agreement.
23
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
maintained by an election system for choosing nodes which verify blocks. These nodes are
called “witnesses” or “block producers”
4 Proof of Burn (PoB): With PoB, instead of investing in expensive hardware equipment,
validators ‘burn’ coins by sending them to an address from where they are irretrievable. By
committing the coins to an unreachable address, validators earn the privilege to mine on the
system based on a random selection process. Thus, burning coins here means that validators
have a long-term commitment in exchange for their short-term loss. Depending on how the
PoB is implemented, miners may burn the native currency of the Blockchain application or the
currency of an alternative chain, such as bitcoin. The more coins they burn, the better their
chances of being selected to mine the next block. While PoB is an interesting alternative to
PoW, the protocol still wastes resources needlessly. And it is also questioned that mining power
simply goes to those who are willing to burn more money.
5 Proof of Capacity: In the Proof of Capacity consensus, validators are supposed to invest
their hard drive space instead of investing in expensive hardware or burning coins. The harder
drive space validators have, the better their chances of getting selected for mining the next
block and earning the block reward.
6 Proof of Elapsed Time: PoET is one of the fairest consensus algorithms which chooses
the next block using fair means only. It is widely used in permissioned Blockchain networks.
In this algorithm, every validator on the network gets a fair chance to create their own block.
All the nodes do so by waiting for a random amount of time, adding proof of their wait in the
block. The created blocks are broadcasted to the network for others’ consideration. The winner
is the validator which has the least timer value in the proof part. The block from the winning
validator node gets appended to the Blockchain. There are additional checks in the algorithm
to stop nodes from always winning the election, and stop nodes from generating the lowest
timer value.
7 Practical byzantine fault tolerance: The Byzantine Generals Problem describes the
complexity of reaching an agreement if there are disloyal generals. The pBFT consensus
mechanism is a secure model that can withstand dishonest validators. It reaches a consensus
when there is ⅔ agreement from the honest nodes. Hyperledger, Fabric, and other prominent
blockchains are utilizing this mechanism. However, the security of pBFT will be breached if
the dishonest nodes are more than ⅓ of all the nodes in the network. The nodes in pBFT are
divided into primary and secondary nodes. The primary nodes are the leader nodes, while the
24
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
secondary nodes are the backup nodes. The primary nodes are changed at every consensus
round.
8 Proof of Weight: Each user in this mechanism exists in weights, and how much they have
in their accounts determines their weight. The algorithm picks committee members randomly
among the users based on their weight. This randomness checkmates the possibility of having
one or many dishonest users. Honest users must have up to ⅔ of the total money in the network.
Otherwise, dishonest nodes can take over. Although the design of PoWeights might look
similar to PoS, each is different. The users only have to have tokens in PoWeights and do not
need to lock or stake them.
9 Proof of Capacity: Miners need to prove that they have the storage capacity to mine
crypto. The most recommended storage device in the instant case is a hard disk. The miner
needs to get ready before the mining kicks off. They get ready by plotting nonces. A miner can
only create as many nonces as they have space for. The network frequently broadcasts puzzles.
Any miner who has the closest hash in their nonce wins the puzzle.
10 Proof of Authority: There must be thorough due diligence on the miners for a
blockchain to be ultimately secure. Some consensus mechanisms skip this process and fall into
the hands of dishonest miners. Proof of Authority, a consensus mechanism in which validators
stake their identity, fixes this loophole in its design. Firstly, the real-life identity of each
validator is ascertained within a PoA consensus model. The network managers will check how
trustworthy the prospective validator is. This also makes it easy to track any validator in case
of foul play. Secondly, each validator must stake a certain amount of assets as a sign of
commitment. Basically, PoA validators stake their reputation and their coins.
25
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Lately, electronic voting systems have begun being used in many countries. Estonia was the
first in the world to adopt an electronic voting system for its national elections. Soon after,
electronic voting was adopted by Switzerland for its state-wide elections, and by Norway for
its council election. For an electronic voting system to compete with the traditional ballot
system, it has to support the same criteria the traditional system supports, such as security and
anonymity. An e-Voting system has to have heightened security in order make sure it is
available to voters but protected against outside influences changing votes from being cast, or
keep a voter’s ballot from being tampered with. Many electronic voting systems rely on Tor to
hide the identity of voters. However, this technique does not provide total anonymity or
integrity since many intelligence agencies around the world control different parts of the
Internet which can allow them to identify or intercept votes.
git --version
cd E-voting-system-using-blockchain-and-python
export FLASK_APP=service.py
OR
set FLASK_APP=service.py
26
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
27
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
28
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
29
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
30
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Run the below codes in command prompt to start backend ganache app
ganache-cli
Now in web search for Remix IDE and open the compiler and write a smart contract code using
solidity programming language.
31
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
32
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
CHAPTER 2
Web technology
1 Web: The World Wide Web (WWW or simply the Web) is an information system that
enables content sharing over the Internet through user-friendly ways meant to appeal to users
beyond IT specialists and hobbyists. It allows documents and other web resources to be
accessed over the Internet according to specific rules of the Hypertext transfer
protocol (HTTP).
2 Web protocols: The Internet Protocol (IP) is a protocol, or set of rules, for routing and
addressing packets of data so that they can travel across networks and arrive at the correct
destination. Data traversing the Internet is divided into smaller pieces, called packets. IP
information is attached to each packet, and this information helps routers to send packets to the
right place. Every device or domain that connects to the Internet is assigned an IP address, and
as packets are directed to the IP address attached to them, data arrives where it is needed.
1. HTML Document: An HTML document is a text file that contains a set of HTML
elements or
2. HTML Tags: HTML tags are used to define elements within an HTML document. Tags
are enclosed in angle brackets, such as `<tag>`. For example, `<h1>` defines a top-level
heading, and
3. Attributes: HTML tags can have attributes that provide additional information about an
element.
For example, the `<a>` tag for links has an `href` attribute to specify the link's destination.
33
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
5. Text and Links: HTML is used to structure text content, create headings, paragraphs, and
lists.
34
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
HTML (Hypertext Markup Language) uses tags and attributes to structure content on web
pages. Tags define different elements, while attributes provide additional information about
those elements. Here are some commonly used HTML tags and attributes:
HTML Tags:
1. <!DOCTYPE html>: This declaration defines the document type and version of HTML being
used.
2. <html>: The root element that wraps the entire HTML document.
3. <head>: Contains metadata about the document, such as the title, character set, and links to
external resources.
4. <title>: Sets the title of the web page, which appears in the browser's title bar or tab.
10. <h1>, <h2>, <h3>, <h4>, <h5>, <h6>: Headings, with <h1> being the most significant
and<h6> the least.
12. <a>: Creates hyperlinks, linking to other web pages or resources. It has attributes like `href`
to specify the link's destination.
13. <img>: Embeds images on the page and uses the `src` attribute to specify the image source.
14. <ul>: Defines an unordered list, typically used with <li> (list item) elements.
15. <ol>: Defines an ordered list, also used with <li> elements.
35
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
18. <span>: A container used for applying styles or scripting to inline content.
19. <table>: Creates a table, used with various elements like <tr> (table row), <th> (table
header), and <td> (table data).
HTML Attributes:
1. id: Provides a unique identifier for an HTML element, allowing CSS and JavaScript to target
specific elements.
2. class: Assigns one or more class names to an element, enabling CSS to target elements with
the same class.
4. src: Specifies the source location for elements like images, scripts, or iframes.
6. alt: Provides alternative text for images, which is displayed if the image cannot be loaded.
8. target: Specifies how links should be opened, such as in the same window or a new tab or
window.
10. value: Defines the initial value for input elements, like text fields.
36
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
37
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
38
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
39
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Fig 2.2.11 HTML code for input type date and time
40
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
1. Selectors: Selectors are patterns used to select the HTML elements you want to style. They
can be element names (e.g., `p` for paragraphs), class names (e.g., `.my-class`), IDs (e.g., `#my-
id`), and more.
Example:
css
p{
color: blue;
.my-class {
font-size: 18px;
2. Properties: CSS properties are the specific styles you want to apply to the selected elements.
They include attributes like `color`, `font-size`, `background-color`, and many more.
Example:
css
p{
color: blue;
font-size: 16px;
background-color: #f0f0f0;
41
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
3. Values: Values are assigned to properties to define the style. They can be units (e.g., `px`,
`%`), colors (e.g., `red`, `#00ff00`), and keywords (e.g., `bold`, `center`).
Example:
css
p{
font-size: 16px;
background-color: #f0f0f0;
5. External CSS: CSS can be included in a separate external file (usually with a `.css` extension)
and linked to an HTML document using the `<link>` tag in the document's `<head>`section
<head>
</head>
6. Internal CSS: CSS can be placed directly within an HTML document using the `<style>`
tagin
Example:
<head>
<style>
p{
color: blue;
</style>
</head>
7. Inline CSS: You can apply CSS styles directly to individual HTML elements using the `style`
42
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
attribute.
Example:
<html>
</html>
43
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
44
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
1. Variable Declaration: Variables in JavaScript are declared using the `var`, `let`, or `const`
JavaScript
const z = 10; // Declares a constant variable named z with an initial value of 10 using 'const'
- `let` is block-scoped, which means it's confined to the block where it's defined.
1 Internal JS: We can add JavaScript directly to our HTML file by writing the code inside the
<script> tag. The <script> tag can either be placed inside the <head> or the <body> tag
according to the requirement.
2 External JS: We can write JavaScript code in another files having an extension.js and then
link this file inside the <head> tag of the HTML file in which we want to add this code.
JavaScript Comments
JavaScript comments help explain code, making it easier to understand. You can also use them
to temporarily disable parts of your code. The JavaScript compiler ignores comments when
running the code.
45
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Syntax:
2. Multi-line Comments
A multiline comment in JavaScript is a way to include comments that span multiple lines in the
source code.
Syntax:
/*
*/
JavaScript Arrays
An array in JavaScript is a data structure used to store multiple values in a single variable. It
can hold various data types and allows for dynamic resizing. Elements are accessed by their
index, starting from 0.
Declaration of an Array
There are basically two ways to declare an array i.e. Array Literal and Array Constructor.
Creating an array using array literal involves using square brackets [] to define and initialize
the array. This method is concise and widely preferred for its simplicity.
Syntax:
46
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
The “Array Constructor” refers to a method of creating arrays by invoking the Array
constructor function. This approach allows for dynamic initialization and can be used to create
arrays with a specified length or elements.
Syntax:
Functions in JavaScript
47
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
48
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
49
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document
traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-
to-use API that works across a multitude of browsers. With a combination of versatility and
extensibility, jQuery has changed the way that millions of people write JavaScript.
1 Downloading jQuery
The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag
(notice that the <script> tag should be inside the <head> section):
<head>
<script src="jquery-3.7.1.min.js"></script>
</head>
2 jQuery CDN
If you don't want to download and host jQuery yourself, you can include it from a CDN
(Content Delivery Network).Google is an example of someone who host jQuery:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
jQuery Syntax
The jQuery syntax is tailor-made for selecting HTML elements and performing some action on
the element(s).
50
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
jQuery Selectors
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the #id selector when you want to find
a single, unique element.
To find an element with a specific id, write a hash character, followed by the id of the HTML
element:
Example:
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
51
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
All the different visitors' actions that a web page can respond to are called events.
Examples:
clicking on an element
$("p").click();
The next step is to define what should happen when the event fires. You must pass a function
to the event:
$("p").click(function(){
// action goes here!!
});
52
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
The function is executed when the user clicks on the HTML element.
The following example says: When a click event fires on a <p> element; hide the
current <p> element:
Example
$("p").click(function(){
$(this).hide();
});
2 dblclick()
The function is executed when the user double-clicks on the HTML element:
Example
$("p").dblclick(function(){
$(this).hide();
});
3 mouseenter()
The function is executed when the mouse pointer enters the HTML element:
Example
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
53
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
4 mouseleave()
The function is executed when the mouse pointer leaves the HTML element:
Example
$("#p1").mouseleave(function(){
alert("Bye! You now leave p1!");
});
5 mousedown()
The function is executed, when the left, middle or right mouse button is pressed down, while
the mouse is over the HTML element:
Example
$("#p1").mousedown(function(){
alert("Mouse down over p1!");
});
6 mouseup()
The function is executed, when the left, middle or right mouse button is released, while the
mouse is over the HTML element:
Example
$("#p1").mouseup(function(){
alert("Mouse up over p1!");
});
7 hover()
54
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
The first function is executed when the mouse enters the HTML element, and the second
function is executed when the mouse leaves the HTML element:
Example
$("#p1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});
8 focus()
The focus() method attaches an event handler function to an HTML form field.
Example
$("input").focus(function(){
$(this).css("background-color", "#cccccc");
});
9 blur()
The blur() method attaches an event handler function to an HTML form field.
Example
$("input").blur(function(){
$(this).css("background-color", "#ffffff");
});
The on() method attaches one or more event handlers for the selected elements.
55
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Example
$("p").on("click", function(){
$(this).hide();
});
56
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
57
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
58
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
A Web API (Application Programming Interface) is a set of protocols and tools for building
software applications. Specifically, a web API is a type of API that is accessed through the
internet, typically using HTTP requests. Web APIs allow developers to interact with remote
systems or services over the internet, and to access and manipulate data that is stored on those
systems. For instance, a web API might allow a developer to access information about a user’s
social media profile, or to retrieve data from a remote database.
Browser API’s
All browsers have a set of built-in Web APIs to support complex operations, and to help
accessing data.
For example, the Geolocation API can return the coordinates of where the browser is located.
59
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
Fig 2.6.2 Uploading YouTube video and google maps using Third party API
JavaScript validation API
60
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
The window.history object contains the URLs (Web Sites) visited by the user.
The back() method loads the previous URL in the windows.history list.
61
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
The localStorage object provides access to a local storage for a particular Web Site. It allows
you to store, read, add, modify, and delete data items for that domain.
The data is stored with no expiration date, and will not be deleted when the browser is closed.
When executing scripts in an HTML page, the page becomes unresponsive until the script is
finished.
A web worker is a JavaScript that runs in the background, independently of other scripts,
without affecting the performance of the page. You can continue to do whatever you want:
clicking, selecting things, etc., while the web worker runs in the back
62
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
63
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
PHP, which stands for "Hypertext Preprocessor," is a widely used server-side scripting
language designed for web development. It is an open-source language, and it is embedded
within HTML to create dynamic web pages. PHP is known for its simplicity, versatility, and
powerful features, making it a preferred choice for building web applications and websites.
Here's an overview of PHP and its basic syntax:
1. PHP Tags: PHP code is embedded within HTML using special tags. The most common way
to enclose PHP code is with `<?php` to start and `?>` to end. For example:
php
<?php
?>
Alternatively, short tags `<?` and `?>` can be used but are less recommended due to
compatibility
concerns.
php
3. Variables: PHP variables are declared with a dollar sign (`$`) followed by the variable name.
php
$name = "John";
$age = 30;
64
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
4. Data Types: PHP supports various data types, including strings, numbers, Booleans, arrays,
and objects. Data types are dynamically determined based on the assigned value.
php
$number = 42;
$isTrue = true;
5. Operators: PHP supports a wide range of operators, including arithmetic, comparison, and
logical operators. For example, `+`, `-`, `==`, `!=`, `&&`, and `||`.
php
$x = 5;
$y = 3;
6. Conditional Statements: PHP allows you to use conditional statements like `if`, `else`, and
php
} else {
7. Loops: You can create loops using `for`, `while`, and `foreach` to iterate over arrays, execute
php
65
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
echo $i;
8. Functions: Functions are reusable blocks of code that perform specific tasks. You can create
php
function greet($name) {
greet("John");
9. Include and Require: PHP allows you to include external files using `include` and `require`.
php
PHP is a versatile language used for web development, offering support for databases, session
management, and interacting with web servers. It is widely used for creating dynamic websites
and web applications, and it can be seamlessly integrated with HTML to build interactive and
data-driven web solutions.
In PHP, code blocks are sections of code enclosed within PHP tags (`<?php` and `?>`). Code
blocks allow you to execute PHP code within an HTML or text document. Here's how PHP
code blocks work, including examples of using strings within code blocks:
To create a code block in PHP, you use the opening `<?php` tag to start the block and the
66
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
closing `?>` tag to end it. Everything between these tags is considered PHP code and is
php
<?php
?>
Strings are a common data type in PHP used to store and manipulate text. You can work
You can declare strings by enclosing text within single quotes (`'`) or double quotes (`"`).
php
67
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
68
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
CHAPTER 3
Hackathon
Problem Statement:
Objectives
1. Transparency: Blockchain's public ledger allows for all transactions to be visible and
verifiable by all participants, reducing the likelihood of tampering and increasing transparency
in the voting process.
2. Security: Blockchain technology uses cryptographic methods to secure data. This helps
to protect votes from being altered or falsified, ensuring that the integrity of the voting process
is maintained.
4. Anonymity: Blockchain can provide privacy for voters by using cryptographic techniques
to anonymize their identities while still allowing votes to be counted accurately.
6. Efficiency: Blockchain can streamline the voting process by automating vote counting
and results reporting, which can reduce the time and costs associated with traditional voting
methods.
69
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
3.2 Execution
Backend
App.py
import time
import json
from hashlib import sha256
class Block:
def __init__(self, index, votes, timestamp, previous_hash):
self.index = index
self.votes = votes
self.timestamp = timestamp
self.previous_hash = previous_hash
self.nonce = 0
def compute_hash(self):
block_string = json.dumps(self.__dict__, sort_keys=True)
return sha256(block_string.encode()).hexdigest()
class Blockchain:
difficulty = 2
def __init__(self):
self.unconfirmed_votes = []
self.chain = []
self.create_genesis_block()
def create_genesis_block(self):
genesis_block = Block(0, [], time.time(), "0")
genesis_block.hash = genesis_block.compute_hash()
self.chain.append(genesis_block)
@property
def last_block(self):
return self.chain[-1]
def proof_of_work(self, block):
70
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
block.nonce = 0
computed_hash = block.compute_hash()
while not computed_hash.startswith('0' * Blockchain.difficulty):
block.nonce += 1
computed_hash = block.compute_hash()
return computed_hash
def add_block(self, block, proof):
previous_hash = self.last_block.hash
if previous_hash != block.previous_hash:
return False
if not Blockchain.is_valid_proof(block, proof):
return False
block.hash = proof
self.chain.append(block)
return True
@staticmethod
def is_valid_proof(block, block_hash):
return (block_hash.startswith('0' * Blockchain.difficulty) and block_hash ==
block.compute_hash())
def add_new_vote(self, vote):
self.unconfirmed_votes.append(vote)
def mine(self):
if not self.unconfirmed_votes:
return False
last_block = self.last_block
new_block = Block(index=last_block.index + 1,
votes=self.unconfirmed_votes,
timestamp=time.time(),
previous_hash=last_block.hash)
proof = self.proof_of_work(new_block)
self.add_block(new_block, proof)
71
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
self.unconfirmed_votes = []
return new_block.index
from flask import Flask, request, redirect, render_template, jsonify
import requests
import json
app = Flask(__name__)
# Initialize the Blockchain
blockchain = Blockchain()
@app.route('/new_vote', methods=['POST'])
def new_vote():
vote_data = request.get_json()
required_fields = ['voter_id', 'candidate']
for field in required_fields:
if not vote_data.get(field):
return "Invalid vote data", 404
vote_data['timestamp'] = time.time()
blockchain.add_new_vote(vote_data)
return jsonify({"message": "Vote successfully added to the pool"}), 201
@app.route('/chain', methods=['GET'])
def get_chain():
chain_data = []
for block in blockchain.chain:
chain_data.append(block.__dict__)
return json.dumps({"length": len(chain_data), "chain": chain_data})
@app.route('/mine', methods=['GET'])
def mine_unconfirmed_votes():
result = blockchain.mine()
if not result:
return "No votes to mine"
return f"Block #{result} is mined."
72
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
@app.route('/pending_votes', methods=['GET'])
def get_pending_votes():
return json.dumps(blockchain.unconfirmed_votes)
@app.route('/')
def index():
return render_template('index.html', posts=blockchain.chain)
@app.route('/submit_vote', methods=['POST'])
def submit_vote():
voter_id = request.form['voter_id']
candidate = request.form['candidate']
vote_object = {
'voter_id': voter_id,
'candidate': candidate
}
# Submit a vote
new_vote_address = "{}/new_vote".format("http://127.0.0.1:8000")
try:
response = requests.post(new_vote_address, json=vote_object, headers={'Content-type':
'application/json'})
response_data = response.json()
message = response_data.get('message', 'Vote failed')
except requests.exceptions.RequestException as e:
# Handle request exceptions
message = f"An error occurred: {e}"
# Redirect to the result page to show the vote details
return
redirect(f'/result?voter_id={voter_id}&candidate={candidate}&message={message}')
@app.route('/result', methods=['GET'])
def result():
voter_id = request.args.get('voter_id')
73
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
candidate = request.args.get('candidate')
message = request.args.get('message')
return render_template('result.html', voter_id=voter_id, candidate=candidate,
message=message)
if __name__ == "__main__":
app.run(debug=True, port=8000)
Frontend
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Online Voting</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
<script src="{{ url_for('static', filename='scripts.js') }}" defer></script>
</head>
<body>
<header>
<div class="container">
<h1>Online Voting System</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/pending_votes">Pending Votes</a></li>
<li><a href="/chain">Blockchain</a></li>
<li><a href="/mine">Mine Votes</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<h2>Submit a Vote</h2>
74
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
75
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
<div class="container">
<h1>Vote Result</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/pending_votes">Pending Votes</a></li>
<li><a href="/chain">Blockchain</a></li>
<li><a href="/mine">Mine Votes</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<h2>Vote Result</h2>
<p><strong>Voter ID:</strong> {{ voter_id }}</p>
<p><strong>Candidate:</strong> {{ candidate }}</p>
<p>{{ message }}</p>
<a href="/">Go Back</a>
</main>
</body>
</html>
Script.js
document.addEventListener('DOMContentLoaded', () => {
// Example of dynamic behavior (e.g., form validation)
const form = document.querySelector('form');
if (form) {
form.addEventListener('submit', (event) => {
const voterId = document.querySelector('input[name="voter_id"]').value;
const candidate = document.querySelector('input[name="candidate"]').value;
if (!voterId || !candidate) {
76
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
77
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
header h1 {
text-align: center;
margin: 0;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline;
margin: 0 10px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
main {
padding: 20px;
background: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
form {
margin: 20px 0;
}
form input[type="text"] {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
width: calc(100% - 22px);
78
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
margin-bottom: 10px;
}
form input[type="submit"] {
background: #333;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
form input[type="submit"]:hover {
background: #555;
}
ul {
list-style: none;
}
li {
background: #fff;
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
a{
color: #333;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
79
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
OUTPUT
Open project directory in command prompt and run python app.py
80
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
81
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
82
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
CERTIFICATIONS
Blockchain in depth:
83
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
JavaScript:
84
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
85
B.E/Dept. of AIML/BNMIT 2024-2025
Internship on Blockchain technology and Web Technology
86
B.E/Dept. of AIML/BNMIT 2024-2025