'Deploy and expose chaincode as REST api on amazon managed blockchain hyperledger fabric 1.2
I have configured amazon managed blockchain setup with Hyperledger 1.2. The network is prepared with a single member and a single peer node. Hyperledger Fabric Client setup is with Golang 1.10.3. I have installed, Instantiated, Queried and Invoked mycc chaincode example given in AWS tutorial. Which works perfectly. Complete exercise was done following this link.
I want to deploy and expose the chaincode as REST api. There is a sample project Amazon Managed Blockchain Workshop. They have used RESTful API, running as a Node.js Express application, using the Hyperledger Fabric Client SDK to query and invoke chaincode. I want to run non-profit chaincode example on Hyperledger Fabric Client prepared for AWS managed Blockchain Hyper Ledger 1.2
I have performed below steps:
Part 2: Deploy the non-profit chaincode)
Part 3: RESTful API to expose the Chaincode
Here are the steps how am I am running and testing the REST API.
cd ~/non-profit-blockchain/ngo-rest-api
nvm use lts/carbon
node app.js &
If I execute Register/enroll a user request
curl -s -X POST http://localhost:3000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=john&orgName=Org1'
Instead of showing: response:
{"success":true,"secret":"","message":"michael enrolled Successfully"}
It shows below error message.
{"success":false,"message":"failed Error: Missing mspid parameter"}
I have also tried by adding mspid in the request but the error message is still same. What am I missing?
Here are contents of ngo-connection-profile.yaml
channels:
mychannel:
orderers:
- orderer.com
peers:
peer1:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
<pre><code>
organizations:
Org1:
mspid:
peers:
- peer1
certificateAuthorities:
- ca-org1
orderers:
orderer.com:
url: grpcs://orderer.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.managedblockchain.us-east-1.amazonaws.com:30001
grpcOptions:
ssl-target-name-override: orderer.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.managedblockchain.us-east-1.amazonaws.com
tlsCACerts:
path: /opt/home/managedblockchain-tls-chain.pem
</pre></code>
peers:
peer1:
url: grpcs://nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS....
eventUrl: grpcs://nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.....
grpcOptions:
ssl-target-name-override: nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.xxx
tlsCACerts:
path: /opt/home/managedblockchain-tls-chain.pem
certificateAuthorities:
ca-org1:
url: https://ca.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS....
httpOptions:
verify: false
tlsCACerts:
path: /opt/home/managedblockchain-tls-chain.pem
registrar:
- enrollId: aaaaaaaa
enrollSecret: XXXXXXXXXXX
caName: m-AAAAAAAAAAAAAAAAAAAAAAAAA
Solution 1:[1]
I am also exploring Amazon Managed Blockchain although its in preview. Hopefully I will be able to assist you in your issue. mspid is not a parameter to be sent in the request. It looks that you are missing some-thing in the configuration file. Can you send me the contents of below configuration file?
cat ~/non-profit-blockchain/tmp/connection-profile/ngo-connection-profile.yaml
While looking at the contents of the configuration file, it is obvious that mspid value is missing in the configuration file. Membership Service Providers (MSP) ID is a mandatory value to be set in the configuration. You can also confirm it with below command.
cat ~/non-profit-blockchain/tmp/connection-profile/ngo-connection-profile.yaml | grep mspid:
If it is showing empty value then you need to set mspid in the configuration file.
Make sure that the environment variables mentioned in ~/non-profit-blockchain/ngo-fabric/fabric-exports.sh
are properly set. If this file is missing then use ~/non-profit-blockchain/ngo-fabric/templates/exports-template.sh
You need to set the value of environment variable ${MEMBERID} in mspid in ngo-connection-profile.yaml, also see if any other required field value is missing in the configuration file. You can also see the detail of values required t be replacs in the configuration file from below script.
~/non-profit-blockchain/ngo-rest-api/connection-profile/gen-connection-profile.sh
.
Let me list down those as well.
sed -i "s|%PEERNODEID%|$PEERNODEID|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%MEMBERID%|$MEMBERID|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%CAFILE%|$LOCALCA|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%ORDERINGSERVICEENDPOINT%|$ORDERINGSERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%ORDERINGSERVICEENDPOINTNOPORT%|$ORDERINGSERVICEENDPOINTNOPORT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%PEERSERVICEENDPOINT%|$PEERSERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%PEERSERVICEENDPOINTNOPORT%|$PEERSERVICEENDPOINTNOPORT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%PEEREVENTENDPOINT%|$PEEREVENTENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%CASERVICEENDPOINT%|$CASERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%ADMINUSER%|$ADMINUSER|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
sed -i "s|%ADMINPWD%|$ADMINPWD|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml
After setting the values and verifying, stop node or kill the process running on port 3000 and run node again. cd ~/non-profit-blockchain/ngo-rest-api
nvm use lts/carbon
node app.js &
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |