You are on page 1of 13

Q. Explain different types of Blockchain.

There are 4 types of blockchain:


1. Public Blockchain.
2. Private Blockchain.
3. Hybrid Blockchain.
4. Consortium Blockchain.

1. Public Blockchain
These blockchains are completely open to following the idea of decentralization. They don’t
have any restrictions, anyone having a computer and internet can participate in the network.
• As the name is public this blockchain is open to the public, which means it is not owned
by anyone.
• Anyone having internet and a computer with good hardware can participate in this
public blockchain.
• All the computer in the network hold the copy of other nodes or block present in the
network
• In this public blockchain, we can also perform verification of transactions or records
Advantages:
• Trustable: There are algorithms to detect no fraud. Participants need not worry about
the other nodes in the network
• Secure: This blockchain is large in size as it is open to the public. In a large size, there
is greater distribution of records
• Anonymous Nature: It is a secure platform to make your transaction properly at the
same time, you are not required to reveal your name and identity in order to participate.
• Decentralized: There is no single platform that maintains the network, instead every
user has a copy of the ledger.
Disadvantages:
• Processing: The rate of the transaction process is very slow, due to its large size.
Verification of each node is a very time-consuming process.
• Energy Consumption: Proof of work is high energy-consuming. It requires good
computer hardware to participate in the network
• Acceptance: No central authority is there so governments are facing the issue to
implement the technology faster.
Use Cases: Public Blockchain is secured with proof of work or proof of stake they can be used
to displace traditional financial systems. The more advanced side of this blockchain is the smart
contract that enabled this blockchain to support decentralization. Examples of public
blockchain are Bitcoin, Ethereum.
2. Private Blockchain
These blockchains are not as decentralized as the public blockchain only selected nodes can
participate in the process, making it more secure than the others.
• These are not as open as a public blockchain.
• They are open to some authorized users only.
• These blockchains are operated in a closed network.
• In this few people are allowed to participate in a network within a
company/organization.
Advantages:
• Speed: The rate of the transaction is high, due to its small size. Verification of each
node is less time-consuming.
• Scalability: We can modify the scalability. The size of the network can be decided
manually.
• Privacy: It has increased the level of privacy for confidentiality reasons as the
businesses required.
• Balanced: It is more balanced as only some user has the access to the transaction which
improves the performance of the network.
Disadvantages:
• Security- The number of nodes in this type is limited so chances of manipulation are
there. These blockchains are more vulnerable.
• Centralized- Trust building is one of the main disadvantages due to its central nature.
Organizations can use this for malpractices.
• Count- Since there are few nodes if nodes go offline the entire system of blockchain
can be endangered.
Use Cases: With proper security and maintenance, this blockchain is a great asset to secure
information without exposing it to the public eye. Therefore companies use them for internal
auditing, voting, and asset management. An example of private blockchains is Hyperledger,
Corda.
3. Hybrid Blockchain
It is the mixed content of the private and public blockchain, where some part is controlled by
some organization and other makes are made visible as a public blockchain.
• It is a combination of both public and private blockchain.
• Permission-based and permissionless systems are used.
• User access information via smart contracts
• Even a primary entity owns a hybrid blockchain it cannot alter the transaction
Advantages:
• Ecosystem: Most advantageous thing about this blockchain is its hybrid nature. It
cannot be hacked as 51% of users don’t have access to the network.
• Cost: Transactions are cheap as only a few nodes verify the transaction. All the nodes
don’t carry the verification hence less computational cost.
• Architecture: It is highly customizable and still maintains integrity, security, and
transparency.
• Operations: It can choose the participants in the blockchain and decide which
transaction can be made public.
Disadvantages:
• Efficiency: Not everyone is in the position to implement a hybrid Blockchain. The
organization also faces some difficulty in terms of efficiency in maintenance.
• Transparency: There is a possibility that someone can hide information from the user.
If someone wants to get access through a hybrid blockchain it depends on the
organization whether they will give or not.
• Ecosystem: Due to its closed ecosystem this blockchain lacks the incentives for
network participation.
Use Case: It provides a greater solution to the health care industry, government, real estate,
and financial companies. It provides a remedy where data is to be accessed publicly but needs
to be shielded privately. Examples of Hybrid Blockchain are Ripple network and XRP token.
4. Consortium Blockchain
It is a creative approach that solves the needs of the organization. This blockchain validates the
transaction and also initiates or receives transactions.
• Also known as Federated Blockchain.
• This is an innovative method to solve the organization’s needs.
• Some part is public and some part is private.
• In this type, more than one organization manages the blockchain.
Advantages:
• Speed: A limited number of users make verification fast. The high speed makes this
more usable for organizations.
• Authority: Multiple organizations can take part and make it decentralized at every
level. Decentralized authority, makes it more secure.
• Privacy: The information of the checked blocks is unknown to the public view. but any
member belonging to the blockchain can access it.
• Flexible: There is much divergence in the flexibility of the blockchain. Since it is not
a very large decision can be taken faster.
Disadvantages:
• Approval: All the members approve the protocol making it less flexible. Since one or
more organizations are involved there can be differences in the vision of interest.
• Transparency: It can be hacked if the organization becomes corrupt. Organizations
may hide information from the users.
• Vulnerability: If few nodes are getting compromised there is a greater chance of
vulnerability in this blockchain
Use Cases: It has high potential in businesses, banks, and other payment processors. Food
tracking of the organizations frequently collaborates with their sectors making it a federated
solution ideal for their use. Examples of consortium Blockchain are Tendermint and
Multichain.

