0% found this document useful (0 votes)
4 views

Final-soc-Ethereum-G5111

hgn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Final-soc-Ethereum-G5111

hgn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES

(Autonomous)

(Accredited by NAAC with Grade “A” and Affiliated to JNTUK-Kakinada)


Vinjanampadu, Vatticherukuru Mandal, Guntur,A.P.-522017.

REPORT ON
ADVANCED SKILL ORIENTED COURSE

Name : NURBASHA NAGABABU

Roll. No : 21JR1A12G5

Course Name : ETHEREUM ( 20IT7S01 )


Year : IV Semester : I

Department
Of
Information Technology

1
KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES
(Autonomous)
(Accredited by NAAC with Grade “A” and Affiliated to JNTUK-Kakinada)
Vinjanampadu, Vatticherukuru Mandal, Guntur,A.P.-522017

CERTIFICATE

Certified that this is the bonafide record of practical work done by


NURBASHA NAGABABU a student of Information Technology Department
with Reg.No. 21JR1A12G5 in the Advanced Skill oriented course on
ETHEREUM ( 20IT7S01 ) during the academic year 2024-25.

Signature Signature
Faculty In charge Head of the
Department

Submitted for the practical examination held on……………….

Examiner

2
(Place your certificate here……………..)

KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES


(Autonomous)
(Approved by A.I.C.T.E New Delhi || Permanently Affiliated to JNTUK, Kakinada || Accredited with ‘A’ Grade by NAAC )

3
Vinjanampadu (V), Vatticherukuru (M), Guntur (DT), A.P-522017

DEPARTMENT OF INFORMATION TECHNOLOGY

DECLARATION

We hereby inform that this Skill Oriented Course on “Ethereum”


has been carried out by myself in the duration of 8th to 13th July 2024
with Make Skilled, Hyderabad and submitted in partial fulfilment
for the award to the degree of Bachelor of Technology in
Information Technology.to Jawaharlal Nehru Technological
University Kakinada under the guidance of N.M.V. Nirmala,
Asst.Prof, Dept. of Information Technology.

NURBASHA NAGABABU
(21JR1A12G5)

KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES


(Autonomous)
4
(Approved by A.I.C.T.E New Delhi || Permanently Affiliated to JNTUK, Kakinada || Accredited with ‘A’ Grade by NAAC )
Vinjanampadu (V), Vatticherukuru (M), Guntur (DT), A.P-522017

DEPARTMENT OF INFORMATION TECHNOLOGY

ACKNOWLEDGEMENT

We would like to express our profound gratitude towards Mrs.N.M.V


Nirmala, Asst. Prof, Department of IT, who played a supervisory role to
utmost perfection for guiding as an internal guide methodically and
meticulously.

We are highly indebted to Dr. M. Srinivasa Sesha Sai, Head of the


Department, Information Technology. for providing us all the necessary
support.

We are very much thankful to the college management for their continuous
support and facilities provided.

We render our deep sense of gratitude to Dr. P. BABU, Principal & Dr. K
Hari Babu, Academic Director, for permitting us to carry out Skill Oriented
course ETHEREUM. We would like to express our sincere thanks to Information
Technology. staff for lending us their time to help us and complete the work
successfully.

We would also like to thank our staff, parents and friends for their enduring
encouragement and assistance whenever required.

NURBASHA
NAGABABU
(21JR1A12G5)

5
KKR & KSR INSTITUTE OF TECHNOLOGY AND SCIENCES
(Autonomous)

(Accredited by NAAC with Grade “A” and Affiliated to JNTUK-Kakinada)


Vinjanampadu, Vatticherukuru Mandal, Guntur, A.P.-522017.
College Vision and Missions
Vision:
To produce eminent and ethical Engineers and Managers for society by
Imparting quality professional education with emphasis on human
values and holistic excellence.

Mission:
 To incorporate benchmarked teaching and learning pedagogies in
curriculum.
 To ensure all round development of students through judicious
blend of curricular, co-curricular and extra-curricular activities.

Department Vision and Missions


Vision:
To produce competent professionals in the field of Information
Technology to meet the global needs of industry and society.

Mission:
 Strengthen the Core Competence through the state-of-the-art
concepts in a congenial Environment.
 Promote innovation research and development for the application
of IT to the Economic, Social and Environmental users.
 Inculcate professional behaviour, lifelong learning and strong
ethical values to meet the challenges in Information Technology.
 Establish centers of excellence in leading area of Information
