Unable to use peer command in docker dev mode in Hyperledger Fabric - node.js

I am trying to test a custom Node JS Chaincode for hyperledger. From the documentation and videos, I understood that I need to use Docker dev mode so that I can access my dev environment out of the box.
I tried to start a basic network using the fabric-samples/basic-network/ folder as suggested by this video: https://www.youtube.com/watch?v=dzwR0dwzXNs.
After I start the network, I am unable to use the peer command through the command line. For example, the below command is not working
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/correctPath/users/Admin#org1.example.com/msp peer0.org1.example.com peer channel list
I suspect that I am unable to avoid my peer from using TLS. How do I overcome this? Or is there some other issue?

move to
cd ~
nano .bash_profile
then add
export PATH=[download path here]/fabric-samples/bin:$PATH
then
source .bash_profile
peer version

Related

Hyperledger Fabric peer, peer chaincode commands

Hyperledger Fabric provides peer, peer chaincode commands: https://hyperledger-fabric.readthedocs.io/en/release-2.3/commands/peerchaincode.html
I have setup on different VMs. I am using commands like:
peer chaincode query on terminal on one vm
It should show the chaincode for the current value on a peer’s ledger.
Instead I get command not found error. What am i missing?
That is because the terminal doesn't know where to find the peer command. You have to set the $PATH environment variable to indicate the location of the peer binary file. From the doc
You may want to add that to your PATH environment variable so that these can be picked up without fully qualifying the path to each binary. e.g.: export PATH=/bin:$PATH

Fail to deploy sample chaincode on Fabric from fabric-samples

I am trying to deploy a sample ChainCode on Fabric test-network. I bring up the network and then I create a channel and then I run this command: ./network.sh deployCC and I get the following error:
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image inspection failed: Get "http://unix.sock/images/dev-peer0.org1.example.com-basic_1.0-4ec191e793b27e953ff2ede5a8bcc63152cecb1e4c3f301a26e22692c61967ad-42f57faac8360472e47cbbbf3940e81bba83439702d085878d148089a1b213ca/json": dial unix /host/var/run/docker.sock: connect: no such file or directory
Chaincode installation on peer0.org1 has failed
Deploying chaincode failed
I'm guessing you are running Docker on a Mac ? Docker made a change in version 2.4.0.0 (I think) and it causes a problem. You need to uncheck the option "use gRPC fuse".
see https://lists.hyperledger.org/g/fabric/topic/77402508?p=Created,,,20,2,0,0::recentpostdate%2Fsticky,,,20,2,0,77402508
for more details
If you are running Docker Desktop on macOS, this problem is caused by a newer version of Docker Desktop for macOS. To resolve this issue, in the Docker Desktop preferences, uncheck the box Use gRPC FUSE for file sharing to use the legacy osxfs file sharing instead and click Apply & Restart.
If you see errors on your create, approve, commit, invoke or query commands, make sure you have properly updated the channel name and chaincode name.

Fabric Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection

There was an Hyperledger Fabric error updating the anchor peer in the Building Your First Network document. This error is as follows.
Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: x509: certificate signed by unknown authority
I need your help.
I fixed by bringing the network down (byfn.sh down)
and then up again (byfn.sh up).
Please see this link for more information:
How to fix "FAILED to execute End-2-End Scenario" in Hyperledger Fabric?
x509: certificate signed by unknown authority
This error is due to the certificate format mismatch, It happed to me when I used v1.0 cryptogen tool for certificate generation and ran the network with v1.1 Fabric containers.
So, try to update the cryptogen tool from here -> http://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html#binaries.
I don't know what version you were using so, I assumed it would be v1.1. So, please specify the Hyperledger Fabric version you were using.
One of the problems could be that you have an old version of the Hyperledger Example and you are pointing to an old version of the Cryptogen tool. So if you download a newer example, when you generate the crypto-config it will generate it with the old version of the cryptogen tool, this could make your orderer container to stop, cause can validate the certificate generated.
This is because the differents versions of the cryptogen tool generate different metadata.
My suggest is to check if the cryptogen version that you are using is the one contained in your downloaded image of your example. If you had run lot of tests, clean all the docker images and containers, that always help.
If nothing of that works, I wrote a tutorial based on the basic-network example and how to run it in multiple hosts, maybe you can take some information from there.
https://medium.com/1950labs/setup-hyperledger-fabric-in-multiple-physical-machines-d8f3710ed9b4
Please, feel free to ask, if you have doubts!
This error is due to channel capabilities are set as true for v.1.4.0 so you should change it to false so that it can run for every version of the fabric.
Try:
docker ps -a
to find container ID of hyperledger orderer and peer images. Then try:
docker rm *container_ID*
to remove them. After you can run ./network.sh up createChannel.
so for this error i tried doing byfn.sh down and byfn.sh up but after that it threw another error, which i solved by first killing all the containers, removing them, cleaning all images and volumes that already exist and restarted the tutorial. to kill and remove processes and images and cleaning my system.
https://medium.com/coinmonks
docker kill $(docker ps -q)
docker rm $(docker ps -qa)
docker system prune -a
docker volumes prune -a
delete fabric-samples directory and start from the beginning and you're ready to go.

Hyperledger Fabric CLI docker container

I have couple a questions regarding HF CLI docker container and some of CLI commands.
First of all, can someone explain the purpose of this container in context of docker container which is started alongside other docker containers required for HF ecosystem. How can I for example query my business network organisations, different peers, and chain-code status on those peers?
Second of all, when I install a chain code issuing peer chaincode install CLI command, to which peer is that code installed (if i have 5 peers attached to org1.example.com organisation, on which peer aforementioned command will install the targeted chain code)?
And third of all, if I have just one organization in my business network specification which handles multiple peers and channels, when I try to instantiate the installed code issuing peer chaincode instantiate command, how to specify the endorsement policy (http://hyperledger-fabric.readthedocs.io/en/latest/endorsement-policies.html) which has just one organisation in endorsement expression after the -P parameter?
Thank you for your help!
EDIT 1:
Just one update regarding 3rd answer. In you have one organisation maintaining peers and channels when instantiating chaincode, you can omit the endorsing policy parameter (-p). In that case transaction will be endorsed if any peer endorses it
Lots of great questions.
the "cli" container's purpose is to run a peer process as a CLI . It is a bit confusing that the same process is both a client and a server, we may change that. Basically, when you run the peer chaincode commands, you are running the CLI. The peer node commands are the server commands. The cli container in our samples runs a script (scripts/script.sh) which in turn executes a series of CLI commands against the peer nodes.
If you examine scripts/script.sh, you will find a setGlobals function that sets a few environment variables, including CORE_PEER_ADDRESS. This is the peer (server) to which the peer (CLI) will communicate when installing the chaincode.
Actually, after further research, this is not possible, unfortunately. The gate syntax isn't yet implemented. You would need to simulate multiple orgs for this.
Re the second part of this question.
Entering the CLI
docker exec -it cli bash
The bootstrapped peer for CLI is peer0.org1.example.com
Check which PEER you are on:
echo $CORE_PEER_ADDRESS
returns
peer0.org1.example.com:7051
Change to peer1.org1:
export CORE_PEER_ADDRESS=peer1.org1.example.com:8051
Also applies to LOCALMSPID, MSPCONFIGPATH, etc

Unable to modify Chaincode in hyperledger fabric

I downloaded the fabric-sample example from the command in linux,
given in the document "http://hyperledger-fabric.readthedocs.io/en/v1.0.0-beta/getting_started.html#install-prerequisites"
I followed the document to start the network, and script.sh
is running successfully.
now when I am modifying the chain code from my local system at "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
chaincode modification is not reflecting in the output.
please suggest me, how to run my own chaincode.
If your target is to run your own chaincode, the recommended way is to follow the chaincode developers guide here. Normally, the chaincode is started and maintained by peer, but this chaincode dev mode allows user to start chaincode for easier testing and development. If you are starting by modifying existing chaincode, you may omit the code-building section and concentrate on the other steps (creating proper directories, building them etc)
When you start your network, you get some Peers and an Orderer. In that step you copy the chaincode that it's in the predefined directory, i.e. a predefined chaincode is copied for you. You define that directory in the docker-compose-cli.yaml file, in the line - ./chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode So, if you want to change the chaincode that is copies to your Blockchain, you should change in that directory.
So, any change that you do in your local machine won't have any effect on the chaincode of the Peer. If you want to run your own chaincode, you have to define it previously, before starting up your network. Then, you will hava it in the corresponding docker container.
You can develope your own chaincode and pass it to the cli container by executing the following command:
docker cp yourchaincode.go cli:/opt/gopath/src/github.com/hyperledger/fabric/examples/mychaincode/yourchaincode.go

Resources