Skip to content

Voting DApp using Web3, Solidity, Hyperledger Fabric and Chaincode EVM

License

Notifications You must be signed in to change notification settings

hovig/web3-fabric-voting-dapp

Repository files navigation

Blockchain DApp - {Web3, Ethereum, Solidity, Hyperledger Fabric, Chaincode EVM}

Simple Web3 Hyperledger Fabric - Hyperledger Burrow EVM Voting Decentralized Application

With few clicks, run smart contracts from Solidity onto Ethereum Virtual Machine (EVM) that is embedded into Hyperledger Fabric to compiles these contracts as bytecode, of course, with the help of the chaincode.



Experience Ethereum into the world of permissioned platform of Hyperledger Fabric. This interaction is done through Hyperledger Chaincode EVM hosting Fabric Network.

Let's consider the followings:

  1. Hyperledger Chaincode EVM
    1.1. Chaincode is written in Go and is a wrapper around the Hyperledger Burrow EVM implementation which can run compiled Solidity smart contracts
  2. Fab3
    2.1. This is partial implementation of the Ethereum JSON RPC API
    2.2. Fab3 interacts with the EVM Chaincode and queries the ledger
    2.3. Uses the Fabric Go SDK to implement Fab3
  3. Voting DApp
    3.1. Node.js based, written in Javascript
    3.2. Uses Web3 library to process smart contracts' deployments
    3.3. Uses Solidity as a language to write the smart contracts
    3.4. Placeholder of all interactions

What you will learn:
. Setup/install a decentralized app with: Fabric, Chaincode EVM and Fab3
. Writing, deploying and compiling Solidity smart contracts
. Vote and display the polls on a simple web page



Before we start

Make sure to have the following prerequisite tools are installed on your machine: NPM, Node, Go, Docker. Their versions used for this code (respectively): v6.4.1, v10.10.0, v1.9.3 darwin/amd64, v18.06.1-ce.

These scripts in this project have been tried and are macOS compatible but if there are machine issues, then follow the steps here to bring up the needed containers, peers and fab3 proxy up and running.

STEPS (OR for manual steps - click here)


Read the full tutorial on how to build this application:

Note: Take into consideration that running ./start/sh will remove existing docker containers and images. If there are no containers or images on your machine, you can comment out the docker stop, rm and rmi in start.sh. The script is removing and adding docker compose yaml file that creates volume for fabric-chaincode-evm, adding needed repos for this project and chmod is to access/enable a file in the cloned repos to be executed.

  • STEP 1 - ./start.sh - run this script file

  • STEP 2 - copy/paste the following sections in the same terminal:

1) # COPY/PASTE THIS SECTION IN THE TERMINAL

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt


2) # COPY/PASTE THIS SECTION IN THE TERMINAL

peer chaincode install -n evmcc -l golang -v 0 -p github.com/hyperledger/fabric-chaincode-evm/evmcc
peer chaincode instantiate -n evmcc -v 0 -C mychannel -c '{"Args":[]}' -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  • STEP 3 - ./proxy.sh - run this script file in a new terminal. The fab3 proxy will be available at localhost:5000.

  • In a different terminal, go back to the project's folder and run the web app locally by doing:

1) npm install
2) npm start

Open your browser at localhost:3000 to view the app.






References

License

Apache 2.0