IBM / blockchainbean2

This code pattern shows how to model a supply-chain network using the IBM Blockchain Platform and is based on a collaboration with Brooklyn Roasting Company. The story, along with the supply-chain documents that were used to model this network, can be found at: https://www.ibm.com/blockchainbean. Note that the 'view the blockchain' button is being migrated''
https://developer.ibm.com/patterns/coffee-supply-chain-network-hyperledger-fabric-blockchain-2/
122 stars 84 forks source link

NPM start not starting local server #9

Closed Vishnupriya-M closed 5 years ago

Vishnupriya-M commented 5 years ago

image

horeaporutiu commented 5 years ago

@Vishnupriya-M I've just done a fresh git clone, and tried to start the server, and everything is working fine.

What operating system are you using? Also, go ahead and try a fresh git clone and see if that changes anything - I've made some changes to the code base in the last few days.

Screen Shot 2019-03-25 at 10 36 11 AM
Vishnupriya-M commented 5 years ago

@horeaporutiu Thank you.I have done the same and got right output.But now encountering an error while adding members to the network as shown below: Screenshot from 2019-04-01 23-10-46 Screenshot from 2019-04-01 23-10-00

horeaporutiu commented 5 years ago

looks like there is a problem with the user1 identity. Have you run the registerUser script to enroll your user1? Should be this step - https://github.com/IBM/blockchainbean2#step-8-run-the-application

if you get an error when running the registerUser script, just go into the config.json file and change the userName to be user4 or another user, and then try it again.

Best, Horea

On Mon, Apr 1, 2019 at 10:43 AM Vishnupriya-M notifications@github.com wrote:

@horeaporutiu https://github.com/horeaporutiu Thank you.I have done the same and got right output.But now encountering an error while adding members to the network as shown below: [image: Screenshot from 2019-04-01 23-10-46] https://user-images.githubusercontent.com/26588548/55347886-763c3280-54d3-11e9-94b9-297d2e4a660f.png [image: Screenshot from 2019-04-01 23-10-00] https://user-images.githubusercontent.com/26588548/55347887-76d4c900-54d3-11e9-846d-a89e89381e70.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IBM/blockchainbean2/issues/9#issuecomment-478675782, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8gZV-3VSzmtbBYxDQ9iMD3mqi4baULks5vckUlgaJpZM4cEuBN .

-- Thanks in advance, Horea Porutiu

Univ. of California, San Diego 2017 B.S. Computer Science B.S. Management Science (310) 707-6864 horeaporutiu@gmail.com

Vishnupriya-M commented 5 years ago

Could you please help me to know that how data from an html form can direct to the blockchain(also how can we retrieve data from blockchain through an html page)?

horeaporutiu commented 5 years ago

@Vishnupriya-M sure. The programming layer that actuall submits transactions to the blockchain network is the smart contract. In this project, this smart contract code can be seen here: https://github.com/IBM/blockchainbean2/blob/master/lib/my-contract.js The important difference between smart contract code and other code is that the smart contract code must be installed on the peer. This means that the only way to update our contract is to redeploy it (update the contract) on the peer. This update will be recorded in the blockchain to make sure we can audit it later.

In our html form, each API endpoint calls a different smart contract function. For example, for the queryAll endpoint that can be seen here: http://blockchainbeans2.mybluemix.net/explorer/#/WorldStateController/WorldStateController.queryAll calls the queryAll method that we have defined in our smart contract.

What we are doing, is transferring data from off-chain to on-chain. (In this case, only getting data, since this is a query, but if we did a /POST transaction, we would transfer data from off chain to on chain). The way we do this is that we pass data to our html page, and that html page then talks to our smart contract in the following way:

  1. in our controller file - https://github.com/IBM/blockchainbean2/blob/master/web-app/src/controllers/world-state.controller.ts#L26 we see that the first thing we do on line 36 is that we call blockchainClient.connectToNetowrk() to make sure that we can connect to our network - also our network must have a smart contract deployed onto the network. we did this in step https://github.com/IBM/blockchainbean2#step-6-deploy-blockchainbean2-smart-contract-on-the-network.

  2. after we connect to network, we call blockchainClient.queryAll() -https://github.com/IBM/blockchainbean2/blob/master/web-app/src/controllers/world-state.controller.ts#L37 . In blockchainClient file, we have then call contract.evaluateTransaction('queryAll') https://github.com/IBM/blockchainbean2/blob/master/web-app/src/blockchainClient.ts#L94 - this is the ONLY Hyperledger API call we make in this instance, which signals a call to smart contract.

This contract.evaluateTransaction simply looks into the deployed contract, and finds a function that has the name mentioned (queryAll) and then runs that function with the given args (in this case none).

The pattern is the same for all endpoints. First the control goes from the user -> controllers file -> blockchainClient file -> smart contract file.

Long explanation, but wanted to make sure it makes sense. Hope this helps :)

horeaporutiu commented 5 years ago

@Vishnupriya-M the actual API to use to store data on the blockchain is this one - https://fabric-shim.github.io/release-1.4/fabric-shim.ChaincodeStub.html#putState__anchor

And to retrieve data from blockchain - https://fabric-shim.github.io/release-1.4/fabric-shim.ChaincodeStub.html#getState__anchor

You can see we use both those API's extensively in blockchainbean smart contract here: https://github.com/IBM/blockchainbean2/blob/master/lib/my-contract.js

For example, getState in query method: https://github.com/IBM/blockchainbean2/blob/master/lib/my-contract.js#L391

And then putState in the addMember method: https://github.com/IBM/blockchainbean2/blob/master/lib/my-contract.js#L35

Vishnupriya-M commented 5 years ago

@horeaporutiu Thank you.

horeaporutiu commented 5 years ago

No problem! Closing issue now.