Hyperledger fabric 1.4 Error on Instantiate chaincode - hyperledger-fabric

Setting up Built Your First Network (BYFN), after creating and joining Channel, chaincode is installed on both organization peers using following cli command -
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
Chaincode Installation is successful.
While I tried to Instantiate chaincode from the CLI using following command given by HLF document.
The following error occurred while Instantiate the chaincode in Hyperledger fabric v 1.4.
root#8804d95b7083:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
Error: must supply value for chaincode name parameter
Usage:
peer chaincode instantiate [flags]
Flags:
-C, --channelID string The channel on which this command should be executed
--collections-config string The fully qualified path to the collection JSON file including the file name
Is there any alternative way to resolve this error other than re-setup the Network?

There is a conflict with the CLI command there. You used go cli command for installing the chaincode and NodeJS cli command for instantiating the chaincode.

Related

How to list chaincode?

I'm able to follow https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html
$ peer chaincode invoke ... -c '{"function":"InitLedger","Args":[]}'
2021-08-23 17:52:59.534 PST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
I leanred peer chaincode list can list chaincodes, but the following commands don't give expected result.
$ peer chaincode list -C mychannel --installed
Get installed chaincodes on peer:
$ peer chaincode list -C mychannel --instantiated
Get instantiated chaincodes on channel mychannel:
Given I've successfully deployed the basic chaincode, how do I see it through peer chaincode list?
I think issue, will be with the path that is getting set. Make sure to export the following peer path where chaincode is installed :-
FABRIC_LOGGING_SPEC
CORE_PEER_MSPCONFIGPATH
CORE_PEER_LISTENADDRESS
CORE_PEER_LOCALMSPDIR
If tls is enabled, export the following path along with the paths above
CORE_PEER_TLS_ENABLED
CORE_PEER_TLS_KEY_FILE
CORE_PEER_TLS_CERT_FILE
CORE_PEER_TLS_ROOTCERT_FILE
And then try the commands
peer chaincode list --installed
peer chaincode list --instantiated -C mychannel
If you want to just view the installed chaincode below is the command for the HLF2.2x
peer lifecycle chaincode queryinstalled --peerAddresses localhost:7051
--tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE
If you want to view the commited chaincode list below is the command
peer lifecycle chaincode querycommitted --channelID channelName
in HLF2.2x chaincode lifecycle is introduced. So if you want to execute chaincode you need to approve and commit after installed on peer.

What is the meaning of “peer chaincode install -p" in Hyperledger Fabric?

I passed "first-network", no problem.
In CLI:/opt/gopath/src/github.com/hyperledger/fabric/peer:, execute these commands:
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND('Org1MSP.peer','Org2MSP.peer')"
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}' --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
There are no problem. But when I execute these commands in the subdirectory of the peer /opt/gopath/src/github.com/hyperledger/fabric/peer/scripts:, install、instantiate and query success, but invoke error:
Error: endorsement failure during invoke. response: status:500 message:"cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory".
This happens when CLI connects to peer0.ogr1, but I find this file at peer0.ogr1:
enter image description here
I replaced the peer node through the CLI, and the same problem occurred under the same path.
The problem may arise from the path specified by chaincode install -p. The official document says that this is a path relative to $GOPATH/src, so I feel that this path should have nothing to do with the current directory.
After searching, I found two similar problems, but the reasons are completely different and cannot be used for reference. Therefore, I can only raise new problems and hope to find solutions.
two similar problems:
Install a different version of chaincode (Hyperledger fabic)
Hyperledger Fabric - How to limit Org2 to install/instantiate/upgrade the chaincode to the channel?
version: Fabric1.4.4, Ubuntu18.04
structure: one order, four peers, each distributed on five machines, there is no problem with normal transactions

Error when invoking chaincode in hyperledger fabric

I have made my custom chaincode "mycc.js" It is successfully installed on peer. But when i Instantiate this chaincode using
peer chaincode instantiate -l node -n mycc -v v0 -C mychannel -c '{"args":["init","A","100","B","100"]}' -o locahost:7050
command. I got error this error
Any help is appreciated.
It's localhost, not locahost, you are missing "l"

Modify existing endorsement policy (Hyperledger Fabric)

I had 2 organization in Hyperledger Fabric blockchain network initially. Recently I added one more organization on a different host using swarm. When I try to invoke chaincode from 1st or 2nd organization then it's working fine and I can see the updated transaction from org3. But when I invoke a transaction from org3, I am getting the following error.
"[2019-02-06 06:44:21.895] [ERROR] invoke - The transaction was
invalid, code = ENDORSEMENT_POLICY_FAILURE"
Initially, chaincode was initiated using the following policy.
-P "OR ('Org1MSP.peer','Org2MSP.peer')"
So I think I will have to update existing endorsement policy to include org3.
Could anyone help to modify existing endorsement policy or to resolve the issue?
The way to upgrade the chaincode is as followed:
Increment the version of ccRequest containing ccPackage
Re-Install the ccRequest on all orgs in the channel.
Ex: peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
Create new ccPolicy with correct rules containing required orgs as endorsers.
Upgrade the chaincode by running upgradeCC command
Ex: peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
Test with a query on chaincode with peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
For more details refer docs or ask on rockerchat
Yes, you can do that using peer chaincode upgrade command.
peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile
$ORDERER_CA -C mychannel -n mycc -v 1.2 -c
'{"Args":["init","a","100","b","200","c","300"]}' -P "AND
('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
refer : peer chaincode upgrade

Error invoking chaincode "Error: unknown flag: --peerAddresses" Hyperledger Fabric first-network tutorial

I have been roughly following http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html#troubleshoot to create my first network, and have executed steps involving installing, istantiating, querying a chaincode. However, I get the following error while invoking chaincode.
root#5a0be253ef6e:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050 --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 -C testhimani123456 -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
Error: unknown flag: --peerAddresses
Usage:
peer chaincode invoke [flags]
Flags:
-C, --channelID string The channel on which this command should be executed
-c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
-n, --name string Name of the chaincode
Global Flags:
--cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
--certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
--clientauth Use mutual TLS when communicating with the orderer endpoint
--keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
--logging-level string Default logging level and overrides, see core.yaml for full syntax
-o, --orderer string Ordering service endpoint
--ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer.
--tls Use TLS when communicating with the orderer endpoint
--transient string Transient map of arguments in JSON encoding
-v, --version Display current version of fabric peer server
I have ignored the part concerning environment variables. I was confused as to where to include it. I tried adding the fields that were absent in docker-compose-base.yaml file, but it gave me errors while running docker exec -it cli bash command, saying that there is no container for cli. So i decided to go with the original file, completely ignoring the step.
(finally know how to use this) Actually found the solution thanks to a friend.
The "peer chaincode invoke " doesn't have the flag "peerAddresses". The code given on the Hyperledger fabric tutorial documentation might be outdated or incorrect.
This can be seen in the Reference documentation : https://hyperledger-fabric.readthedocs.io/en/release-1.1/commands/peerchaincode.html
So removing peerAddresses and writing something like this might solve the error.
peer chaincode invoke -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
Problem was resolved by changing chaincode instantiation by changing "and" to "or".
Since I had skipped the environment variables step, default was peer0.org1 (i.e. org1MSP). Nothing was set for org2MSP. Thus it was in no position to award permissions in the first place.
peer chaincode instantiate -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

Resources