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
Related
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
Can you delete hyperledger fabric smart contract like the kill function in ethereum?
To kill a chaincode(Smart contract) you need to follow following steps:
Kill chaincode containers belonging to respective chaincode version, which you want to kill. You may kill containers using following command:-
docker rm -f [Chaincode docker container's ids separated by space]
Delete chaincode images, using following command:-
docker rmi [Chaincode images ids]
Delete the chaincode from the file system of each peer under /var/hyperledger/production/chaincodes
Right now this is the procedure to uninstall a chaincode, in future there will be stop and start command to stop and resume a smart contract respectively. You may checkout the same in official documentation:-
Hyperledger fabric chaincode lifecycle
You can remove the containers and images for your smartcontract, but if you go to the peer container the foulder /var/hyperledger/production/chaincodes is empty.
If you run hyperledger explorer you will see that the contract remains and if you want install again with same name obtains an error, so the question is where and how you can remove this link in hyperledger 2.3?
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.
I am running Docker Toolbox on Windows. I have downloaded fabric samples from https://github.com/hyperledger/fabric-samples. Modified the fabcar chaincode.
The first time I ran ./startFabric.sh to bring up the local blokchain network, the chaincode is getting picked up well and fine.
Now I make further changes to fabcar chaincode. But this time, my latest chaincode changes are not being picked up by the blockchain network. I still see old log messages and responses.
I have tried the following options already:
1) clearing up docker containers
2) restarting docker toolbox.
3) rerunning ./startFabric.sh from scratch.
The only time my chaincode changes are picked up is the "first ever time" when i use that particular chaincode. Thereafter the first chaincode somehow resides in the memory forever.
Please let me know what I am doing wrong.
Thanks!
After changing chaincode in fabric-samples/chaincode/fabcar/go/fabcar.go (this is where you change the chaincode, I presume), you have to go build fabcar.go so that latest compiled code gets into the peer.
./startFabric.sh add a new docker image and use it as chaincode container.
To run updated chaincode, remove this container and execute ./startFabric.sh again.
docker rmi -f dev-peer0.org1.example.com-docchain-1.0-961b279a2d42ac81dd6585a11d9fad6bfe4f000a2c3d0cdc9be4bd1ecdf5610d
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