0% found this document useful (0 votes)
12 views48 pages

Vansh Blockchain

The document outlines a series of experiments conducted in a Blockchain Lab at Maharaja Agrasen Institute of Technology, focusing on the installation and deployment of various blockchain technologies including Docker, Hyperledger Fabric, and Ethereum. It details the procedures for setting up a blockchain network, deploying smart contracts, and creating applications to interact with the blockchain, such as an asset-transfer app and a rewards tracking web app. Each experiment includes specific aims, procedures, and results, demonstrating practical applications of blockchain technology in different contexts.

Uploaded by

Sahil Sadhwani
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)
12 views48 pages

Vansh Blockchain

The document outlines a series of experiments conducted in a Blockchain Lab at Maharaja Agrasen Institute of Technology, focusing on the installation and deployment of various blockchain technologies including Docker, Hyperledger Fabric, and Ethereum. It details the procedures for setting up a blockchain network, deploying smart contracts, and creating applications to interact with the blockchain, such as an asset-transfer app and a rewards tracking web app. Each experiment includes specific aims, procedures, and results, demonstrating practical applications of blockchain technology in different contexts.

Uploaded by

Sahil Sadhwani
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/ 48

MAHARAJA AGRASEN INSTITUTE OF

TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY

BLOCKCHAIN LAB
Subject Code: ETCT-451

SUBMITTED BY: Vansh Comar SUBMITTED TO: Dr. Yogesh Sharma


ROLL NO: - 05214812720
GROUP: CST3
INDEX

S. No. EXPERIMENT NAME DATE REMARK

1. Install and understand Docker container, Node.js, Java and


Hyperledger Fabric, Ethereum and perform necessary software
installation on local machine/create instance on Cloud to run.

2. Create and deploy a blockchain network using


Hyperledger Fabric SDK for Java Set up and
initialize the channel, install and instantiate chain code,
and perform invoke and query on your
blockchain network.

3. Interact with a block chain network. Execute


transactions and requests against a block chain network
by creating an app to test the network and its rules

4. Deploy an asset-transfer app using block chain. Learn app


development within a Hyperledger Fabric network

5. Use block chain to track fitness club rewardsBuild a


web app that uses Hyperledger Fabric to track and trace
member rewards

6. Car auction network: A Hello World example with


Hyperledger Fabric Node SDK and IBM Block chain
Starter Plan. Use Hyperledger Fabric to invoke
chaincode while storing results and data in the starter
plan

7. Develop an loT asset tracking app using Block chain.


Use an loT asset tracking device to improve a supply
chain by using Block chain, loT devices, and
Node-RED

8. Secure art using block chain digital certificates.


Node.js-based auction application can help
democratize the art market

9. Develop a voting application using Hyperledger and


Ethereum. Build a decentralized app that
combines Ethereum's Web3 and Solidity smart
contracts with Hyperledger's hosting Fabric and
Chaincode EVM
EXPERIMENT - 1

AIM :

Install and understand Docker container, Node.js, Java and Hyperledger Fabric, Ethereum and
perform necessary software installation on local machine/create instance on Cloud to run.

Docker

Docker is an OS-level virtualization software platform that helps users in building and
managingapplications in the Docker environment with all its library dependencies. Docker is
considered a betteralternative to a virtual machine.

The main components of Docker are:

Docker Engine: The core component of Docker that manages containers. It includes a
serverand a REST API that allows users to interact with the Docker daemon.

Docker Images: A Docker image is a lightweight, standalone, and executable package thatcontains
everything needed to run an application, including the code, runtime, libraries,environment variables,
and configuration files.

Docker Container: A container is an instance of a Docker image, running in an


isolatedenvironment. Containers are lightweight, start quickly, and use the host operating
system'skernel to run the application.

a. Install and understand Docker container, Node.js,

Java Procedure:

Step 1: Install and understand Docker container, Node.js, Java


Step 2: Confirm the latest versions of both Docker and Docker Compose executables were installed.
Step 3: Start the docker service
Step 4: Pull a CentOS image from docker hub and run the CentOS
container. Step 5: Run the CentOS container.

Install Docker Desktop on Ubuntu

Step 1: Docker installation On Ubuntu

Install docker on Ubuntu box, first let us update the packages.


sudo apt-get update
Step 2: Install Docker

Install the latest version of Docker if it is not already installed.

sudo apt-get -y install docker-compose

Step 3: Confirm the latest versions of both Docker and Docker Compose executables were
installed.

docker --version
Docker version 20.10.12, build 20.10.12-

0ubuntu2~20.04.1 docker-compose --version

docker-compose version 1.25.0, build

Step 4: Make sure the Docker daemon is running.

sudo systemctl start docker

Optional: If you want the Docker daemon to start when the system starts, use the following:
sudo systemctl enable docker

Step 5: Start the docker service.

sudo service docker

start

It says your job is already running. Docker has been successfully installed.

Step 6: Pull a CentOS image from docker hub and run the CentOS

container.

sudo docker pull centos

Step 7: Run the CentOS container

sudo docker run -it centos

First installed docker on Ubuntu, after that we have pulled a CentOS image from docker hub and
using that image, we have successfully built a CentOS container.

Result:
Thus the installation of Docker container, Node.js, Java is successfully completed.
b. Install and understand Hyperledger Fabric and

Ethereum Procedure:

Step 1: Install curl,


git Step 2: Install
Docker Step 3: Install
Golang
Step 4: Install Hyperledger Fabric
Step 5: Update the repositories
Step 6: Install ethereum
Step 7: Install the Test
RPC Step 1: Install curl,
git

Install the latest version of git and curl if it is not already installed.

sudo apt update


sudo apt-get install git
sudo apt-get install curl

Step 2: Install Docker

Install the latest version of Docker if it is not already installed.


sudo apt-get -y install docker-compose

Once installed, confirm that the latest versions of both Docker and Docker Compose executables
were installed.

docker --version

Docker version 20.10.12, build 20.10.12-

0ubuntu2~20.04.1 docker-compose --version

docker-compose version 1.25.0, build

Make sure the Docker daemon is

running.

sudo systemctl start docker

Optional: If you want the Docker daemon to start when the system starts, use the following:

sudo systemctl enable docker

Add your user to the Docker group.


sudo usermod -a -G docker <username>

Step 3: Install Golang

curl -O https://dl.google.com/go/go1.18.3.linux-
amd64.tar.gz tar xvf go1.18.3.linux-amd64.tar.gz
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Now, you have to open and edit you **bashrc **file. In most cases, the bashrc is a hidden file that
lives in your home directory.

nano ~/.bashrc

Add following two lines, at the end of the file:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Create new directory where you will install Hyperledger Fabric

mkdir fabric-network
Step 4: Install Hyperledger Fabric
To download a specific release, pass a version identifier for Fabric and Fabric CA Docker
images. The command below demonstrates how to download the latest production releases -
Fabric v2.4.4 and Fabric CA v1.5.3

curl -sSL https://bit.ly/2ysbOFE | bash -s -- <fabric_version> <fabric-ca_version>


curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.4.4 1.5.3

Download the latest release of Fabric samples, docker images, and binaries.

curl -sSL https://bit.ly/2ysbOFE | bash -s


Now you have installed Hyperledger Fabric with all dependencies.

To test the our installation, we will run test network that comes with fabric-

samples cd fabric-samples/test-network
./network.sh up createChannel -ca -c mychannel -s couchdb

The above command will create a channel(mychannel) with certificate Authorities and bring
up couch-db as state database.

Using following Docker command we can check all running container

docker ps -a

You should be able to see the containers up and running.


You have installed and setup Hyperledger

Fabric. Step 5: Update the repositories

.sudo apt update

