GithubHelp home page GithubHelp logo

ibm / evote Goto Github PK

View Code? Open in Web Editor NEW
322.0 13.0 166.0 74.79 MB

A voting application that leverages Hyperledger Fabric and the IBM Blockchain Platform to record and tally ballots.

Home Page: https://developer.ibm.com/patterns/how-to-create-a-secure-e-voting-application-on-hyperledger-fabric/

License: Apache License 2.0

JavaScript 76.89% HTML 0.83% Vue 22.28%
hyperledger-fabric blockchain vuejs node-js kubernetes

evote's Introduction

WARNING: This repository is no longer maintained ⚠️

This repository will not be updated. I will check periodically for pull requests, but do not expect a quick response.

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

NOTE: This developer pattern creates a blockchain network on IBM Blockchain Platform version 2.5 using the Hyperledger Fabric version 1.4.



Have you ever wondered how exactly the votes in a presidential election counted? What if instead of having volunteers that are spending hours a day counting votes manually, we have an app that was backed by blockchain, recording each vote made by a voter, ensuring double-voting is not possible? That's what this code pattern explains how to do. We aim to build a web-app in which the voter can register with their drivers license, get a unique voterId which is used to login to the app, and cast the vote. The vote is tallied on the blockchain, and the web-app shows the current standings of the polls.

Voting using Public Key Infrastructure

At the start of the application, the user registers to vote by providing their drivers license number, registrar district, and first and last name. In this step, we can check to see if the drivers license is valid, and has not been registered previously. If all goes well, we create a private and public key for the voter with our certificate authority that is running on the cloud, and add those keys to the wallet. To read more about public key infrastructure, and how Hyperledger Fabric implements identity using this technology, go here.

After that, we use our drivers license number to submit our vote, during which the application checks if this drivers license number has voted before and tells the user they have already submitted a vote if so. If all goes well, the political party which the voter has chosen is given a vote, and the world state is updated. The application then updates our current standings of the election to show how many votes each political party currently has.

Since each transaction that is submitted to the ordering service must have a signature from a valid public-private key pair, we can trace back each transaction to a registered voter of the application, in the case of an audit.

In conclusion, although this is a simple application, the developer can see how they can implement a Hyperledger Fabric web-app to decrease the chance of election-meddling, and enhance a voting application by using blockchain technology.

When the reader has completed this code pattern, they will understand how to:

  • Create, build, and use the IBM Blockchain Platform service.
  • Build a blockchain back-end using Hyperledger Fabric API's
  • Create and use a (free) Kubernetes Cluster to deploy and monitor our Hyperledger Fabric nodes.
  • Deploy a Node.js app that will interact with our deployed smart contract.

Flow Diagram



Flow Description

  1. The blockchain operator sets up the IBM Blockchain Platform 2.5 service.
  2. The IBM Blockchain Platform 2.5 creates a Hyperledger Fabric network on an IBM Kubernetes Service, and the operator installs and instantiates the smart contract on the network.
  3. The Node.js application server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform 2.5 and creates APIs for a web client.
  4. The Vue.js client uses the Node.js application API to interact with the network.
  5. The user interacts with the Vue.js web interface to cast their ballot and and query the world state to see current poll standings.

Included components

  • IBM Blockchain Platform gives you total control of your blockchain network with a user interface that can simplify and accelerate your journey to deploy and manage blockchain components on the IBM Cloud Kubernetes Service.
  • IBM Cloud Kubernetes Service creates a cluster of compute hosts and deploys highly available containers. A Kubernetes cluster lets you securely manage the resources that you need to quickly deploy, update, and scale applications.
  • IBM Blockchain Platform Extension for VS Code is designed to assist users in developing, testing, and deploying smart contracts -- including connecting to Hyperledger Fabric environments.

Featured technologies

  • Hyperledger Fabric v1.4 is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability.
  • Node.js is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
  • Vue.js 2.6.10 Vue.js is an open-source JavaScript framework for building user interfaces and single-page applications.

Watch the Video - Intro (Cloud)

Watch the Video - Build and Run the App (Cloud)

Watch the Video - Code walkthrough (User Authentication)

Watch the Video - Code walkthrough (Routes)

Prerequisites (Cloud)

This Cloud pattern assumes you have an IBM Cloud account.

You do not technically need VSCode or the IBM Blockchain Platform extension for VSCode if you are running the Cloud pattern, but if you want to make any changes to the smart contract, you will need the extension to package your smart contract project.

Prerequisites (Local)