Q. Explain the different types of Cryptocurrency wallets.


1. Software Wallets: These wallets are applications that you install on your computer or
mobile device. They can be further categorized into:

a. Desktop wallets: Installed on your computer and provide full control over your
private
keys. Examples include Electrum, Exodus, and Atomic Wallet.

b. Mobile wallets: Installed on your smartphone or tablet, offering convenience


and
portability. Examples include Trust Wallet, Coinbase Wallet, and Mycelium.

2. Online Wallets: These wallets are web-based and accessible through a browser. They
are convenient but come with the risk of being hacked. Examples include MetaMask,
MyEtherWallet, and Binance Wallet.

3. Hardware Wallets: These are physical devices designed specifically for storing
cryptocurrencies securely. They generate and store your private keys offline. Examples
include Ledger, Trezor, and KeepKey. Hardware wallets are considered one of the most
secure options.

4. Paper Wallets: These wallets involve printing your public and private keys on a
physical piece of paper. They are offline and immune to hacking but require careful
handling to avoid loss, damage, or theft.

Q. Explain different layers of Blockchain with diagram.


1. Hardware/Infrastructure layer: This layer includes the physical components of
the blockchain network, such as computers, data centers, and storage devices. The
hardware layer must be secure and reliable in order to protect the data of the
blockchain network.
2. Data layer: This layer stores the data of the blockchain, such as transactions,
blocks, and smart contracts. The data layer must be immutable and tamper-proof in
order to ensure the security of the blockchain network.
3. Network layer: This layer allows the nodes of the blockchain network to
communicate with each other. The network layer must be secure and efficient in
order to ensure the availability of the blockchain network.
4. Consensus layer: This layer ensures that all nodes of the blockchain network agree
on the state of the ledger. The consensus layer must be secure and scalable in order
to ensure the efficiency of the blockchain network.
5. Application layer: This layer provides the functionality for applications to interact
with the blockchain network. The application layer must be secure and user-friendly
in order to encourage the adoption of blockchain technology.

Q. What is double Spending problem? How PoW solves the problem of double spending?
Double Spending Problem:
The double spending problem is a challenge in digital currencies and electronic payment
systems, particularly when dealing with digital assets like cryptocurrencies. It refers to the risk
of spending the same digital currency unit more than once, essentially counterfeiting the
currency. In a physical cash system, this is not an issue because when you give someone a
dollar bill, you can't simultaneously give the same bill to someone else. However, in digital
transactions, there's no physical representation of money, making it possible for someone to
copy and spend the same digital currency multiple times.