Step 6: Install ethereum


sudo apt install ethereum

You can check the installation by using

the geth version command

Step 7: Install the Test RPC

Test RPC is an Ethereum node emulator implemented in NodeJS. The purpose of this Test RPC is
to easily start the Ethereum node for test and development purposes.
sudo npm install -g ethereumjs-testrpc
It created 10 test accounts and displays respective private keys. We can use these accounts for
our testing purposes. By default the Test

RESULT:

The installation of hyper ledger and ethereum is completed successfully


EXPERIMENT- 2

AIM:

Create and deploy a blockchain network using Hyperledger Fabric SDK for Java Set up and initialize
the channel, install and instantiate chain code, and perform invoke and query on your blockchain
network.

a. Create and deploy a blockchain network using Hyperledger Fabric SDK for Java Set up
and initialize the channel.

PROCEDURE:

Step 1: Install Fabric and Fabric


Samples Step 2: Download fabric
samples
Step 3: Pull the docker containers
Step 4: Navigate to test network directory
Step 5: Remove any containers or
artifacts Step 6: Up the network
Step 7: Verify the
containers Step S: Create a
channel

$ sudo apt update


$ sudo apt-get install git
$ sudo apt install -yjq

Ifthe Jq installtion Enor arises and If lock files is there need to remove lock by

sudo rm /vawlib/apt/üstsnock
sudo rm /var/cache/apt/archivesnock
sudo rm /vawlib/dpkgnock
sudo dpkg —configure -a

Kill running process


Find Process id by ps then install

sudo apt update


sudo apt install -
yjq

Step 1: Install Fabric and Fabric Samples


Fabric and Fabric samples: The Fabric executables to run a Fabric network along with sample
code.

mkdir fabric
cd fabric
Step 2: Download fabric samples

Before you can run the test network, you need to install Fabric Samples in your environment.

curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh


&& chmod +x
install-fabric. Sh

Step 3: Pull the docker containers

./install-fabric. sh

Step 4: Navigate to test network directory

cd fabric-samples/test-network

Step 5: Remove any containers or artifacts

./network.sh down

Step 6: Up the network

./network.sh up

Step 7: Verify the containers

Run the following command to list all of Docker containers that are running on your machine.
You should see the three nodes that were created by the network.sh

script docker ps -a

Step 8: Create a channel

./network.sh createChannel -c mychannel


//mychannel is the channel name//

For Step 6 And Step 8: Up and create channel in single step (already done)

./network.sh up createChannel
Result:
Thus blockchain network using Hyperledger Fabric SDK for Java Set up is created and the channel
initializes successfully.
b Install and Instantiate chain code, and Perform invoke and Query on your blockchain
Network.

Procedure:

Step 1: Deploy chaincode on peers and channel


Step 2: Set the path for peer binary and config for core.yaml
Step 3: Set the environment variables to operate Peer as
Orgl Step 4: Command to initialize the ledger with assets
Step 5: Query the ledger
Step 1: Deploy chaincode on peers and channel

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-


typescript typescript

Interacting with the network

Step 2: Set the path for peer binary and config for core.yaml
expon PATH-S
expon FABRIC_CFG PATH=SPWD/.a'config/

Step 3: Set the environment variables to operate Peer as Orgl


export CORE_PEER TLS ENABLED-ttue
export CORE PEER
export CORE_PEER

{PWD}/organizations/peerOrganizations/org1.example.com/peers/peeff).org1.example.com/tls/ca.clt
export CORE_PEER MSPCONFIGPATH=S

{PWD }/organizations/peerOrganizations/org1.example.com/users/[email protected]
export CORE PEER

Step 4: Command to initialize the ledger with assets

Chaincodes are invoked when a network member wants to transfer or change an asset on the ledger.
Use the following command to change the owner of an asset on the ledger by invoking the asset-
transfer (basic) chaincode:

