Ethereum and Fabric Crossover: Deploying Ethereum Smart Contract on Hyperledger Fabric Blockchain

Saif Rehman
Coinmonks
6 min readJul 14, 2018

--

“Any positioning of the Hyperledger and Ethereum communities as competitive is incorrect,”-Hyperledger Project Executive Director Brian Behlendorf

Introduction

It is crucial to observe that intersection between Hyperledger and Ethereum is widening. Hypeledger Burrow project that runs under Tendermint consensus engine allows us to run Ethereum smart contract on Fabric using Hyperledger Fabric EVM chaincode plugin.

Hyperledger Fabric and Ethereum are complementary not competitive to each other

What is Hyperledger Burrow?

Burrow before was formerly known as ErisDB. Burrow in short is a permissionable smart contract machine. It executes Ethereum EVM smart contract code (usually written in Solidity or Viper) on a permissioned virtual machine. Burrow is owned and developed by Monax and is now under the umbrella of Hyperledger . Burrow project was founded and open-sourced since December 2014 and was licensed under GPL3.

“It provides a modular blockchain client with a permissioned smart contract interpreter built in part to the specification of the Ethereum Virtual Machine (EVM),” according to Monax CEO Casey Kuhlman.

Let’s burrow into Burrow

  1. Consensus Engine: It has something called an application engine which is responsible for maintaining the networking stack.
  2. Application Blockchain Interface (ABCI): Allows application engine and consensus engine to communicate and allows developers to write smart contracts in any language
  3. Smart contract application engine: provides application builders with a strongly deterministic smart contract engine for operating complex industrial processes.
  4. Gateway: provides programmatic interfaces for system integrations and user interfaces
  5. Permissioned Ethereum Virtual Machine: It brings permissions to Ethereum Blockchain, and it is built to observe the Ethereum operation code specification that ensures assertion of correct permissions have been granted
  6. Application Binary Interface (ABI): Any Transaction that is on Blockchain has to be formulated into a binary format that can be processed by the blockchain node, ABI allows us to do that.
  7. Cryptographically Secured Consensus: This is provided by Tendemint Protocol which achieves consensus over a known set of validators.
  8. Remote signing: Burrow has an interface for remote signing which allows and accepts client-side formulated/signed transactions

Discover and review best Blockchain softwares

Let’s BUIDL!

First of all, hold your horses and complete the prerequisites

Prerequisites

  1. Signup to IBM Cloud for free
  2. Install IBM Cloud CLI
  3. Install Docker
  4. Install Kubectl
  5. Go to your IBM Cloud Dashboard and Sign in
  6. Go to IBM Container Service and create a Cluster
  7. Install Golang 1.9.3 and set GOPATH

8. Once ready, click on your cluster, and click on worker nodes to check its public ip and note it down

9. Now to Access your cluster hosted on IBM Cloud by clicking on Access tab and follow the steps which will look similar to picture below.

10. Now by using kubectl, you will now be able to interact with you cluster on IKS

Deploy Fabric with an EVM plugin to the IBM Container Service

  1. Clone this repo
$ git clone https://github.com/SaifRehman/fabric-evm-ibm-container-service.git

2. Navigate to the directory

$ cd fabric-evm-ibm-container-service

3. Navigate to script folder

$ cd cs-offerings/scripts

4. Deploy to Fabric with an EVM plugin to the IBM Container Service

$ ./create_all.sh

5. To delete the deployment

$ ./delete_all.sh -i
Give it sometime to deploy

6. The scripts will deploy a 2 Peers (1 for each Org) and 1 orderer. The scripts will also setup a channel with the id channel1, create credentials needed to talk to the network, and finally installs & instantiates a sample chaincode.

7. Run kubectl get pods to see if all pods are running fine

8. Copy crypto-config folder from one of the pod to localhost. This could be any pod

$ kubectl cp <pod name>:/shared/crypto-config crypto-config

9. Open fabric-cluster.ymlfile and edit

10. Find and replace <path-to-crypto-config-folder> in the file with crypto-config directory

11. Find and replace <cluster-ip> in the file with cluster ip of your cluster

12. This you can get by running this command

$ bx cs workers <cluster-name>

Running a proxy to deploy Ethereum smart contract to Fabric

  1. Navigate to GOPATH
$ cd $GOPATH

2. Navigate to github.com directory

$ cd src/github.com

3. Create a folder called hyperledger

$ mkdir hyperledger

4. Navigate to hyperledger directory

$ cd hyperledger

5. Clone the repo at that path

$ git clone https://github.com/SaifRehman/fabric-chaincode-evm.git

6. Run the proxy

$ ETHSERVER_CONFIG=<path-to-fabric-cluster.yml-you-configured>/fabric-cluster.yml go run main.go

Create and deploy Ethereum smart contract on Fabric

  1. Clone the repo
$ git clone https://github.com/SaifRehman/fabric-web3.git

2. Navigate to the directory

$ cd fabric-web3

3. Install all dependencies

$ npm i 

4. Sample smart contract, with a simple setter and a getter function

5. Deploy this contract to Remix IDE to get its ABI and ByteCode

6. Go to RemixIDE

7. Paste in the solidity code, select run tab, from environment select javascript vm, and click on Deploy

8. Go to compile tab and click on detail to get ABI and ByteCode

9. Look at sample app.js code for reference

10. Run app.js

$ node app.js

11. This will create and deploy the smart contract over fabric, and then call set and get function defined in solidty smart contract

NOTE: Once deployed you may just get the contract address to call set and get function from solidity again, instead of redeploying it.

myContract = Contract.at(web3.eth.getTransactionReceipt(deployedContract.transactionHash).ContractAddress) // this code gets the contract address

Limitations

  1. Doesn’t support cluster with many worker since deployment uses local storage
  2. Doesn’t support truffle and geth
  3. Not stable for production use
  4. Only support Web3 to interact with Ethereum proxy
  5. Only support GO 1.9.3

To DO

  1. Support geth and truffle
  2. Adding more support to EVM
  3. Building more examples
  4. Adding support for NFS for deployment to cluster which support many nodes

Credit

  • Monax for creating this awsome project called Hyperledger Burrow
  • Hyperledger for creating EVM chaincode plugin to deploy Ethereum smart contract on Fabric
  • Tendermint for creating Proof of Stake pluggable consensus that is being used by Hyperledger Burrow
  • Swetha Repakula, she is one of the open source developer for Hyperledger Fabric project, I used her scripts to deploy EVM pluggable Fabric to IBM Container Service. She also helped me out to overcome some of the road blocks on deploying this project. I will be contributing to her work for bringing more EVM functionality to this project.

Read more:

  1. Follow me for more: https://www.engineerability.com

Resources

  1. Hyperledger Burrow

2. Tendermint Protocol

3. More on Tendermint Protocol

4. Hyperledger Fabric

--

--