Technology.

6
7
List of Experiments
SLNo Name of Experiment Page no
1 Create a simple solidity contract that prints “Hello world”. 6
2 Develop a basic ERC-20 token smart contract, including 7 - 8
functions for transfer, balance, and approval.
3 Design a simple ICO contract that allows users to buy 9 - 10
tokens and the owner to withdraw funds.
4 Build a voting contract where users can submit and vote on 11 - 12
proposals , implements safeguards to prevent double
voting.
5 Create a escrow smart contract that holds funds until 13 - 14
predefined conditions are met.
6 Construct a wallet contract that allows funds to be locked 15 -16
until a specified time.
7 Implement a multi-signature wallet that requires multiple 17 - 18
parties to approve transactions.
8 Deasign a simplified decentralized exchange where users 19- 20
can trade tokens.
9 Create a basic NFT contract ,allowing the minting and 21 - 22
transferring of unique tokens.
10 Develop a lottery contract with an entry fee and 23 - 24
randomized winner selection.
11 Build a supply chain contract that tracks the movement of 25 - 26
goods from producer to consumer.
12 Build a contract that verifies user identify using KYC 27 - 28
principles.
13 Develop a contract for subscription-based services , 29 - 30
enabling users to pay on a recurring basis.
14 Design a contract that allows users to stake tokens in 31 - 32
returns for rewards.
15 Design a contract that allows users to purchase pets from 33 - 34
the shop.

8
Activity - 1
Problem Statement: Hello World Contract

Create a simple Solidity smart contract that prints "Hello,


World!"

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
string public greeting = "Hello, World!";

function getGreeting() public view returns (string memory) {


return greeting;
}
}

Output:

9
Activity - 2
Problem Statement: Token Creation

Develop a basic ERC-20 token smart contract, including functions for


transfer, balance, and approval.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleToken { string


public name = "Simple Token";
string public symbol = "ST";
uint8 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf; event

Transfer(address indexed from, address indexed to, uint256

value);

constructor(uint256 initialSupply) { totalSupply


= initialSupply * 10 ** uint256(decimals);
balanceOf[msg.sender] = totalSupply;
}

function transfer(address to, uint256 value) public returns (bool success) {


require(to != address(0), "Invalid address");
require(balanceOf[msg.sender] >= value, "Insufficient balance");

balanceOf[msg.sender] -= value;
balanceOf[to] += value;

emit Transfer(msg.sender, to, value);


return true;
}
}

10
Output :

11
12
Activity - 3
Problem Statement: ICO Crowdsale