peer chaincode invoke -o localhost:7050 —ordererTLSHostnameOve1Tide orderer.example.com


--tls
—cafile "S
{PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscace
rts/tlsca.example.com-ceff.pem" -C mychannel -n basic —peerAddresses localhost:7051

--t1sRootCertFiles "S
{PWD} /organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.
CH"

--peerAddresses localhost:9051 --tlsRootCertFiles "S

{PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
"
Step 5: Query the ledger

Run the following command to get the list of assets that were added to your channel ledger:

peer chaincode query -C mychannel -n basic -c '{"Args":["GetA11Assets"]}'

The output of the command will display the result of the "GetA11Assets" function query,
showing the assets retrieved from the ledger

Result:

Thus the chain code Installed, invoked and Query on your blockchain network is Performed
successfully.
EXPERIMENT-3

AIM:

Interact with a block chain network. Execute transactions and requests against a block chain
network by creating an app to test the network and its rules

PROCEDURE:

Step 1: Install Python

sudo apt update


sudo apt install python3 python3-pip

Step 2: Install Ganache:

chmod +x Ganache-*.AppImage
./Ganache-*.AppImage

Start a new Ethereum blockchain. Take note of the RPC server endpoint
(usually http://127.0.0.1:7545).

Step 3: Install Web3.py


Open your terminal and run the following command to install the Web3.py

library: pip3 install web3

Step 4: Create a Python Script


Create a new Python script (e.g., blockchain_interaction.py) with the following code:
Step 5: Run the Script
Execute the script by running the following command in your terminal:

python3 blockchain_interaction.py

Output :
EXPERIMENT 4

AIM:

Deploy an asset-transfer app using block chain. Learn app development within a Hyperledger
Fabric network

PROCEDURE:

Docker and Docker Compose:

Install Docker: Docker Installation Guide


Install Docker Compose: Docker Compose Installation Guide

Go Programming Language:

Install Go: Go Installation Guide


Hyperledger Fabric Samples:

Clone the Hyperledger Fabric Samples repository:


git clone https://github.com/hyperledger/fabric-samples.git

PROCEDURE

Step 1: Set Up Hyperledger Fabric Network


Navigate to the fabric-samples/test-network directory and start the test network with a basic
configuration:

Step 2: Create and Deploy Smart Contract (Chaincode)


Navigate to the fabric-samples/chaincode/asset-transfer-basic directory and install the smart contract:

Now, package and install the chaincode:

Step 3: Build Asset-Transfer Application


Create a new directory for your application, navigate into it, and create a simple Go application to
interact with the blockchain.

Create a file named main.go and add the following code:


Step 4: Run the Asset-Transfer

Application Run the asset-transfer

application:\

OUTPUT:

Query Response: {"ID":"asset1","Color":"blue","Size":35,"Owner":"Tom","AppraisedValue":300}


EXPERIMENT-5

AIM:

Use block chain to track fitness club rewardsBuild a web app that uses Hyperledger Fabric to track and trace
member rewards.

PREREQUISITES:

Hyperledger Fabric Setup:

Follow the instructions in the Hyperledger Fabric documentation to set up your Hyperledger Fabric network.

Docker and Docker Compose:

Install Docker: Docker Installation Guide

Install Docker Compose: Docker Compose Installation Guide

PROCEDURE:

Step 1: Define the Smart Contract (Chaincode)

Create a new chaincode that will handle the tracking and tracing of member rewards. You can modify the asset-
transfer-basic chaincode provided in the Hyperledger Fabric samples as a starting point.

Step 2: Install and Instantiate the Chaincode

Use the Hyperledger Fabric CLI or SDK to install and instantiate your chaincode on the Hyperledger Fabric network.
Step 3: Build the Web App

Create a web application to interact with the Hyperledger Fabric network. You can use a web framework like Flask
(Python) for simplicity.

a) Install Flask: pip install Flask


b) Create a file named app.py with the following code:
c) Create a file named templates/index.html for the front-end:

Step 4: Integrate the Web App with Hyperledger Fabric

Modify the web app (app.py) to use the Hyperledger Fabric SDK to interact with the blockchain. You will need to
replace the placeholder logic in the query_rewards route with the actual logic to query the member rewards from the
Hyperledger Fabric network.

Step 5: Run the Web App

Run the Flask web application:

$ python app.py

OUPUT:
EXPERIMENT - 6

AIM:

Car auction network: A Hello World example with Hyperledger Fabric Node SDK and IBM Block
chain Starter Plan. Use Hyperledger Fabric to invoke chaincode while storing results and data inthe
starter plan.

PREREQUISITES:

1. IBM Blockchain Starter Plan:

Sign up for the IBM Blockchain Platform Starter Plan: IBM Blockchain

Platform Create a new network and add a new member organization.

2. Hyperledger Fabric Node SDK:

Install Node.js: Node.js Installation

Install the Hyperledger Fabric Node SDK:

$ npm install fabric-network

PROCEDURE:

Step 1: Define the Smart Contract (Chaincode)

Create a simple chaincode for a car auction network. This example uses the "Hello World" chaincode.

Step 2: Deploy the Chaincode to IBM Blockchain Starter Plan

Use the IBM Blockchain Platform to deploy your chaincode to the network you created. Follow the
platform's documentation to package, install, and instantiate the chaincode.

Step 3: Create a Node.js Application

Create a Node.js application to interact with the deployed

chaincode. Create a file named app.js with the following code:


Step 4: Run the Node.js Application

Run the Node.js application to invoke the chaincode and store results on the IBM Blockchain Starter
Plan

$ node app.js

OUTPUT:
EXPERIMENT 7

AIM:
Develop an loT asset tracking app using Block chain. Use an loT asset tracking device to improve a
supply chain by using Block chain, loT devices, and
Node-RED

PREREQUISITES:

Components and Technologies:

1. Blockchain Network:

2. Hyperledger Fabric or Ethereum are popular choices for building blockchain networks.

3. IoT Devices:

Use IoT devices with sensors for tracking assets. These devices should be capable of sending
data to the blockchain.

4. Node-RED:

Node-RED is a flow-based development tool for visual programming. It can be used to create a user
interface and to handle communication between IoT devices and the blockchain.

PROCEDURE:

Step 1: Set Up the Blockchain Network

Choose and set up a blockchain network (Hyperledger Fabric or Ethereum). Follow the
documentation for the chosen blockchain technology to create and deploy smart contracts
(chaincode) for asset tracking.

Step 2: Configure IoT Devices

Configure your IoT devices with the necessary sensors for asset tracking. Ensure that the devices are
capable of sending data to the blockchain network. This may involve setting up MQTT or other
communication protocols.

Step 3: Set Up Node-RED

Node-RED is used to create a visual interface and manage communication between IoT devices
and the blockchain. Install and configure Node-RED on a server or device.

Install Node-RED:

$ npm install -g --unsafe-perm


node-red Start Node-RED:

$ node-red
Access the Node-RED Editor:

Open a web browser and navigate to http://localhost:1880 to access the Node-RED editor.

Step 4: Build the Node-RED Flow

Create a Node-RED flow to handle communication between IoT devices and the

blockchain. Install Node-RED Packages:

Install the necessary Node-RED packages for blockchain and IoT

integration. Create a Flow:


Design a flow that receives data from IoT devices, formats the data, and sends it to the blockchain
network.

Step 5: Test the Solution

Deploy the solution and test the end-to-end process:

Send Data from IoT Devices:

Ensure that the IoT devices are sending data to Node-RED.

Node-RED Processing:

Observe Node-RED processing the data and preparing it for the blockchain.

Blockchain Interaction:

Verify that the data is successfully stored on the blockchain.

Step 6: Implement Asset Tracking App