How Proof of Work (PoW) Solves the Double Spending Problem:


Proof of Work is a consensus mechanism used in blockchain networks, including Bitcoin. It
solves the double spending problem through a combination of cryptographic techniques,
distributed consensus, and computational effort. Here's how PoW addresses the issue:
1. Transaction Verification: When a user initiates a cryptocurrency transaction (e.g., sending
Bitcoin to someone), the transaction is broadcast to the network for verification.
2. Transaction Pool: Unconfirmed transactions are collected in a pool called the "mempool"
before being added to a block.
3. Mining Process: Miners, who are participants in the network, compete to solve a complex
mathematical puzzle associated with the pending transactions. This process is resource-
intensive and requires significant computational power.
4. Block Creation: The first miner to successfully solve the puzzle gets to create a new block
of transactions, including the one involving the user's cryptocurrency transfer.
5. Consensus and Validation: Other nodes in the network verify the solution and the
transactions in the newly created block. They ensure that the sender of the cryptocurrency
indeed has the required amount in their wallet and has not spent it before.
6. Proof of Validity: Once a transaction is included in a block and the block is added to the
blockchain, it becomes a part of the immutable ledger. This transaction now has cryptographic
proof that it has been validated and confirmed by the network.
7. Incentive Structure: Miners are incentivized to play by the rules because they invest
significant computational resources (and electricity) in the mining process. Attempting double
spending by creating fraudulent transactions would be computationally expensive and is highly
unlikely to succeed.
8. Network Agreement: The decentralized nature of blockchain networks and the consensus
mechanism ensure that all participants agree on the state of the ledger. Any attempt to double
spend would require a malicious actor to control the majority of the network's computational
power, which is extremely difficult and costly.

Write a short note:


1. PoW
2. PoS
3. DPoS
4. PoET

Proof of Work (PoW):


1. Operation: PoW is the original consensus mechanism used in cryptocurrencies like Bitcoin.
It relies on miners who compete to solve complex mathematical puzzles through brute-force
computation. These puzzles are known as "hash functions," and the first miner to find a solution
that meets specific criteria gets the right to create a new block of transactions and is rewarded
with cryptocurrency.
2. Security: PoW is renowned for its high level of security. To tamper with the blockchain, an
attacker would need to control more than 50% of the network's computational power, which is
often referred to as a "51% attack." This is considered highly improbable and expensive.
3. Energy Consumption: One major drawback of PoW is its significant energy consumption.
Mining involves running powerful computers 24/7 to compete for block rewards, leading to a
substantial carbon footprint and energy expenditure.

Proof of Stake (PoS):


1. Operation: PoS is an alternative to PoW. In PoS networks, miners are replaced by validators
who are chosen to create new blocks and validate transactions based on the amount of
cryptocurrency they "stake" as collateral. Validators with a higher stake have a better chance
of being selected.
2. Energy Efficiency: PoS is more energy-efficient compared to PoW because it doesn't
involve resource-intensive mining processes. Validators are chosen based on their holdings
rather than computational power, making it a more environmentally friendly option.
3. Security: PoS maintains security through economic incentives. Validators have a financial
interest in maintaining the integrity of the network because they have staked their own
cryptocurrency as collateral. If they act maliciously, they risk losing their staked coins.

Delegated Proof of Stake (DPoS):


1. Operation: DPoS is a variation of PoS. In DPoS networks, token holders vote to elect a
limited number of delegates (validators) who have the authority to produce blocks and validate
transactions. DPoS is designed to improve scalability and transaction confirmation times by
reducing the number of validators.
2. Efficiency: DPoS is known for its efficiency and fast transaction processing. Delegates are
elected by the community, and they take turns validating transactions, reducing the need for
every node to validate every transaction. This makes DPoS suitable for networks with high
transaction volumes.
3. Centralization Concerns: Some critics argue that DPoS can lead to centralization because
a small number of delegates have significant power. However, proponents believe that the
democratic voting process mitigates this concern, and DPoS can strike a balance between
efficiency and decentralization.

