Peer Command not found - hyperledger-fabric

I am working on this tutorial http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
To Create and Join Channel i am trying to run following peer command :
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
I am connected to container as well after executing docker exec -it cli bash. Even i have tried ./peer but i am still getting no peer directory exist or peer command not found

This may be due to relative path is not correct, where peer binary is stored. You can find it inside hyperledger/fabric/build/bin. Once you locate the peer binary export it using.
e.g. export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric/build/bin/
Then try to create channel using commands you are using.

Related

Hyperledger Fabric "evaluateTransaction" ERROR

I am trying to develop a supply chain application using Hyperledger Fabric.
During development, I am using Hyperledger Fabric Test Network and I added a 3. organization using "addOrg3.sh" command. All the codes I used when I start the network are listed below.
cd ../test-network
./network.sh down
docker rm -f $(docker ps -aq)
./network.sh up createChannel -ca -s couchdb
cd addOrg3
./addOrg3.sh up -c mychannel -ca -s couchdb
export FABRIC_CFG_PATH=$PWD
../../bin/configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json
cd ..
./network.sh deployCC -ccn SupplychainContract -ccp ../supply-chain/chaincode/ -ccl javascript -ccep "OR('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
cd ../supply-chain/server
rm -r ./wallet/*
node enrollAdmin.js org1 admin adminpw
node enrollAdmin.js org2 admin adminpw
node enrollAdmin.js org3 admin adminpw
chmod 777 wallet
chmod 777 ./wallet/*
However, on the running project, while using a wallet belonging to the org3 network, I can run submitTransaction command on the chaincode without any problem, but when I try to run the evaluateTransaction command, it gives an error as follows.
ERROR MESSAGE: 2022-12-07T12:45:38.620Z - error: \[SingleQueryHandler\]: evaluate: message=Query failed. Errors: \["Error: Peer peer0.org3.example.com:11051 is not running chaincode SupplychainContract"\], stack=FabricError: Query failed. Errors: \["Error: Peer peer0.org3.example.com:11051 is not running chaincode SupplychainContract"\]
When I call the related method using submitTransaction , there is no problem. if i use docker-compose -f ./compose/docker/docker-compose-org3.yaml up -d while raising the network, it conflicts with another container produced by addOrg3.sh .
How can I solve this problem?
I think the issue you are seeing is because the default query handler implementation prefers the client's org peers, and it also returns (either a result or an error) from the first peer it is able to successfully invoke. Your org3 client evaluates the transaction on the org3 peer, which responds with an error saying the smart contract is not deployed there.
The submit implementation is more complex and will use service discovery to identify peer that can satisfy the endorsement policy for a given chaincode, so will not attempt to use the org3 peer.
Using Fabric v2.2, your best options are probably either:
Deploy the chaincode on the org3 peer; or
Implement your own query handler that provides appropriate behaviour.
This tutorial page describes how to configure an alternative query handler and how to write a custom query handler:
https://hyperledger.github.io/fabric-sdk-node/release-2.2/tutorial-query-peers.html
A possible approach would be for your handler to use all network peers and to keep trying peers until it either receives an endorsed response or has tried all available peers.
If you can use Fabric v2.4 (or later), you should consider using the Fabric Gateway client API instead. This will just work without any additional configuration.

How to install custom chaincode?

I want to install custom chaincode on my hyperledger fabric channel. I put my chaincode.go file besides of my .yaml files .when I run this command :
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
I got this error:
Error: error getting chaincode code mycc: path to chaincode does not
exist: /opt/gopath/src/github.com/chaincode/chaincode_example02/go
I do not know where is opt/gopath or how to address the chaincode.go file?
please help me
When you launch your network (if you are using the first-network template), you bring up a container 'CLI', you can find it in docker-compose-cli.yaml
This container is used to operate on the differents nodes of the architecture.
You need to create a volume who match your chaincode path like so
Then, when the container 'cli' goes up, you can enter into it with
docker exec -it cli bash
Now you can navigate to your path and see your chaincode directory.
And do your command :
peer chaincode install -n mycc -v 1.0 -p path/define/in/your/volume/section/to/your/chaincode

create new channel and join peers

I have few basic doubts regarding creating a channel in fabric. I was trying to set up the first network with individual commands.
I came across multiple commands for creating channel but unable to understand the difference
a. sudo docker exec peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c composerchannel -f /etc/configtx/composer-channel.tx — tls true — cafile /etc/configtx/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
b. peer channel create -o orderer.example.com:7050 -c mychannel1 -f ./channel-artifacts/channel1.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA
Does channel need to be created under an orderer container or peer container?
in the above command I can see peer0.org1.example.com with exec, is it given to create the channel inside the peer container?
In the command b peer0.org1.example.com is not given, is it because we run this command inside CLI?
I just wanted to understand how to works with the channel creation syntax?
I can see why this can be confusing. At a high level:
In order to create a channel, you need to submit a configuration
transaction to an orderer node (aka "create channel").
In order for peers to receive blocks from a channel and to invoke
chaincode on a channel, you need to call the "join channel API" on
each peer.
The confusing part is that there is only a single CLI (command-line interface) for performing both actions and it is actually the peer executable.
So when you call peer channel create ... you are actually sending a configuration transaction to an ordering node.
You can either execute the peer ... commands inside a container which has the peer executable ( that's the docker exec ... you show above ) or you can run the peer binary on a host system and do the same thing (the second option you show above runs it within the CLI container).

When I building my first network in Hyperledger, I failed to create channel, and give following tips:

I clone the project fabric-samples to my file names HYFA.
I created the file names init.sh and copy the content of link https://github.com/hyperledger/fabric-samples/blob/release-1.3/scripts/bootstrap.sh to it.
perform init.sh to download binary file and docker images.
Then I follow the official Docs Building Your First Network to config when I execute peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Above command returns below error
Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
How can I solve this question?
I just got the same error and what I did was prune my containers and such (restart network in short). It works again. This may not be the solution for you but please add more details :)

error when creating an new channel 'BAD_REQUEST -- error authorizing update: error validating DeltaSet'

I try to create first-network manually instead of using byfn.sh script, and when I try to create channel inside cli container.
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
I get this error:
Error: got unexpected status: BAD_REQUEST -- error authorizing update: error validating DeltaSet: policy for [Group] /Channel/Application not satisfied: Failed to reach implicit threshold of 1 sub-policies, required 1 remaining
and this error from orderer:
ERRO 008 Principal deserialization failure (the supplied identity is not valid: x509: certificate signed by unknown authority (possibly because of "x509: ECDSA verification failure" while trying to verify candidate authority certificate "ca.org1.example.com")) for identity
note:
it's work fine if I use byfn.sh script
I found this
peer channel creation fails in Hyperledger Fabric,
hyperledger fabric first_network example create channel got BAD_REQUEST,
FABRIC returns Error: Got unexpected status: BAD_REQUEST questions
but I still don't know how I can fix this error?
os host: ubuntu 16:04
hyperledger fabric version: x86_64-1.1.0
If you're still having this error, you might have already tried to start the network, and then started over. You'll need to delete both the old docker containers and their volumes - they might try to be reused, and then old cert data will be used, leading to the unknown authority error.
Here are all the reset commands you'll want to use for the byfn.sh or similar script:
# STOP AND DELETE THE DOCKER CONTAINERS
docker ps -aq | xargs -n 1 docker stop
docker ps -aq | xargs -n 1 docker rm -v
# DELETE THE OLD DOCKER VOLUMES
docker volume prune
# DELETE OLD DOCKER NETWORKS (OPTIONAL: seems to restart fine without)
docker network prune
# DELETE SCRIPT-CREATED FILES
rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
rm -f docker-compose-e2e.yaml
# VERIFY RESULTS
docker ps -a
docker volume ls
ls -l
Try doing byfn down before starting manual steps. I think previous volumes are not cleared.

Resources