Design a simple ICO (Initial Coin Offering) contract that allows users to
buy tokens and the owner to withdraw funds.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleICO
{ address public
owner; uint256 public
tokenPrice; uint256
public totalTokens;
uint256 public
tokensSold;
mapping(address => uint256) public balances;

event TokensPurchased(address indexed buyer, uint256


amount); event FundsWithdrawn(address owner, uint256
amount);

constructor(uint256 _tokenPrice, uint256


_totalTokens) { owner = msg.sender;
tokenPrice = _tokenPrice; totalTokens =
_totalTokens; tokensSold = 0;
}

function buyTokens(address buyer, uint256 value) public


{ require(tokensSold + value / tokenPrice <= totalTokens, "Not
enough tokens
available"); uint256 numberOfTokens = value
/ tokenPrice; balances[buyer] +=
numberOfTokens; tokensSold +=
numberOfTokens;
emit TokensPurchased(buyer, numberOfTokens);
}

function withdrawFunds() public { require(msg.sender ==


owner, "Only the owner can withdraw funds"); uint256

13
balance = address(this).balance;
payable(owner).transfer(balance);
emit FundsWithdrawn(owner, balance);
}
}

14
Activity - 4
Problem Statement: Voting Contract

Build a voting contract where users can submit and vote on proposals.
Implement safeguards to prevent double voting.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleVoting { mapping(address


=> bool) public hasVoted; mapping(string
=> uint256) public proposalVotes; string[]
public proposals;
event Voted(address indexed voter, string proposal);

function addProposal(string memory proposal) public


{ proposals.push(proposal);
}

function vote(string memory proposal) public


{ require(!hasVoted[msg.sender], "You have
already voted."); require(proposalExists(proposal),
"Invalid proposal.");
proposalVotes[proposal]++;
hasVoted[msg.sender] = true;

emit Voted(msg.sender, proposal);


}

function getProposalVotes(string memory proposal) public view returns


(uint256) { return proposalVotes[proposal];
}

function proposalExists(string memory proposal) internal view


returns (bool) { for (uint256 i = 0; i < proposals.length; i++) { if
(keccak256(abi.encodePacked(proposals[i])) ==

15
keccak256(abi.encodePacked(proposal))) {
return true;
}
}
return false;
}
}

16
Activity - 5
Problem Statement: Escrow Contract

Create an escrow smart contract that holds funds until predefined conditions
are met.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract
SimpleEscrow
{ address public
payer; address
public payee;
uint256 public
amount;
bool public released;

event FundsDeposited(address indexed payer, uint256


amount); event FundsReleased(address indexed payee,
uint256 amount);

constructor(address _payee)
{ payer = msg.sender;
payee = _payee;
}

function deposit() public payable { require(msg.sender ==


payer, "Only the payer can deposit funds"); amount +=
msg.value;
emit FundsDeposited(payer, msg.value);
}

17
function release() public { require(msg.sender == payee,
"Only the payee can release funds"); require(amount > 0,
"No funds to release"); require(!released, "Funds already
released");

released = true;
(bool success, ) = payable(payee).call{value: amount}("");
require(success, "Transfer failed");
emit FundsReleased(payee, amount);
}
}

18
Output:

19
Activity - 6
Problem Statement: Wallet Contract

Construct a wallet contract that allows funds to be locked until a


specified time.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract TimelockWallet {
address public owner;
uint256 public
releaseTime;
uint256 public balance;

event FundsDeposited(address indexed from, uint256


amount); event FundsWithdrawn(address indexed to, uint256
amount);

constructor(uint256 _releaseTime)
{ owner = msg.sender;
releaseTime = _releaseTime;
}

modifier onlyOwner() { require(msg.sender == owner, "Only the


owner can perform this action");
_;
}

modifier onlyAfter(uint256 _time) { require(block.timestamp >= _time,


"Action can only be performed after the specified
time");
_;
}

function deposit() public payable { require(msg.value


> 0, "Must send Ether with the deposit"); balance
+= msg.value;
emit FundsDeposited(msg.sender, msg.value);

20
}

function withdraw() public onlyOwner


onlyAfter(releaseTime) { require(balance > 0, "No
funds to withdraw"); uint256 amountToWithdraw =
balance; balance = 0;
(bool success, ) = payable(owner).call{value: amountToWithdraw}("");
require(success, "Transfer failed");
emit FundsWithdrawn(owner, amountToWithdraw);
}
}

Output:

21
Activity - 7
Problem Statement: Multi Signature Wallet

Implement a multi-signature wallet that requires multiple parties to


approve transactions.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract
MultiSigWallet
{ address public
owner; address
public signer1;
address public
signer2; address
public signer3;

event Deposit(address indexed sender, uint256


value); event Transfer(address indexed to, uint256
value);

constructor(address _signer1, address _signer2, address


_signer3) { owner = msg.sender; signer1 = _signer1;
signer2 = _signer2;
signer3 = _signer3;
}

receive() external payable { emit


Deposit(msg.sender,
msg.value);
}

function transfer(address payable to, uint256 value) public


{ require(msg.sender == owner || msg.sender == signer1 ||
msg.sender == signer2 ||

22
msg.sender == signer3, "Not authorized");
require(address(this).balance >= value, "Insufficient
balance");

to.transfer(value);
emit Transfer(to, value);
}
}
Output:

23
Activity - 8
Problem Statement: Decentralised Exchange

Design a simplified decentralised exchange where users can trade


tokens.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleDecentralizedExchange
{ address public owner;
uint256 public tokenBalance;

event TokensPurchased(address indexed buyer, uint256 ethValue, uint256


tokenAmount); event TokensSold(address indexed seller, uint256 ethValue,
uint256 tokenAmount);

constructor()
{ owner =
msg.sender;
}

modifier onlyOwner() { require(msg.sender == owner, "Only the


owner can perform this action"); _;
}

function buyTokens() public payable


{ uint256 ethValue = msg.value;
uint256 tokenAmount = ethValue; // 1 Ether = 1 Token (simplified rate)

24
tokenBalance += tokenAmount;
emit TokensPurchased(msg.sender, ethValue, tokenAmount);
}

function sellTokens(uint256 _tokenAmount) public


{ require(_tokenAmount > 0, "Invalid token amount");
uint256 ethValue = _tokenAmount; // 1 Token = 1 Ether

(simplified rate) require(tokenBalance >= _tokenAmount,

"Insufficient token balance"); tokenBalance -= _tokenAmount;

payable(msg.sender).transfer(ethValue);

emit TokensSold(msg.sender, ethValue, _tokenAmount);


}

function depositTokens(uint256 _tokenAmount) public onlyOwner {


tokenBalance += _tokenAmount;
}

function withdrawTokens(uint256 _tokenAmount) public onlyOwner {


require(tokenBalance >= _tokenAmount, "Insufficient token balance");
tokenBalance -= _tokenAmount;
}

function getContractBalance() public view returns (uint256) {


return address(this).balance;
}

function getContractTokenBalance() public view returns (uint256) {


return tokenBalance;
}
}

Output:

25
Activity - 9
Problem Statement: NFT Contract

Create a basic NFT contract, allowing the minting and transferring of


unique tokens.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BasicNFT
{ string public
name;
string public symbol;

struct Token
{ address owner;
string tokenURI;
}

26
Token[] public tokens;
mapping(uint256 => address) public tokenOwners;

constructor(string memory _name, string memory _symbol) {


name = _name;
symbol = _symbol;
}

function mint(string memory _tokenURI)


public { uint256 tokenId =
tokens.length;
tokens.push(Token(msg.sender,
_tokenURI));
tokenOwners[tokenId] = msg.sender;
}

function transfer(address _to, uint256 _tokenId) public


{ require(tokenOwners[_tokenId] == msg.sender, "You don't own
this token"); tokenOwners[_tokenId] = _to;
}

function getTokenURI(uint256 _tokenId) public view returns (string


memory) { return tokens[_tokenId].tokenURI;
}
}
Output:

27
28
Activity - 10
Problem Statement: Lottery Contract

Develop a lottery contract with an entry fee and randomised winner


selection.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Lottery
{ address public
manager;
address[] public players;

event LotteryStarted();
event WinnerSelected(address winner);

constructor()
{ manager =
msg.sender;
}

function enter() public payable { require(msg.value > 0.01


ether, "Entry fee is at least 0.01 Ether");
players.push(msg.sender);
}

function random() private view returns (uint) { return


uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp,
players)));
}

function pickWinner() public restricted


{ require(players.length > 0, "No players in the
lottery");

uint index = random() % players.length;


address winner = players[index];
emit WinnerSelected(winner);

29
// Transfer the entire contract balance to the winner
payable(winner).transfer(address(this).balance);

// Reset the player array for the next round


players = new address[](0);
}
modifier restricted() { require(msg.sender == manager, "Only the
manager can call this function"); _;
}

function getPlayers() public view returns (address[]


memory) { return players;
}
}

Output:

30
Activity - 11
Problem Statement: Supply Chain Contract

Build a supply chain contract that tracks the movement of goods from
producer to consumer.

Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

31
contract
SimpleSupplyChain
{ address public
producer; address
public consumer;
bool public delivered;

event ProductProduced();
event ProductShipped();
event ProductDelivered();

constructor()
{ producer =
msg.sender;
delivered = false;
}

modifier onlyProducer() { require(msg.sender == producer, "Only the


producer can perform this action"); _;
}

modifier onlyConsumer() { require(msg.sender == consumer, "Only the


consumer can perform this action"); _;
}

function produceProduct() public onlyProducer


{ emit ProductProduced();
}

function shipProduct(address _consumer) public onlyProducer


{ consumer = _consumer;
emit ProductShipped();
}
function confirmDelivery() public
onlyConsumer {
delivered = true;
emit ProductDelivered();
}
}

Output:

32
Activity - 12
Problem Statement: KYC Contract

Build a contract that verifies user identity using KYC (Know Your
Customer) principles.

Pre-Requisites:

33
1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract KYC { address public owner; enum KYCStatus


{ NotSubmitted, Pending, Approved, Rejected }

struct KYCData
{ KYCStatus status;
string data; // In a real KYC system, this would be more detailed user data
}

mapping(address => KYCData) public kycRecords;

event KYCSubmitted(address user);


event KYCApproved(address user);
event KYCRejected(address user);

constructor()
{ owner =
msg.sender;
}

modifier onlyOwner() { require(msg.sender == owner, "Only the


owner can perform this action"); _;
}

function submitKYC(string memory _data) public


{ require(kycRecords[msg.sender].status == KYCStatus.NotSubmitted,
"KYC already
submitted"); kycRecords[msg.sender] =
KYCData(KYCStatus.Pending, _data); emit
KYCSubmitted(msg.sender);
}

function approveKYC(address _user) public


onlyOwner { require(kycRecords[_user].status ==
KYCStatus.Pending, "KYC is not pending");
kycRecords[_user].status = KYCStatus.Approved;
emit KYCApproved(_user);
}

function rejectKYC(address _user) public onlyOwner


{ require(kycRecords[_user].status == KYCStatus.Pending, "KYC is not

34
pending"); kycRecords[_user].status = KYCStatus.Rejected; emit
KYCRejected(_user);
}
}

Output:

Activity - 13
Problem Statement: Subscription Contract

Develop a contract for subscription-based services, enabling users to


pay on a recurring basis.

35
Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SubscriptionService { address public owner; uint256


public subscriptionPrice; uint256 public nextPaymentDue;
event SubscriptionRenewed(address user, uint256
nextPaymentDue);

constructor(uint256 _subscriptionPrice)
{ owner = msg.sender;
subscriptionPrice = _subscriptionPrice;
nextPaymentDue = block.timestamp + 30 days; // Initial subscription is for 30
days
}

modifier onlyOwner() { require(msg.sender == owner, "Only the


owner can perform this action"); _;
}

modifier subscriptionDue() { require(block.timestamp >=


nextPaymentDue, "Subscription payment is due");
_;
}

function setSubscriptionPrice(uint256 _newPrice) public onlyOwner


{ subscriptionPrice = _newPrice;
}

function renewSubscription() public payable subscriptionDue


{ require(msg.value >= subscriptionPrice, "Insufficient payment for
subscription
renewal");

uint256 extraAmount = msg.value -


subscriptionPrice; if (extraAmount > 0)
{ payable(msg.sender).transfer(extraAmount); //
Refund extra payment
}

nextPaymentDue = nextPaymentDue + 30 days; // Renew for another 30


days emit SubscriptionRenewed(msg.sender, nextPaymentDue);
}
36
}

Output:

Activity - 14
Problem Statement: Stake Contract

Design a contract that allows users to stake tokens in return for rewards.

Pre-Requisites:
37
1. Remix Engine
2. Solidity Compiler

Program:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStaking
{ address public
owner; uint256 public
rewardRate; uint256
public totalStaked;

mapping(address => uint256) public stakedBalances;


mapping(address => uint256) public rewards;

event Staked(address staker, uint256 amount);


event Unstaked(address staker, uint256
amount); event RewardClaimed(address staker,
uint256 amount);

constructor(uint256 _rewardRate)
{ owner = msg.sender;
rewardRate = _rewardRate;
}

modifier onlyOwner() { require(msg.sender == owner, "Only the


owner can perform this action"); _;
}

function stake() public payable { require(msg.value


> 0, "Amount must be greater than 0");
stakedBalances[msg.sender] += msg.value;
totalStaked += msg.value;
emit Staked(msg.sender, msg.value);
}

function unstake(uint256 _amount) public


{ require(stakedBalances[msg.sender] >= _amount, "Insufficient
staked balance"); stakedBalances[msg.sender] -= _amount;
totalStaked -= _amount;
payable(msg.sender).transfer(_amount);
emit Unstaked(msg.sender, _amount);
}

function claimReward() public {

38
uint256 reward = (stakedBalances[msg.sender] *
rewardRate) / 100; require(reward > 0, "No rewards to
claim"); rewards[msg.sender] += reward;
emit RewardClaimed(msg.sender, reward);
}

function withdrawRewards() public {


uint256 reward = rewards[msg.sender];
require(reward > 0, "No rewards to
withdraw"); rewards[msg.sender] = 0;
payable(msg.sender).transfer(reward);
}
}
Output:

Activity - 15
Problem Statement: Pet Shop Contract

Design a contract that allows users to purchase pets from the shop.

39
Pre-Requisites:

1. Remix Engine
2. Solidity Compiler

Program:

pragma solidity 0.5.16;

contract Adoption
{ address[16] public
adopters;

function adopt(uint petId) public returns (uint) {


require(petId>=0 && petId<=15);
adopters[petId]=msg.sender;
return petId;
}

function getAdopters() public view returns(address[16]


memory) { return adopters;
}
}

Output:
40
41

You might also like