Proof of Elapsed Time (PoET):


1. Operation: PoET is a consensus mechanism designed by Intel. In PoET, participants in a
distributed network wait for a randomly chosen period (elapsed time) before they can create
blocks or perform certain actions. The randomness ensures fairness and prevents any single
participant from gaining an unfair advantage.
2. Use Cases: PoET is often used in permissioned or private blockchain networks where
participants are known and trusted. It ensures that no participant can dominate the network due
to computational power or stake.
3. Security and Fairness: PoET aims to provide both security and fairness by using a random
timer. It's a more lightweight consensus mechanism compared to PoW and PoS, making it
suitable for networks where energy efficiency and trust among participants are priorities.

Write a smart contract on Lottery system


//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
contract Lottery{
address payable[] public players;
address public manager;
constructor(){
manager = msg.sender;
}
receive () payable external{
require(msg.value >= 2 ether);
players.push(payable(msg.sender));
}
function getBalance() public view returns(uint){
require(msg.sender == manager);
return address(this).balance;
}
function random() internal view returns(uint){
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp,
players.length)));
}
function pickWinner() public{
require(msg.sender == manager);
require (players.length >= 3);
uint r = random();
address payable winner;
uint index = r % players.length;
winner = players[index];
winner.transfer(getBalance());
players = new address payable[](0);
}
}

Write a smart contract on Event Organization.


//SPDX-License-Identifier: Unlicense
pragma solidity >=0.5.0 <0.9.0;
contract EventContract {
struct Event{
address organizer;
string name;
uint date; //0 1 2
uint price;
uint ticketCount; //1 sec 0.5 sec
uint ticketRemain;
}
mapping(uint=>Event) public events;
mapping(address=>mapping(uint=>uint)) public tickets;
uint public nextId;
function createEvent(string memory name,uint date,uint price,uint ticketCount) external{
require(date>block.timestamp,"You can organize event for future date");
require(ticketCount>0,"You can organize event only if you create more than 0 tickets");
events[nextId] = Event(msg.sender,name,date,price,ticketCount,ticketCount);
nextId++;
}
function buyTicket(uint id,uint quantity) external payable{
require(events[id].date!=0,"Event does not exist");
require(events[id].date>block.timestamp,"Event has already occured");
Event storage _event = events[id];
require(msg.value==(_event.price*quantity),"Ethere is not enough");
require(_event.ticketRemain>=quantity,"Not enough tickets");
_event.ticketRemain-=quantity;
tickets[msg.sender][id]+=quantity;
}
function transferTicket(uint id,uint quantity,address to) external{
require(events[id].date!=0,"Event does not exist");
require(events[id].date>block.timestamp,"Event has already occured");
require(tickets[msg.sender][id]>=quantity,"You do not have enough tickets");
tickets[msg.sender][id]-=quantity;
tickets[to][id]+=quantity;
}
}

Write a smart contract on Crowdfunding.