If you want to run this pattern locally, without any Cloud services, then all you need is VSCode and the IBM Blockchain Platform extension.

🚧🚧Note: you will need Node 8.x to run this pattern!🚧🚧

For example, to install and run Node 8.9.0:

  brew install nvm
  nvm install 8.9.0
  nvm use 8.9.0

Steps (Local Deployment)

To run a local network, you can find steps here.

Steps (Cloud Deployment)

  1. Clone the Repo
  2. Create IBM Cloud services
  3. Build a network
  4. Deploy voterContract Smart Contract on the network
  5. Connect application to the network
  6. Run the application

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. Create IBM Cloud services

  • Create the IBM Cloud Kubernetes Service. You can find the service in the Catalog. For this code pattern, we can use the Free cluster, and give it a name. Note, that the IBM Cloud allows one instance of a free cluster and expires after 30 days. The cluster takes around 20 minutes to provision, so please be patient!


  • Create the IBM Blockchain Platform service on the IBM Cloud. You can find the service in the Catalog, and give a name.

  • After your Kubernetes cluster is up and running, you can deploy your IBM Blockchain Platform service on the cluster. The service walks through few steps and finds your cluster on the IBM Cloud to deploy the service on.

  • In the gif below, you can see me choosing my free cluster to deploy my IBM Blockchain Platform.

  • Once the Blockchain Platform is deployed on the Kubernetes cluster (which can take a couple of minutes, you can launch the console to start operating on your blockchain network by clicking on Launch the IBM Blockchain Platform.



Step 3. Build a network

We will build a network as provided by the IBM Blockchain Platform documentation. This will include creating a channel with a single peer organization with its own MSP and CA (Certificate Authority), and an orderer organization with its own MSP and CA. We will create the respective identities to deploy peers and operate nodes.

Create your organization and your entry point to your blockchain

  • Create your Voter Organization CA

    • Navigate to the Nodes tab in the left navigation and click Add Certificate Authority +.
    • Click Create a Certificate Authority + and click Next.
    • Give it a CA display name of Voter CA, a CA administrator enroll ID of admin and a CA administrator enroll secret of adminpw, then click Next.
    • Review the summary and click Add Certificate Authority.


  • Associate the voter organization CA admin identity

    • In the Nodes tab, select the Voter CA once it is running (indicated by the green box in the tile).
    • Click Associate identity on the CA overview panel.
    • On the side panel, select the Enroll ID tab.
    • Provide an Enroll ID of admin and an Enroll secret of adminpw. Use the default value of Voter CA Admin for the Identity display name.
    • Click Associate identity to add the identity into your wallet and associate the admin identity with the Voter CA.


  • Use your CA to register identities

    • Select the Voter CA Certificate Authority and ensure the admin identity that was created for the CA is visible in the table.
    • The next step is to register an admin for the organization "Voter". Click on the Register User + button. Give an Enroll ID of voterAdmin and an Enroll secret of voterAdminpw. Set the Type for this identity as admin. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
    • Skip the section to add attributes to this user and click Register user.
    • Repeat the process to create an identity of the peer. Click on the Register User + button. Give an Enroll ID of peer1 and an Enroll secret of peer1pw. Set the Type for this identity as peer. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
    • Skip the section to add attributes to this user and click Register user.


  • Create the peer organization MSP definition

    • Navigate to the Organizations tab in the left navigation and click Create MSP definition +.
    • Enter the MSP display name as Voter MSP and the MSP ID as votermsp. Click Next.
    • Specify Voter CA as the Root Certificate Authority. Click Next.
    • Select the New identity tab. Give the Enroll ID and Enroll secret for your organization admin, i.e. voterAdmin and voterAdminpw respectively. Then, give the Identity name as Voter Admin.
    • Click the Generate button to enroll this identity as the admin of your organization and add the identity to the wallet. Click Export to export the admin certificates to your file system. Click Next.
    • Review all the information and click Create MSP definition.


  • Create a peer

    • Navigate to the Nodes tab in the left navigation and click Add peer +.
    • Click Create a peer + and then click Next.
    • Give the Peer display name as Voter Peer and click Next.
    • On the next screen, select Voter CA as the Certificate Authority. Then, give the Peer enroll ID and Peer enroll secret as peer1 and peer1pw respectively. Select the Organization MSP as Voter MSP. Leave the TLS CSR hostname blank and select 1.4.7-0 in the drop-down for Fabric version. Click Next.
    • Provide Voter Admin as the Peer administrator identity and click Next.
    • Review the summary and click Add peer.


Create the node that orders transactions

  • Create your orderer organization CA

    • Navigate to the Nodes tab in the left navigation and click Add Certificate Authority +.
    • Click Create a Certificate Authority + and click Next.
    • Give it a CA display name of Orderer CA, a CA administrator enroll ID of admin and a CA administrator enroll secret of adminpw, then click Next.
    • Review the summary and click Add Certificate Authority.


  • Associate the orderer organization CA admin identity

    • In the Nodes tab, select the Orderer CA once it is running (indicated by the green box in the tile).
    • Click Associate identity on the CA overview panel.
    • On the side panel, select the Enroll ID tab.
    • Provide an Enroll ID of admin and an Enroll secret of adminpw. Use the default value of Orderer CA Admin for the Identity display name.
    • Click Associate identity to add the identity into your wallet and associate the admin identity with the Orderer CA.


  • Use your CA to register orderer and orderer admin identities

    • Select the Orderer CA Certificate Authority and ensure the admin identity that was created for the CA is visible in the table.
    • The next step is to register an admin for the organization "Orderer". Click on the Register User + button. Give an Enroll ID of ordererAdmin and an Enroll secret of ordererAdminpw. Set the Type for this identity as admin. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
    • Skip the section to add attributes to this user and click Register user.
    • Repeat the process to create an identity of the orderer. Click on the Register User + button. Give an Enroll ID of orderer1 and an Enroll secret of orderer1pw. Set the Type for this identity as orderer. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
    • Skip the section to add attributes to this user and click Register user.


  • Create the orderer organization MSP definition

    • Navigate to the Organizations tab in the left navigation and click Create MSP definition +.
    • Enter the MSP display name as Orderer MSP and the MSP ID as orderermsp. Click Next.
    • Specify Orderer CA as the Root Certificate Authority. Click Next.
    • Select the New identity tab. Give the Enroll ID and Enroll secret for your organization admin, i.e. ordererAdmin and ordererAdminpw respectively. Then, give the Identity name as Orderer Admin.
    • Click the Generate button to enroll this identity as the admin of your organization and add the identity to the wallet. Click Export to export the admin certificates to your file system. Click Next.
    • Review all the information and click Create MSP definition.


  • Create an orderer

    • Navigate to the Nodes tab in the left navigation and click Add ordering service +.
    • Click Create an ordering service + and then click Next.
    • Give the Ordering service display name as Orderer and click Next.
    • On the next screen, select Orderer CA as the Certificate Authority. Then, give the Ordering service enroll ID and Ordering service enroll secret as orderer1 and orderer1pw respectively. Select the Organization MSP as Orderer MSP. Leave the TLS CSR hostname blank and select 1.4.7-0 in the drop-down for Fabric version. Click Next.
    • Provide Orderer Admin as the Orderer administrator identity and click Next.
    • Review the summary and click Add ordering service.


  • Add organization as Consortium Member on the orderer to transact

    • Navigate to the Nodes tab, and click on the Orderer that was created.
    • Under Consortium Members, click Add organization +.
    • Select the Existing MSP ID tab. From the drop-down list, select Voter MSP (votermsp), as this is the MSP that represents the peer's organization "Voter".
    • Click Add organization.


Create and join channel

  • Create the channel

    • Navigate to the Channels tab in the left navigation and click Create channel +.
    • Click Next.
    • Give the Channel name as mychannel. Select Orderer from the Ordering service drop-down list. Click Next.
    • Under Organizations, select Voter MSP (votermsp) from the drop-down list to add the organization "Voter" as a member of this channel. Click the Add button. Set the permissions for this member as Operator. Click Next.
    • Leave the Policy as the default value i.e. 1 out of 1. Click Next.
    • Select the Channel creator MSP as Voter MSP (votermsp) and the Identity as Voter Admin. Click Next.
    • Review the summary and click Create channel.


  • Join your peer to the channel

    • Click on the newly created channel mychannel.
    • In the side panel that opens, under Choose from available peers, select Voter Peer. Once the peer is selected, a check mark will be displayed next to it. Ensure that Make anchor peer(s) is marked as Yes. Click Join channel.


Step 4. Deploy voterContract Smart Contract on the network

  • Install a smart contract

    • Navigate to the Smart contracts tab in the left navigation and click Install smart contract +.
    • Click on Add file.
    • Browse to the location of the voterContract smart contract package file, which is in the root of the repo we cloned - the file is called voterContract.cds.
    • Once the contract is uploaded, click Install smart contract.


  • Instantiate smart contract

    • Under Installed smart contracts, find the smart contract from the list (Note: ours is called voterContract) installed on our peer and click Instantiate from the overflow menu on the right side of the row.
    • On the side panel that opens, select the channel, mychannel on which to instantiate the smart contract. Click Next.
    • Select Voter MSP as the organization member to be included in the endorsement policy. Click Next.
    • Skip the Setup private data collection step and simply click Next.
    • Give the Function name as init and leave the Arguments blank. Note: init is the method in the voterContract.js file that initiates the smart contracts on the peer.
    • Click Instantiate smart contract.


Step 5. Connect application to the network

  • Connect with sdk through connection profile

    • Navigate to the Organizations tab in the left navigation, and click on Voter MSP.
    • Click on Download Connection Profile.
    • In the side panel that opens up, select Yes as the response for Include Voter CA for user registration and enrollment?. Under Select peers to include, select Voter Peer. Then click Download connection profile. This will download the connection json which we will use to establish a connection between the Node.js web application and the Blockchain Network.


  • Create an application admin

    • Navigate to the Nodes tab in the left navigation, and under Certificate Authorities, choose Voter CA.
    • Click on the Register User + button. Give an Enroll ID of app-admin and an Enroll secret of app-adminpw. Set the Type for this identity as client. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
    • Click on Add attribute +. Enter the attribute name as hf.Registrar.Roles and the attribute value as *. Click Register user.


  • Update application connection

    • Copy the connection profile you downloaded into server folder
    • Rename the connection profile you downloaded ibpConnection.json
    • Update the config.json file with:
      • ibpConnection.json.
      • The enroll id and enroll secret for your app admin, which we earlier provided as app-admin and app-adminpw.
      • The orgMSP ID, which we provided as votermsp.
      • The caName, which can be found in your connection json file under "organizations" -> "votermsp" -> certificateAuthorities". This would be like an IP address and a port. You should also use the https version of the certificateAuthorities line.
      • The username you would like to register.
      • Update gateway discovery to { enabled: true, asLocalhost: false } to connect to IBP.


  • Once you are done, the final version of the config.json should look something like this:
{
    "connection_file": "ibpConnection.json",
    "appAdmin": "app-admin",
    "appAdminSecret": "app-adminpw",
    "orgMSPID": "votermsp",
    "caName": "https://173.193.106.28:32634",
    "userName": "V1",
    "gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}

Step 6. Run the application

  • Enroll admin

    • First, navigate to the web-app/server directory, and install the node dependencies.

      cd web-app/server
      npm install
    • Run the enrollAdmin.js script

      node enrollAdmin.js
    • You should see the following in the terminal:

      msg: Successfully enrolled admin user app-admin and imported it into the wallet
    • Start the server:

      npm start


  • Start the web client

    • In a new terminal, open the web-app/client folder from the root directory. Install the required dependencies with npm install.

      cd web-app/client
      npm install
    • Start the client:

      npm run serve
    • In a browser of your choice, go to http://localhost:8080/#/. If all goes well, you should see something like the gif below:



You can find the app running at http://localhost:8080/ If all goes well, you should be greeted with the homepage that says 2020 Presidential Election

Now, we can start interacting with the app.

First, we need to register as a voter, and create our digital identity with which we will submit our vote with. To do this, we will need to enter a uniqueId (drivers license) with a registrarId, and our first and last names. After we do that, and click register the world state will be updated with our voterId and our name and registrarId.

If all goes well, you should see voter with voterId {} is updated in the world state. Use voterId to login above. Note: on the first try, the app can take a second to start up. If you click on register and nothing happens, try to fill in the form and click register again!

Next, we can login to the app with our voterId.

Once we login, we can cast our vote. We will use our voterId again to cast our vote. Since we are voting for the presidential election for 2020, we can choose the party of our liking. Once we are done, we can choose submit, and then our vote is cast. As long as this voterId hasn't voted before, all is well. Next, we can view the poll standings by clicking Get Poll Standings and clicking Check Poll. This will query the world state and get the current number of votes for each political party.



If we want to query for a particular voterId, we can do so in the Query by Key tab. If we want to query by object, we can do so by clicking on the Query by Type tab, and entering a type, such as voter. This will return all voter objects that are currently in the state. QueryAll will return all objects in the state.



Extending the code pattern

Pull requests and contribution are always welcome. Remember that a code pattern is a path to a solution, and not a complete solution on its own. To make this a more complete solution, this application can be expanded in a couple of ways:

  • Use an API to verify the drivers license to make sure it is valid, and registered with the DMV.
  • Use a more complex consensus mechanism where multiple organizations (DMV, US Federal Government, US State Government) have to approve a vote before it is successfully recorded onto the blockchain.
  • Use ordering service which uses Raft consensus mechanism.

Troubleshooting

  • If you get an error that says Error: Calling register endpoint failed with error [Error: self signed certificate], you can get past this by adding "httpOptions": {"verify": false} to the certificateAuthorities section of the connection profile that was downloaded from IBM Blockchain Platform.




Related Links

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

evote's People

Contributors

chrisnosowsky avatar horeaporutiu avatar pratikspatil024 avatar sandhya-nayak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

evote's Issues

Unable to cast vote

I did a local installation but I am unable to cast vote. Query all assets gives the following output:

0000 | { "ballotCreated": false, "firstName": "jfgkl", "lastName": "jgfkl", "registrarId": "7890", "type": "voter", "voterId": "0000" }

0001 | { "ballotCreated": false, "firstName": "fghjkl", "lastName": "fghjkl", "registrarId": "56789", "type": "voter", "voterId": "0001" }

Starting server

When runing npm start, to run the server I receive the following error:

image

Smart Contract Not Compatible with IBM Blockchain Platform 2.5 using Fabric 2.x Images

The smart contract uses an older shim level that is not supported with Hyperledger Fabric 2.x images.

Fabric runtimes that use Fabric 2.x images have Node version 12 instead of Node version 8 which is used in Fabric 1.4.x runtimes.

The smart contract fabric-contract-api & fabric-shim node modules must be at v1.4.5 or greater to work with Fabric 2.x images.

This is from the smart contract package.json:

"dependencies": {
"fabric-contract-api": "1.4.1",
"fabric-shim": "^1.4.1",
"mem": "^5.1.1",
"os-locale": "^4.0.0"
},

This should be updated to:

"dependencies": {
"fabric-contract-api": "1.4.5",
"fabric-shim": "^1.4.5",
"mem": "^5.1.1",
"os-locale": "^4.0.0"
},

Unable to Cast Ballot

Hi @horeaporutiu, thank you for sharing this code.

I was able to register a drivers license, but unable to cast a ballot.
I'm receiving the following error upon submission:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler (Promise/async): "TypeError: Cannot read property 'Key' of undefined"

found in

---> <Response> at src/components/CastBallot.vue

The data array from await PostsService.queryWithQueryString('election') is empty.
Could you point me in right direction on what could I do to fix it?
Screenshot from 2020-01-29 15-46-45

FileSystemWallet is not a constructor

Good day all,

Kindly assist with this error:

PS C:\Users\CCSA\Desktop\evote-master\web-app\server> node enrollAdmin.js
Failed to enroll admin user ' + app-admin + : TypeError: FileSystemWallet is not a constructor
FileSystemWallet_Error

Thank-you!

Adding Function to Smart Contract

Hello! I am trying to add a function in the voterContract file but I am getting errors saying that the contract does not exist. I even tore down the environment, packaged the new contract and installed and instantiated it. I did another test where I changed the castVote function in the voterContract file to castVote_t. Then, in app.js, I changed castVote to castVote_t. Everything should work because all I did was change the function name, but it is getting to the invoke function in networks.js, gets to console.log('before submit'), but errors at await networkObj.contract.submitTransaction(func, args).

Not sure why this is happening. Does it have to do something with the endorsement policy? Please help.

Below is the error log:
notQuery
notQuery, args
$$$$$$$$$$$$$ args:
[ '{"electionId":"5ltlrbqlk58kou4ujakgb","voterId":"b","picked":"asdf"}' ]
castVote_t
object
{ electionId: '5ltlrbqlk58kou4ujakgb',
voterId: 'b',
picked: 'asdf' }
'{"electionId":"5ltlrbqlk58kou4ujakgb","voterId":"b","picked":"asdf"}'
before submit 1
{ contract:
Contract {
network:
Network {
gateway: [Object],
channel: [Object],
contracts: [Object],
initialized: true,
listeners: Map {},
queryHandler: [Object],
checkpointer: [Object],
eventHubSelectionStrategy: [Object],
eventHubManager: [Object] },
channel:
Channel {
_name: 'mychannel',
_channel_peers: [Object],
_anchor_peers: [],
_orderers: [Object],
_kafka_brokers: [],
_clientContext: [Object],
_msp_manager: [Object],
_discovery_interests: [Object],
_discovery_results: [Object],
_last_discover_timestamp: 1611854570667,
_use_discovery: true,
_as_localhost: true,
_endorsement_handler: [Object],
_commit_handler: [Object],
_last_refresh_request: [Object] },
chaincodeId: 'voterContract',
gateway:
Gateway {
client: [Object],
wallet: null,
networks: [Object],
options: [Object],
currentIdentity: [Object] },
namespace: '',
checkpointer: { factory: [Function: FILE_SYSTEM_CHECKPOINTER], options: {} } },
network:
Network {
gateway:
Gateway {
client: [Object],
wallet: null,
networks: [Object],
options: [Object],
currentIdentity: [Object] },
channel:
Channel {
_name: 'mychannel',
_channel_peers: [Object],
_anchor_peers: [],
_orderers: [Object],
_kafka_brokers: [],
_clientContext: [Object],
_msp_manager: [Object],
_discovery_interests: [Object],
_discovery_results: [Object],
_last_discover_timestamp: 1611854570667,
_use_discovery: true,
_as_localhost: true,
_endorsement_handler: [Object],
_commit_handler: [Object],
_last_refresh_request: [Object] },
contracts: Map { 'voterContract:' => [Object] },
initialized: true,
listeners: Map {},
queryHandler: SingleQueryHandler { _peers: [Array], _currentPeerIndex: 0 },
checkpointer: { factory: [Function: FILE_SYSTEM_CHECKPOINTER], options: {} },
eventHubSelectionStrategy: RoundRobinEventHubSelectionStrategy { peers: [Array], lastPeerIdx: null },
eventHubManager:
EventHubManager {
channel: [Object],
eventHubFactory: [Object],
eventHubSelectionStrategy: [Object],
newEventHubs: [] } },
gateway:
Gateway {
client:
Client {
_cryptoSuite: [Object],
_clientConfigMspid: 'Org1MSP',
_stateStore: [Object],
_userContext: [Object],
_network_config: [Object],
_msps: Map {},
_devMode: false,
_adminSigningIdentity: null,
_tls_mutual: [Object],
_organizations: Map {},
_certificateAuthorities: Map {},
_channels: [Object],
_connection_options: {} },
wallet: null,
networks: Map { 'mychannel' => [Object] },
options:
{ queryHandlerOptions: [Object],
eventHandlerOptions: [Object],
discovery: [Object],
checkpointer: [Object],
eventHubSelectionOptions: [Object],
wallet: [Object],
identity: 'b' },
currentIdentity:
User {
_name: 'b',
_roles: null,
_affiliation: '',
_enrollmentSecret: '',
_identity: [Object],
_signingIdentity: [Object],
_mspId: 'Org1MSP',
_cryptoSuite: [Object] } } }
****func:
castVote_t
2021-01-28T17:22:50.716Z - warn: [DiscoveryEndorsementHandler]: _build_endorse_group_member >> G0:0 - endorsement failed - Error: transaction returned with failure: Error: You've asked to invoke a function that does not exist: castVote_t
Failed to submit transaction: Error: Endorsement has failed
response:
{ Error: Endorsement has failed
at DiscoveryEndorsementHandler._endorse (/Users/Kevin/p2osu/web-app/server/node_modules/fabric-network/node_modules/fabric-client/lib/impl/DiscoveryEndorsementHandler.js:184:19)
at
endorsements:
[ { Error: transaction returned with failure: Error: You've asked to invoke a function that does not exist: castVote_t
at self._endorserClient.processProposal (/Users/Kevin/p2osu/web-app/server/node_modules/fabric-network/node_modules/fabric-client/lib/Peer.js:140:36)
at Object.onReceiveStatus (/Users/Kevin/p2osu/web-app/server/node_modules/grpc/src/client_interceptors.js:1207:9)
at InterceptingListener._callNext (/Users/Kevin/p2osu/web-app/server/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/Users/Kevin/p2osu/web-app/server/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/Users/Kevin/p2osu/web-app/server/node_modules/grpc/src/client_interceptors.js:845:24)
status: 500,
payload: ,
peer: [Object],
isProposalResponse: true } ] }
::ffff:127.0.0.1 - - [28/Jan/2021:17:22:50 +0000] "POST /castBallot HTTP/1.1" 200 1754 "http://localhost:8080/?" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0"

Unable to validate parameter due to ["should be string"]

Hello,

I am have implemented everything correctly and now trying to work some examples, I am making request and getting this error
2020-10-26T21:32:35.962Z - warn: [DiscoveryEndorsementHandler]: _build_endorse_group_member >> G0:0 - endorsement failed - Error: error in simulation: transaction returned with failure: Error: Unable to validate parameter due to ["should be string"] Failed to submit transaction: Error: Endorsement has failed after network.invoke Error: Endorsement has failed

Idk why this happening, I successfully generated wallet for app-admin,
my config.json

{ "connection_file": "ibpConnection.json", "appAdmin": "app-admin", "appAdminSecret": "secret", "orgMSPID": "org1msp", "caName": "https://{secretCname}", "userName": "V1", "gatewayDiscovery": { "enabled": true, "asLocalhost": false } }

also when I made app-admin user in CA I added attributes also.
So I think problem is in contracts, I have tried to generate contracts correctly from VS code but exactly can't understand how to export, can someone link me correct way to export contracts correctly to upload on IBM platform later?

Runtime NPM Issue

I haven't been able to run the projcect locally I install NPM but whenever I start npm
it shows the following error

C:\Users\akshat\evote\web-app\server>npm install
npm WARN [email protected] requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

audited 2359 packages in 42.46s
found 18 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

C:\Users\akshat\evote\web-app\server>npm start

> [email protected] start C:\Users\akshat\evote\web-app\server
> ./node_modules/nodemon/bin/nodemon.js src/app.js

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `./node_modules/nodemon/bin/nodemon.js src/app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\akshat\AppData\Roaming\npm-cache\_logs\2020-04-07T11_45_12_000Z-debug.log

C:\Users\akshat\evote\web-app\server>

I haven't been able to figure out how to solve this issue.
I tried to use NPM 8.9.0 and it brings up the same issue and more


C:\Users\akshat\evote\web-app\server>npm install
npm WARN [email protected] requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm ERR! path C:\Users\akshat\evote\web-app\server\node_modules\grpc\node_modules\abbrev
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\akshat\evote\web-app\server\node_modules\grpc\node_modules\abbrev' -> 'C:\Users\akshat\evote\web-app\server\node_modules\grpc\node_modules\.abbrev.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\akshat\AppData\Roaming\npm-cache\_logs\2020-04-07T12_16_57_399Z-debug.log

So am I missing something

Detailed Guide to understand your code

Good Morning Sir
Could you please provide me with some detailed guide to understand your code?
Like how things are working from the very basic, and which components are connected to which one, and how these are working interconnectively.
Please revert back asap.

can't add consortium

I'm using blockchain to create a voting app but i can't add the consortium because the add organization is grayed out, what may be the problem?
consortium

node v12.6.0 not ok?

I tried "npm install" and got the following errors, I need change node v12.x to node v8.x, right?
make: *** [x509.target.mk:112:Release/obj.target/x509/src/addon.o] error 1
make: leaving “/home/.../evote/contract/node_modules/@ampretia/x509/build”
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/.../.nvm/versions/node/v12.6.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:203:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 5.1.18-1-MANJARO
gyp ERR! command "/home/.../.nvm/versions/node/v12.6.0/bin/node" "/home/.../.nvm/versions/node/v12.6.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/.../evote/contract/node_modules/@ampretia/x509
gyp ERR! node -v v12.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ampretia/[email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ampretia/[email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

while starting the server

Hi,
I am getting this error while starting the server : listen EADDRINUSE: address already in use :::8081
Can you tell me the reason for this error?? and also after successfully getting this should we type in some command before starting the client??
Screenshot from 2020-06-11 19-56-32

Screenshot from 2020-06-11 20-15-18

PLEASE HELP

Hi
could you please tell me how can I run this on multiple nodes to get some research-based results like in the attachment below?
result

Server not starting

PS C:\Users\Sasindu Fdo\Desktop\IBM Test\evote\web-app\server> npm run start
Debugger listening on ws://127.0.0.1:60526/c8d8f66a-e30a-4ffe-8fd8-a959c0f8fa7f
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

[email protected] start C:\Users\Sasindu Fdo\Desktop\IBM Test\evote\web-app\server
./node_modules/nodemon/bin/nodemon.js src/app.js

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: ./node_modules/nodemon/bin/nodemon.js src/app.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sasindu Fdo\AppData\Roaming\npm-cache_logs\2020-10-07T12_40_29_657Z-debug.log

Please Resolve the issue ASAP.

Good Afternoon,
I am trying to run this project on my MacBook air.
I have followed the steps mentioned by you.
But, I am still facing an issue.

While running npm start on the terminal i am getting the following error,

[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node src/app.js`
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module 'fabric-network'
Require stack:
- /Users/adityaverma/Desktop/evote/web-app/server/src/fabric/network.js
- /Users/adityaverma/Desktop/evote/web-app/server/src/app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/adityaverma/Desktop/evote/web-app/server/src/fabric/network.js:4:56)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/adityaverma/Desktop/evote/web-app/server/src/fabric/network.js',
    '/Users/adityaverma/Desktop/evote/web-app/server/src/app.js'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

Please revert back here in the comments, or email me at [email protected]
Warm Regards to you
Aditya Verma

Protect casted vote

I was wondering how the app and the contract can be changed to protect what a voter chose but still enable anyone to check their vote was casted correctly.

[no suitable peers available to initialize from] - [error]

I got this error when querying the fabric network:

[Network]: _initializeInternalChannel: no suitable peers available to initialize from
Error processing transaction. Error: no suitable peers available to initialize from
Error: no suitable peers available to initialize from
    at Network._initializeInternalChannel (/username/repos/blockchain/evote/web-app/server/node_modules/fabric-network/lib/network.js:84:10)

Do I need anchor peers? I have the Voter Peer as the anchor. Can you please recommend a solution for this? I followed your instructions on how to create a free cluster and how to deploy a Fabric Network.

Thank you in advance.

The "options.ca" property must be one of type string, Buffer, TypedArray, or DataView. Received type object

After user registration, there is a response:

Failed to register user + E12345678 + : TypeError [ERR_INVALID_ARG_TYPE]: The "options.ca" property must be one of type string, Buffer, TypedArray, or DataView. Received type object
response from registerVoter:
{
error: TypeError [ERR_INVALID_ARG_TYPE]: The "options.ca" property must be one of type string, Buffer, TypedArray, or DataView. Received type object
at validateKeyOrCertOption (_tls_common.js:80:11)
at Object.createSecureContext (_tls_common.js:110:9)
at Object.connect (_tls_wrap.js:1403:48)
at Agent.createConnection (https.js:125:22)
at Agent.createSocket (_http_agent.js:234:26)
at Agent.addRequest (_http_agent.js:193:10)
at new ClientRequest (_http_client.js:276:16)
at Object.request (https.js:309:10)
at /Users/user/Desktop/evote/evote/web-app/server/node_modules/fabric-network/node_modules/fabric-ca-client/lib/FabricCAClient.js:306:37
at new Promise ()
}

Expected: I should register new user.

How to add new field

The voter can login just by voter id. How can I add the password and changing password functionality? In which file(s) do I have to make changes?

Has an errror querying channels while connecting to fabric environment

I have encountered an error whileee trying to start the fabric environment on Visual Studio Code
Here is the log out put
[ERROR] Error connecting to environment Local Fabric: Error: Error querying channels: Failed to connect before the deadline URL:grpc://localhost:17051

here is the output of docker ps

bb7c0e54a06d hyperledger/fabric-ca:1.4.4 "sh -c 'fabric-ca-..." 5 minutes ago Up 5 minutes 7054/tcp, 0.0.0.0:17050->17050/tcp fabricvscodelocalfabric_ca.org1.example.com

Error when start the server

Hi,
I am following the run-local steps and everything was well. But I got an error when I tried to start the server in Step 6. Here is the output:

$ npm start

[email protected] start /home/ubuntu1804/BlockChainProjects/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
fs.js:114
throw err;
^

Error: ENOENT: no such file or directory, open '/home/ubuntu1804/BlockChainProjects/evote/web-app/server/ibpConnection.json'
at Object.openSync (fs.js:438:3)
at Object.readFileSync (fs.js:343:35)
at Object. (/home/ubuntu1804/BlockChainProjects/evote/web-app/server/src/fabric/network.js:20:20)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
[nodemon] app crashed - waiting for file changes before starting...

My vscode version is 1..39.2
My IBP extension is 1.0.23

Could you please help me figure out the problem?

Thanks

no free cluster

I have an account of IBM Cloud, but I can't get the free cluster of Kubernetes Service. Why?

Couchdb

Hi sir, I see that this application uses the couchdb which has some data that I am trying to access. Unfortunately I am not being able to access as it is asking me for login credentials. Is there any way I can access c803d1c24ac7 container ID?
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.