Build a web or mobile application that interacts with the blockchain to display asset tracking
information. You can use web development frameworks like React, Angular, or Vue.js for this
purpose.
OUTPUT:

DEBUG CONSOLE OUTPUT(NODE-RED)

[Iot Asset Tracking] 2023-01-01T12:00:00 - Asset ID: 123, Location: Warehouse A, Status: In Transit

HYPERLEDGER FABRIC OUTPUT(NODE-RED)

[Hyperledger Fabric] 2023-01-01T12:00:00 - Transaction submitted: Create Asset - Asset ID: 123,
Location: Warehouse A, Status: In Transit
EXPERIMENT -8

AIM:

Secure art using block chain digital certificates. Node.js-based auction application can help
democratize the art market

PREREQUISITES:

1. Blockchain Network:

2. Hyperledger Fabric or Ethereum are common choices for building blockchain networks.

3. Digital Certificates:

Use digital certificates to uniquely identify and verify the authenticity of artworks. These
certificates can be stored on the blockchain.

4. Node.js and Express:

5. Node.js is used for building the backend server, and Express is a web application framework for Node.js.

6. Smart Contracts (Chaincode):

Develop smart contracts that define the rules and logic of the art auction on the blockchain.

PROCEDURE:

Step 1: Set Up the Blockchain Network

Choose and set up a blockchain network (Hyperledger Fabric or Ethereum). Follow the
documentation for the chosen blockchain technology to create and deploy smart contracts
(chaincode) for the art auction.

Step 2: Implement Digital Certificates

Generate digital certificates for each piece of art. The certificates could contain information about
the artist, artwork details, and a unique identifier (e.g., hash) that can be linked to the blockchain.

Step 3: Build the Node.js Auction Application

Create a Node.js application using the Express framework for the auction.

1) Instal Dependencies

$ npm init -y

$ npm install express body-parser

2) Create the Server(app.js)


Step 4: Implement Auction Operations:

const express = require('express');

const bodyParser = require('body-parser');

const app = express();

const port = 3000;

app.use(bodyParser.json());

// Sample data for artworks and bids

let artworks = [

id: 1,

title: 'Sunflowers',

artist: 'Vincent van Gogh',

certificate: 'a1b2c3d4e5f6' // Replace with actual certificate hash


},

// Add more artworks as needed

];

let bids = [];

app.get('/', (req, res) => { res.send('Welcome to the Art

Auction!');

});

// Get a list of available artworks app.get('/artworks',

(req, res) => {

res.json(artworks);

});

// Place a bid for a specific artwork app.post('/bid/:artworkId', (req, res) => {

const { artworkId } = req.params; const {

bidder, amount } = req.body;

// Check if the artwork exists

const artwork = artworks.find(art => art.id == artworkId); if (!

artwork) {

return res.status(404).json({ error: 'Artwork not found' });

// Check if the bid amount is valid


if (amount <= 0) {

return res.status(400).json({ error: 'Invalid bid amount' });

// Place the bid

bids.push({

artworkId: artwork.id,

bidder,

amount

});

res.json({ message: 'Bid placed successfully' });

});

app.listen(port, () => {

console.log(`Server is running at http://localhost:${port}`);

});

Step 5: Integrate with Blockchain

Install the necessary blockchain SDK or library for your chosen blockchain platform. Below is a basic
example using the fabric-network SDK for Hyperledger Fabric. You'll need to adapt this code based on your
actual blockchain configuration.

javascrip

t Copy

code

const { Gateway, Wallets } = require('fabric-network'); const path =

require('path');
async function submitArtworkToBlockchain(artwork) { try {

const ccpPath = path.resolve( dirname, 'connection.json'); // Replace


with actual connection profile

const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));

const walletPath = path.join(process.cwd(), 'wallet');

const wallet = await Wallets.newFileSystemWallet(walletPath);

const gateway = new Gateway();

