Error adding new Peer in Hyperledger Fabric - hyperledger-fabric

To add a new peer in Hyperledger Fabric I am using following command
peer = client.newPeer('grpcs://localhost:7051')
getting following error
PEM encoded certificate is required
Please help!

You can find PEM certificate in first-network folder and in connection-org1/org2.json.
Just start your network and after starting it copy the PEM certi.

Related

How to start hyperledger fabric network with project name reln and channel name relianceorgs

I have passed following commands :
mkdir workspace
cd workspace
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
./scripts/bootstrap.sh 1.4.1 1.4.1 0.4.14
cd reliance-network
What command to be next for project name reln & channel name relianceorgs ?
you need to modify configtx.yaml and crypto-config.yaml for channel name as well as organisation name, configtx.yaml will be used to generate genesis block and channel.tx file, while crypto-config.yaml file will be used to generate crypto material such as tls files and msp (i.e membership service provider) for organization. you can use first-network or basic network in fabric sample as an example. it would be better if you go through Read the docs https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html you will find all the commands and instructions that you need to follow.

Unsupported Config Type ""

While generating the configtx peer block for Hyperledger Fabric Channel Creation in Amazon Managed Blockchain
Facing an error
CRIT 002 Error reading configuration: Unsupported Config Type ""
ERRO 003 Could not find configtx.yaml. Please make sure that FABRIC_CFG_PATH or --configPath is set to a path which contains configtx.yaml
Even though I tried export FABRIC_CFG_PATH=$PWD still facing same error.
Make sure you defined correctly the Fabric config directory. In terminal in the root folder of you HLF configuration just use the command:
export FABRIC_CFG_PATH=${PWD}/<folder-with-configtx.yaml-and-crypto-config.yaml>

Hyperledger Fabric. Unable to invoke transactions using Fabric Node SDK

I tried two different tutorials:
This one to deploy docker images locally:
https://github.com/hyperledger/fabric-samples
I tried the fabcar sample. Everything works fine. I'm able to enroll the admin, register a user and invoke transactions using this user identity. Nice.
The second one to deploy a fabric composer playground on bluemix:
https://ibm-blockchain.github.io/setup/
I was able to get into the composer playground and deploy business network examples. I'm also able to upload and deploy my own business networks I designed locally with composer-cli. I exposed the network over a Rest Server with admin rights in order to test the transactions. All works fine.
Now it comes to my problem. I want to combine both examples (just for fun, learning by doing:)). I want to deploy the fabcar samples network to the kubernetes environment on bluemix and interact with the network using the fabric node sdk like in example 1. So I made following changes in the scripts/yaml files of example 2:
adapt the chaincode installation procedure
in the create_all.sh. line 41 (for peer 1) and line 45 (for peer 2). I changed the values of the env variables CHAINCODE_NAME and CHAINCODE_VERSION
echo "=> CREATE_ALL: Running Install Chaincode on Org1 Peer1" CHAINCODE_NAME="fabcar" CHAINCODE_VERSION="1.0" MSP_CONFIGPATH="/shared/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" PEER_MSPID="Org1MSP" PEER_ADDRESS="blockchain-org1peer1:30110" create/chaincode_install.sh
in the chaincode_install.yaml.base line 16, I changed the path of the chaincode. I forked the https://github.com/hyperledger/fabric and added the fabcar.go chaincode from example 1 to the new repository https://github.com/bigbelette/fabric
command: ["sh", "-c", "git clone https://github.com/bigbelette/fabric $GOPATH/src/github.com/bigbelette/fabric/ && peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p github.com/bigbelette/fabric/examples/chaincode/go/fabcar/"]
adapt the chaincode instantiation procedure:
in the create_all.sh. line 49. I changed the values of the env variables CHAINCODE_NAME and CHAINCODE_VERSION:
CHANNEL_NAME="channel1" CHAINCODE_NAME="fabcar" CHAINCODE_VERSION="1.0" MSP_CONFIGPATH="/shared/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" PEER_MSPID="Org1MSP" PEER_ADDRESS="blockchain-org1peer1:30110" create/chaincode_instantiate.sh
In the chaincode_instantiate.yaml.base, I made the parameter list empty:
command: ["sh", "-c", "peer chaincode instantiate -o blockchain-orderer:31010 -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -c '{\"Args\":[\"\"]}'"]
The deployment on the cluster works without an error. In the fabcar examples node js file enrollAdmin, regiserUser, query and invoke, I changed the channel name (from mychannel to channel1) and the IPs and ports to match to the online kubernetes services:
enrollAdmin.js and registerUser.js work fine so I can get the certificates and store it in the key store. But when I try to invoke a transaction, i get the following error:
It seems the CA which gave me the certificates is not recognized by the peers. But there is only one CA in my network!? Or is it a problem in the MSP definition (something I still dont understand well).
Thanks for your help.
I finally found the error.
My network has 1 CA (the root CA, named ca) and 2 "sub" CAs (ca1 und ca2). I was enrolling admin and user directly by the root CA because I didnt mention the name of the ca in the parameters of the Fabric_CA_Client class:
fabric_ca_client = new Fabric_CA_Client('http://184.173.5.108:30054', tlsOption, crypto_suite)
Without the name, the used CA will be the default CA (Root CA in my case). But the signature of user certificates by the root CA wont be recognized by the peers. Only the signatures from the last hierarchical CA levels will be accepted. So the solution was to refer the name of the CA:
fabric_ca_client = new Fabric_CA_Client('http://184.173.5.108:30054', tlsOptions , 'CA1', crypto_suite)
It works. Now the user can invoke transactions.

PEM encoded certificate is required

I am trying to access the remote peer from SDK using Hyperledger Fabric using following code
var peer = new Peer('Remote path', PemFile name)
it is giving me error that
Error: PEM encoded certificate is required.
I have tried reading file, using string every thing. Please advise me what I am doing wrong here
This is sorted.
It should be like this
var peer = newPeer('Remote Path', {
pem: 'PEM file name' })

Executing fabcar without fabric-ca

I built a Fabric network with multiple orgs and tls enabled. Crypto material was built with cryptogen. I do not intend to use fabric-ca in my example.
I installed and instantiated fabcar through CLI. Invoke and Query with CLI commands work as charm.
Now, for the purpose of using nodejs scripts query.js and invoke.js I concatenated a private and public key in order to create PeerAdmin credential for Fabcar. I also altered a configuration in .js files to aim at peers and orderers with grpcs.
Whenever I execute any .js script, I am constantly getting the following error:
Create a client and set the wallet location
Set wallet path, and associate user PeerAdmin with application
Check user is enrolled, and set a query URL in the network
Caught Error Error: PEM encoded certificate is required.
at new Endpoint (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:146:11)
at new Remote (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:95:20)
at new Peer (/home/hl/fabcar/node_modules/fabric-client/lib/Peer.js:53:3)
at Client.newPeer (/home/hl/fabcar/node_modules/fabric-client/lib/Client.js:173:14)
at Promise.resolve.then.then.then (/home/hl/fabcar/query.js:39:28)
at <anonymous>
When I try to query the chaincode without grpcs I receive the following error:
Create a client and set the wallet location
Set wallet path, and associate user PeerAdmin with application
Check user is enrolled, and set a query URL in the network
Make query
Assigning transaction_id: 9cbf355cda03db2b1971fe10af27d66686ea9b913eda80f667cac48bada015bf
error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: Endpoint read failed
at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15
returned from query
Query result count = 1
error from query = { Error: Endpoint read failed
at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15 code: 14, metadata: Metadata { _internal_repr: {} } }
Response is Error: Endpoint read failed
PeerAdmin content:
{"name":"PeerAdmin","mspid":"PeerOrgMSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"[...]","identity":{"certificate":"-----BEGIN CERTIFICATE-----\n[...]-----END CERTIFICATE-----\n"}}}
Any help in pointing me to a right procedure or troubleshooting with the above would be greatly appreciated.
I understand that you are going to do a fabcar without a Fabric CA.
If so, you can't use the Node.js application because it is using user context and you didn't enroll user context.
But you want to use fabcar without CA, you can invoke or query transaction as cli.
connect to cli container, if you use fabcar, cli-container-name is 'cli' so
docker exec -it cli bash
In cli container, you can invoke or query transaction. as the example below
peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars",""]}'
peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryCar","CAR4"]}'
invoking transaction is same
When you enable gRPCs you must pass the pem as a parameter in the instantiation of the various Hyperledger element objects (e.g. peer, orderer). In the case of the fabcar example (invoke.js):
// This is a new line
var options = {
tls_cert: {
pem: fs.readFileSync(path.join(__dirname, './network/tls') + '/peer.cert').toString(),
}
};
...
// Replace the original instantiation by adding the pem option
var peer = fabric_client.newPeer('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:26268', {
pem: options.tls_cert.pem
});
channel.addPeer(peer);
// Replace the original instantiation by adding the pem option
var order = fabric_client.newOrderer('grpcs://fft-zbc03b.4.secure.blockchain.ibm.com:20161', {
pem: options.tls_cert.pem
})
...
// Replace the original instantiation by adding the pem option
event_hub.setPeerAddr('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:23972', {
pem: options.tls_cert.pem
});
The code above assumes that you downloaded the right certificates to network/tls/. These certificates can be downloaded by sending requests to the CA. For a full example refer to the Bluemix documentation here.

Resources