// SPDX-License-Identifier: MIT
pragma solidity >=0.4.16 <0.9.0;
contract CrowdFunding{
mapping(address=>uint) public contributors; //contributors[msg.sender]=100
address public manager;
uint public minimumContribution;
uint public deadline;
uint public target;
uint public raisedAmount;
uint public noOfContributors;
struct Request{
string description;
address payable recipient;
uint value;
bool completed;
uint noOfVoters;
mapping(address=>bool) voters;
}
mapping(uint=>Request) public requests;
uint public numRequests;

constructor(uint _target,uint _deadline){


target=_target;
deadline=block.timestamp+_deadline; //10sec + 3600sec (60*60)
minimumContribution=100 wei;
manager=msg.sender;
}

function sendEth() public payable{


require(block.timestamp < deadline,"Deadline has passed");
require(msg.value >=minimumContribution,"Minimum Contribution is not met");

if(contributors[msg.sender]==0){
noOfContributors++;
}
contributors[msg.sender]+=msg.value;
raisedAmount+=msg.value;
}
function getContractBalance() public view returns(uint){
return address(this).balance;
}
function refund() public{
require(block.timestamp>deadline && raisedAmount<target,"You are not eligible for
refund");
require(contributors[msg.sender]>0);
address payable user=payable(msg.sender);
user.transfer(contributors[msg.sender]);
contributors[msg.sender]=0;

}
modifier onlyManger(){
require(msg.sender==manager,"Only manager can calll this function");
_;
}
function createRequests(string memory _description,address payable _recipient,uint _value)
public onlyManger{
Request storage newRequest = requests[numRequests];
numRequests++;
newRequest.description=_description;
newRequest.recipient=_recipient;
newRequest.value=_value;
newRequest.completed=false;
newRequest.noOfVoters=0;
}
function voteRequest(uint _requestNo) public{
require(contributors[msg.sender]>0,"YOu must be contributor");
Request storage thisRequest=requests[_requestNo];
require(thisRequest.voters[msg.sender]==false,"You have already voted");
thisRequest.voters[msg.sender]=true;
thisRequest.noOfVoters++;
}
function makePayment(uint _requestNo) public onlyManger{
require(raisedAmount>=target);
Request storage thisRequest=requests[_requestNo];
require(thisRequest.completed==false,"The request has been completed");
require(thisRequest.noOfVoters > noOfContributors/2,"Majority does not support");
thisRequest.recipient.transfer(thisRequest.value);
thisRequest.completed=true;
}
}

Write a smart contract on Banking Transaction.


// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract DBank
{
address Owner;

// We are creating the Mapping for the Adding & Transfer Amount in Account
mapping(address=>uint)Balance;

// constructor for the address of the Owner


constructor()
{
Owner = msg.sender;
}

// function for adding the Ethereum in Account


function addBalance(uint amount) public returns(uint)
{
// first we have to check the is it Owners Account or Not
require(msg.sender == Owner, "Yes it is Owner Account !!");
Balance[msg.sender] = Balance[msg.sender] + amount;

return Balance[msg.sender];
}

// function for Get the Balance from an Account


function getBalance() public view returns(uint)
{
return Balance[msg.sender];
}

// to transfer the Amount from Owner to Recipient


function Transfer(address recipient, uint amount) public
{
// check the Self account is or not
require(msg.sender != recipient, "Can't Transfer !! Self Account.");

// check the owner has balance is available or not


require(Balance[msg.sender] >= amount, "No, We Can't Transfer. Insufficient Balance
!!");

_transfer(msg.sender, recipient, amount);


}

function _transfer(address From, address To, uint Amount) private


{
Balance[From] = Balance[From] - Amount;
Balance[To] = Balance[To] + Amount;
}

}
Write a program in solidity to implement multi-level inheritance.
// Solidity program to
// demonstrate Multi-Level
// Inheritance
pragma solidity >=0.4.22 <0.6.0;

// Defining parent contract A


contract A {

// Declaring state variables


string internal x;
string a = "Geeks" ;
string b = "For";

// Defining external function


// to return concatenated string
function getA() external{
x = string(abi.encodePacked(a, b));
}
}

// Defining child contract B


// inheriting parent contract A
contract B is A {

// Declaring state variables


// of child contract B
string public y;
string c = "Geeks";

// Defining external function to


// return concatenated string
function getB() external payable returns(
string memory){
y = string(abi.encodePacked(x, c));
}
}

// Defining child contract C


// inheriting parent contract A
contract C is B {

// Defining external function


// returning concatenated string
// generated in child contract B
function getC() external view returns(
string memory){
return y;
}
}

// Defining calling contract


contract caller {

// Creating object of child C


C cc = new C();

// Defining public function to


// return final concatenated string
function testInheritance(
) public returns (
string memory) {
cc.getA();
cc.getB();
return cc.getC();
}
}

You might also like