Skip to content

Latest commit

 

History

History
186 lines (139 loc) · 6.06 KB

run-local.md

File metadata and controls

186 lines (139 loc) · 6.06 KB

Create a fair evoting application to ensure correct election results with Hyperledger Fabric and IBM Blockchain Platform (Local)

Steps (Local Deployment)

  1. Clone the Repo
  2. Start the Fabric Runtime
  3. Install Contract
  4. Instantiate Contract
  5. Export Connection Details
  6. Run the App

Note: This repo assumes you have VSCode and IBM Blockchain VSCode extension installed. If you don't, first install the latest version of VSCode, and then install the IBM Blockchain VSCode extension ensuring you have the correct system requirements to run the extension. You will need Docker as this is how the extension builds a development Hyperledger Fabric network with a click of a button.

Step 1. Clone the Repo

Git clone this repo onto your computer in the destination of your choice, then go into the web-app folder:

HoreaPorutiu$ git clone https://github.com/IBM/evote

Step 2. Start the Fabric Runtime

  • First, we need to go to our IBM Blockchain Extension. Click on the IBM Blockchain icon in the left side of VSCode (It looks like a square).

  • Next, start your local fabric by clicking on the three dot symbol to the right of LOCAL FABRIC OPS and then Start Fabric Runtime.

  • Once the runtime is finished starting (this might take a couple of minutes), under Local Fabric Ops you should see Smart Contracts and a section for both installed and instantiated.

Step 3. Install Contract

Now, let's click on + Install and choose the peer that is available. Then the extension will ask you which package to install. Choose [email protected] which is in your evote/contract directory which you just cloned.

If all goes well, you should get a notification as shown below.

packageFile

Step 4. Instantiate Contract

You guessed it. Next, it's time to instantiate.

Click on + Instantiate

and then choose mychannel for the channel to instantiate the contract on.

packageFile

Next, the extension will ask you to choose a smart contract and version to instantiate. Click on [email protected].

Next, for the optional function, type in init. packageFile

Leave the arguments blank, and hit enter on your keyboard. packageFile

This will instantiate the smart contract. You should see the contract under the instantiated tab on the left-hand side, as shown in the picture. Note: excuse the version number on the picture.

Step 5. Export Connection Details

  • Under LOCAL FABRIC OPS and Nodes, right-click on peer0.org1.example.com and select Export Connection Profile and then choose the evote/web-app/server directory.

Export Wallet

  • Under FABRIC WALLETS and Nodes, right-click on local_fabric_wallet and select Export Wallet.

  • When asked what to save the wallet as, save it as wallet, and save it in the evote/web-app/server, the same place we saved our connection profile from earlier.

Update Config

Next, update the config.json file so it looks like this:

{
  "connection_file": "local_fabric_connection.json",
  "appAdmin": "admin",
  "appAdminSecret": "adminpw",
  "orgMSPID": "Org1MSP",
  "caName": "ca.org1.example.com",
  "userName": "V1",
  "gatewayDiscovery": { "enabled": true, "asLocalhost": true }
}

This will ensure we use the admin identity that is stored in our wallet to sign transactions, and let the network know that the transactions that are coming from this certain identity were first signed off by the certificate authority with the name ca.org1.example.com.

Step 6. Run the App

To run the app, we will need to install dependencies for both our front-end and our back-end.

Start the Server

  • First, navigate to the server directory, and install the node dependencies.
    cd evote/web-app/server
    npm install
  • Then, start the server:
    npm start
  • If all goes well, you should see the following in your terminal:
      > [email protected] start /Users/[email protected]/Workdir/testDir/July7/evote/web-app/server
      > ./node_modules/nodemon/bin/nodemon.js src/app.js
    
      [nodemon] 1.19.1
      [nodemon] to restart at any time, enter `rs`
      [nodemon] watching: *.*
      [nodemon] starting `node src/app.js`  
    

Start the Front-end (Client)

  • First, navigate to the client directory, and install the node dependencies.
    cd evote/web-app/client
    npm install
  • Then, start the client:
    npm run serve
  • If all goes well, you should see the following in your terminal:
        DONE  Compiled successfully in 6803ms                                                                                             11:48:20
    
        App running at:
        - Local:   http://localhost:8080/ 
        - Network: unavailable
    
        Note that the development build is not optimized.
        To create a production build, run npm run build. 
    

Nice. We're pretty much ready to submit transactions on our contract. Go to http://localhost:8080/ to see your app.

Go ahead and register a voter, login with your VoterId, and submit a vote. Have fun! :)