Cbt-Record Removed Merged
Cbt-Record Removed Merged
KANCHEEPURAM
(A Constituent college of Anna University Chennai)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Name:
Register no:
Year/Semester: Branch:
UNIVERSITY COLLEGE OF ENGINEERING KANCHEEPURAM
KANCHEEPURAM - 631 552
BONAFIDE CERTIFICATE
REGISTER NO
AIM:
• Verify the installation of Docker, Node.js, and Java.
• Set up Hyperledger Fabric using Docker.
• Set up a local Ethereum environment using Docker and Ganache.
PREREQUISITES:
PROCEDURE:
1. Open Linux terminal using WSL (Windows Subsystem for Linux) or using VirtualBox.
Docker:
2. Verify the installation of Docker.
Nodejs:
4. Verify the installation of Nodejs and install if not present.
Java:
5. Verify the installation of Java and install if not present
1. Install cURL
1. Install Ganache
2. The interface will be like this :
3. Create a folder Ethereum_ganache
version: '3'
services:
ganache:
image: trufflesuite/ganache-cli
ports:
- "8545:8545"
command: >
ganache-cli
--host 0.0.0.0
--port 8545
--networkId 5777
--mnemonic "candy maple cake sugar pudding cream honey rich smooth crumble sweet
treat"
RESULT:
Thus, Docker, Java, NodeJS have been successfully installed and the Hyperledger Fabric
and Ethereum Network have been setup on the Local machine using Docker
.
EX.NO: 2 Create and deploy a blockchain network and perform invoke and
query on your blockchain network.
DATE:
AIM:
To create a blockchain network and perform invoke and query on the deployed blockchain
network.
PROCEDURE:
5. Initialize truffle
6. Modify the truffle with the code below
module.exports = {
networks : {
development : {
host : '127.0.0.1',
port : 5777,
network_id : "*"
}
},
compilers : {
solc : {
version : "0.8.19"
}
}
}
7. Now, in the contracts folder create a contract and name it as SimpleStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract SimpleStorage {
uint256 storedData;
8. This contract allows us to invoke and query the locally deployed Ethereum Blockchain.
9. Now, in the migrations folder create a file and name it as 2_deploy_contracts.js and write
the code below
const SimpleStorage = artifacts.require("SimpleStorage");
12. Now, we will be ale to interact with the blockchain, by using the command truffle console.
RESULT:
Thus, created a blockchain network and performed invoke and query on the deployed
blockchain network.
EX.NO: 3
Interact with a blockchain network. Execute transactions and
requests against a blockchain network by creating an app to test the
DATE:
network and its rules.
AIM:
To setup a Blockchain network and execute Transactions and Requests against a Blockchain
network and test by developing an application.
PROCEDURE:
module.exports = {
networks: {
development: {
host: '127.0.0.1',
port: 7545,
network_id: '*'
}
},
compilers: {
solc: {
version: "0.8.19"
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract SimpleStorage {
useEffect(() => {
fetchStoredValue();
}, []);
return (
<div className="flex flex-col items-center mt-16">
<h1 className="text-3xl text-neutral-700 font-bold">Simple Storage</h1>
<div className="mt-6">
<h2 className="text-xl">Stored Value: {storedValue}</h2>
</div>
</div>
);
};
14. Now link the contract to ganache , by opening ganache and adding truffle-config.js
15. Now, testing our web app
16. And now we can see the changed value as well as do transactions.
RESULT:
Thus, interacted with a blockchain network and executed transactions and requests against a
blockchain network by creating an app to test the network and its rules.
EX.NO: 4
Deploy an asset-transfer app using blockchain.
DATE:
AIM:
To create an asset transfer app using solidity smart contract and testing out using truffle
PROCEDURE:
1. Create a folder and initialize smart contract, using command truffle init
2. Inside the contracts folder create contract file and write the following code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleAssetTransfer {
struct Asset {
string name;
address owner;
}
removeAssetFromOwner(previousOwner, _assetId);
ownerAssets[_to].push(_assetId);
3. Inside migrations folder create a file 2_deploy_contracts.js and write the following code
useEffect(() => {
if (storedOwner) {
fetchOwnerAssets(storedOwner);
}
}, [storedOwner]);
return (
<div className="flex flex-col items-center mt-16">
<h1 className="text-3xl text-neutral-700 font-bold">Simple Asset
Transfer</h1>
<div className="mt-6">
<h2 className="text-xl">Asset Owner: {storedOwner}</h2>
<button
onClick={() => fetchOwner(assetId)}
className="mt-2 bg-blue-500 text-white px-3 py-2 rounded-md"
>
Get Asset Owner
</button>
</div>
<div className="mt-6">
<h2 className="text-xl">Assets Owned:</h2>
<ul>
{ownerAssets.map((id) => (
<li key={id.toString()}>Asset ID: {id.toString()}</li>
))}
</ul>
</div>
</div>
);
};
RESULT:
Thus, an asset transfer app created using Ethereum Blockchain.
EX.NO: 5 Use blockchain to track fitness club rewards. Build a web app
to track and trace member rewards
DATE:
AIM:
To develop a web app to track the fitness club rewards using Blockchain
PROCEDURE:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Fitness {
struct Member {
address memberAddress;
uint256 points;
bool isMember;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can execute this function");
_;
}
modifier onlyMember() {
require(members[msg.sender].isMember, "Only members can execute this
function");
_;
}
constructor() {
owner = msg.sender;
}
9. In the src, create a folder utils/constants/contract.js and then paste the abi and
contractAddress.
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<MetaMaskProvider>
<Toaster/>
<App />
</MetaMaskProvider>
</React.StrictMode>,
)
useEffect(() => {
const connectMetaMask = async () => {
const provider = await detectEthereumProvider();
if (provider) {
const accounts = provider.selectedAddress ? [provider.selectedAddress] :
[];
handleAccountsChanged(accounts);
handleNetworkChanged(provider.networkVersion);
provider.on('accountsChanged', handleAccountsChanged);
provider.on('chainChanged', handleNetworkChanged);
} else {
toast.error('Please install MetaMask!');
}
};
connectMetaMask();
}, []);
try {
const signer = await provider.getSigner();
const tx = await contract.connect(signer).addRewardPoints(addressToAdd,
pointsToAdd);
await tx.wait();
fetchData();
setPointsToAdd(0);
setAddressToAdd("");
setAddPointsLoading(false) // Reset address input after adding points
toast.success('Reward points added successfully!'); // Success notification
} catch (error) {
console.error(error);
toast.error('Error adding points');
}
};
return (
<div className="">
<div className="fixed right-3 top-3">
<button onClick={connectWallet} className="flex bg-black justify-center
text-white px-3 py-2 rounded-lg">
<h1 className="w-24 truncate">{isConnected ? `${account}` : `Connect
Wallet`}</h1>
</button>
</div>
<div className="mt-16 flex items-center flex-col ">
<h1 className="text-3xl text-neutral-700 font-bold">Fitness Club Reward
Tracker</h1>
<button
onClick={fetchData}
className="bg-blue-700 mt-6 text-white px-3 py-2 rounded-md shadow-sm"
disabled={!isConnected}
>
{
dataloading ? <div className="flex items-center gap-2">
<div className="h-3 w-3 border border-t-transparent rounded-full
animate-spin"></div>
Fetching...
</div> : <div> My Rewards</div>
}
</button>
{data !== null && <p className="flex items-center gap-2 mt-5">{data}
<Trophy className="text-yellow-400" size={18} /></p>}
</div>
</div>
);
};
RESULT:
Thus, a web application for Tracking Fitness Club Rewards was doen with the help of
Ethereum Blockchain.
EX.NO: 6
Use blockchain to create a Car Auction Network
DATE:
AIM:
To create a car Auction network using Blockchain technology using Ethereum Blockchain
PROCEDURE:
1. Develop the Smart contract by applying all logics required for creating a Car Auction
Network.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract CarAuction {
struct Car {
string make;
string model;
uint256 year;
}
struct Auction {
Car car;
address payable seller;
uint256 startingBid;
uint256 highestBid;
address payable highestBidder;
bool active;
}
if (auction.highestBidder != address(0)) {
auction.highestBidder.transfer(auction.highestBid);
}
auction.highestBid = msg.value;
auction.highestBidder = payable(msg.sender);
emit HighestBidIncreased(_auctionId, msg.sender, msg.value);
}
auction.active = false;
auction.seller.transfer(auction.highestBid);
emit AuctionEnded(_auctionId, auction.highestBidder,
auction.highestBid);
}
RESULT:
Thus, a Car Auction network have been created by Ethereum Blockchain and tested