await gateway.connect(ccp, {

wallet,

identity: 'user1', // Replace with actual user identity discovery: {

enabled: true, asLocalhost: true }

});

const network = await gateway.getNetwork('mychannel'); // Replace with


actual channel name

const contract = network.getContract('auction'); // Replace with actual contract name

await contract.submitTransaction('createArtwork',
JSON.stringify(artwork));

console.log('Artwork details submitted to the blockchain'); await gateway.disconnect();

} catch (error) {

console.error(`Failed to submit artwork details to blockchain:


${error}`);

}
}

// Example: Submit artwork details to the blockchain when the server starts

artworks.forEach(async (artwork) => {

await submitArtworkToBlockchain(artwork);

});

Step 6: Implement certification validation


OUTPUT:

Request:

curl -X POST -H "Content-Type: application/json" -d '{"bidder": "John Doe",


"amount": 500}' http://localhost:3000/bid/1

Response with valid certificate:


EXPERIMENT -9

AIM:

Develop a voting application using Hyperledger and Ethereum. Build a decentralized app that
combines Ethereum's Web3 and Solidity smart contracts with Hyperledger's hosting Fabric
and Chaincode EVM

PREREQUISITES:

1. Ethereum:

2. Solidity for smart contract development.

3. Web3.js for interacting with Ethereum nodes.

4. Hyperledger Fabric:

5. Chaincode EVM for executing Ethereum smart contracts on Hyperledger Fabric.

6. Hyperledger Fabric SDK for Node.js.

PROCEDURE:

Step 1: Set Up Ethereum Smart Contracts

Create a Solidity smart contract for the voting application. Here's a basic example:

Step 2: Deploy Smart Contract to Ethereum


Deploy the smart contract to the Ethereum network using tools like Remix or Truffle.

Step 3: Set Up Hyperledger Fabric Network

Set up a Hyperledger Fabric network with Chaincode EVM. Follow the Hyperledger Fabric
documentation for installation and network setup.

Step 4: Create Node.js Application

Develop a Node.js application to interact with both Ethereum and Hyperledger Fabric.

;// app.js

const Web3 = require('web3');

const { Gateway, Wallets } = require('fabric-network');

const fs = require('fs');

const ethereumRpcUrl = 'http://localhost:8545'; // Replace with your Ethereum


RPC URL

const fabricConnectionProfile = 'connection-profile.json'; // Replace with


your Fabric connection profile

const fabricChannel = 'mychannel'; // Replace with your Fabric channel

const fabricContractName = 'evm-cc'; // Replace with your Fabric chaincode


name

async function main() {

// Connect to Ethereum

const web3 = new Web3(ethereumRpcUrl);

// Connect to Hyperledger Fabric

const gateway = new Gateway();

const walletPath = './wallet';


const wallet = await Wallets.newFileSystemWallet(walletPath);

const fabricConnectionOptions = {

wallet,

identity: 'user1', // Replace with your Fabric user identity discovery: { enabled: true,

asLocalhost: true }

};

await gateway.connect(fs.readFileSync(fabricConnectionProfile, 'utf8'), fabricConnectionOptions);

const network = await gateway.getNetwork(fabricChannel); const

contract = network.getContract(fabricContractName);

// Example: Vote for a candidate on both Ethereum and Fabric const candidate =

'CandidateA';

const account = await web3.eth.getAccounts().then(accounts =>


accounts[0]);

// Vote on Ethereum

const votingContract = new web3.eth.Contract(VotingContractABI,


'0xContractAddress'); // Replace with your deployed contract address

await votingContract.methods.vote(web3.utils.asciiToHex(candidate)).send({ from: account });


await contract.submitTransaction('vote', candidate);

console.log('Vote recorded successfully.');

await gateway.disconnect();

main()

Step 5: Run the Node.js Application

Run the Node.js application to interact with both Ethereum and Hyperledger Fabric.

$ node app.js

OUTPUT:

You might also like