Deploying Ethereum Smartcontracts on HyperledgerFabric

Salman Dabbakuti
Jul 2 · 4 min read

Who This Article is for?

This article is for those who are currently On Blockchain. knowledge on Ethereum and Hyperledger Eco-Systems is necessary to understand these concepts.

What We Are going to do?

The point is very clear that we are going to deploy Ethereum Smartcontracts on Hyperledger fabric Network using Fabric-Evm and doing Cross-Platform checks for Ethereum Smartcontracts.

Components

  1. Hyperledger Fabric EVM

Customized Ethereum virtual machine Running on Hyperledger fabric peers

2.Fab3 Proxy

EVM Compatiable Blockchain(Hyperledger) node client for interacting with nodes.

3.Web3.js

A javascript library for interacting with local or remote blockchain node. in this project scenario, it will interacts Fab3.

4.A BYFN Fabric Network

A simple Byfn network allows you to create Hyperledger Fabric network Running with 2 Organizations each ORG with two peers.

Work Flow

1. Building Fabric network
2. Mounting EVM on Fabric-peers.
3. Starting fabric network
4. Installing and Instantiating EVM Chaincode
5. Setting up Fab3
6. Deploying Smartcontract.

Pre-Requisites

1. Go

Installing Go and add it to your path

2. node.js and Npm

3. Docker

Steps

1. Building Fabric Network

Clone fabric-samples to your $GOPATH/src/github.com/hyperledger directory. for this, we need to create directories first and then clone

Folder Structure

Download docker images for fabric-samples first network

2. Mounting EVM on Fabric-peers.

Clone the fabric-chaincode-evm repo in your GOPATH/ directory.

We need to include fabric-chaincode-evm to our first-network docker images. for this, Navigate back to fabric-samples/first-network directory.

Update docker-compose-cli.yaml with the volumes to include EVM. add EVM volume like below using any code editor

3. Starting fabric-Network

Generate certificates and start your network

4. Installing and Instantiating EVM Chaincode

Now we need to Install and instantiate chaincode on evm. navigate to cli of docker container

Add required Peer dependies for network.

Install and Instantiate Chaincode on all peers

5. Setting up Fab3

Execute the following to set certain environment variables required for setting up Fab3.

Now Navigate back to fabric-chaincode-evm directory to build and run proxy

Now your Fabric network is up and running at http://localhost:5000 and ready for deploying Smartcotracts.

6. Deploying Smartcontracts

Open another terminal, Install web3 library

Create a Work directory of your choice. run npm install on that directory to install required npm modules.

Now we’ll enter node console to set up our web3. Run below command in your work directory

Assign Web3 library and use the fab3 running in the previous terminal as provider

To see your account information, run

You’ll see account address similar to ethereum. Assign this account as defaultAccount

Now You can deploy your smartcontract by pointing Abi and bytecode in similar way as you do with ethereum. Compile Your contract on remix or truffle. make abi and bytecode ready for deployment.

You can get Contract address with transaction hash of deployed contract like below

References:

  1. Hyperledger Fabric EVM
  2. Fabric-samples
  3. Hyperledger Fabric docs
  4. IBM Hyperledger-Ethereum
  5. web3.js

Salman Dabbakuti

Written by

Curious about Decentralized future. Working on Blockchain Technologies.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade