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
Related
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
I have created a Business network archive. composer deploy and composer start works fine. However, I am not understanding where is it getting deployed ?
Under which channel does it get deployed ?
How can I set endorsement policies for this Business network ?
My understanding of BNA is it is equivalent to chain code which is mentioned under Composer v0.19.0 - Breaking changes section
enter link description here
Under v0.19.0 of Composer (the 'latest' version) the composer network install command install the BNA to Peers in the folder /var/hyperledger/production/chaincodes/. The composer network start command creates a new chaincode specific container for each Peer to run the chaincode - the name of the container is made up of the name of the Network and the Version.
The channel used by composer is defined in the Connection Profile (connection.json) being used to install and start the network. In the Development Fabric the channel used is composerchannel.
The endorsement policy can be supplied to the composer network start command e.g. -o endorsementPolicyFile=my-endorsement-policy.json as described here.
The CLI container is used to run below:
peer create channel
List item
peer join channel
peer install chaincode
peer instantiate chaincode
peer invoke chaincode
peer query chaincode
However the same can be achieved without creating a docker CLI container.So what is the actual purpose of it?
The Hyperledger Fabric CLI (peer command) can be run natively, without a docker container. For purposes of the samples, though, we can run the whole sample in the cloud, if one wishes. It just simplifies things a bit and allows us to be more prescriptive of the environment.
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
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