How to get Id number co chaincode of hyperledger fabric by Hyperledger Fabric SDK for node.js? - hyperledger-fabric

After I installed the chaincode, the peer chaincode list return all installed chaincode with the id numbers:
peer chaincode list --installed -C mychannel
Get installed chaincodes on peer:
Name: dev-mychaincode-cc, Version: alpha1, Path: /opt/home/mychaincode-cc, Id: 414955ccc11a2644a7f7caxxxb29ee06
Is there anyway to get this id (414955ccc11a2644a7f7caxxxb29ee06) by Hyperledger Fabric SDK for node.js?

You should be able to call the GetInstalledChaincodes transaction function on the lscc system chaincode, and parse the return value, which is a ChaincodeQueryResponse protocol buffer (protobuf) message.
The protobuf definitions for Fabric are in the fabric-protos repository. There are also published Go, Node (TypeScript/JavaScript) and Java language bindings for all the Fabric protobufs that you can use directly to help unpack protobuf messages:
https://hyperledger.github.io/fabric-protos/
For reference, the lscc chaincode's GetAllChaincodes transaction function implementation is here:
https://github.com/hyperledger/fabric/blob/2b8997153a4d7ea94429b23f9868eb937bce35b5/core/scc/lscc/lscc.go#L613

Related

Hyperledger Fabric: CouchDB doesn't show the worldstate of a channel

The HLF Version I use is 2.2
I set up my own network consisting of 3 Orgs, 1 Orderer and 2 Channels. The network is set up and I can call Chaincode Functions responding with 200. So far, so good. The problem is I don't see the worldstate in CouchDB. I think it's related due to the fact the chaincode is not instantiated properly or at all
When I call:
peer chaincode list --instantiated -C examplechannel
It doesn't return anything. But if I try to set the flag --isInit on the first Invoke.
peer chaincode invoke -o localhost:7050 -C examplechannel -n example --peerAddresses localhost:9051 --isInit -c '{"function":"instantiate","Args":[]}'
The response is:
chaincode 'example' does not require initialization but called as init
When I try to instantiate the Chaincode by:
peer chaincode instantiate -o localhost:7050 -C examplechannel -n example -v 1 -c '{"function":"instantiate","Args":[]}'
I get the response:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg Channel 'examplechannel' has been migrated to the new lifecycle, LSCC is now read-only
Any suggestions?
There is difference in the chaincode installation from Fabric version 2.0 when compare to previous version. Please refer below documentation for more details regarding new chaincode lifecycle
https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html

hyperledger fabric No such file or directory when invoke chaincode by sdk-node

This is a tracing network with one channel composed of 3 Orgs, 1 anchor peer per organization, 1 MSP per org, and 1 CA for org3. And I'm not using TLS (because I couldn't find a dependable sample with TLS ON)
I'm trying to use Fabric-sdk-node to build a web front end for it, and I'm using fabcar sample. and when I use invoke.js (almost the same as the example), I find this.
root#oyu-virtual-machine:~/hyperledger-fabric/test/webapp# node get2.js
Wallet path: /root/hyperledger-fabric/test/webapp/wallet
2021-05-05T10:34:16.275Z - warn: [Query]: evaluate: Query ID "[object Object]" of peer "peer0.sell.trace.com" failed: message=cannot retrieve package for chaincode sellcc/1.0, error open /var/hyperledger/production/chaincodes/sellcc.1.0: no such file or directory, stack=Error: cannot retrieve package for chaincode sellcc/1.0, error open /var/hyperledger/production/chaincodes/sellcc.1.0: no such file or directory
at /root/hyperledger-fabric/test/webapp/node_modules/fabric-client/lib/Peer.js:144:36
at Object.onReceiveStatus (/root/hyperledger-fabric/test/webapp/node_modules/grpc/src/client_interceptors.js:1212:9)
at InterceptingListener._callNext (/root/hyperledger-fabric/test/webapp/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/root/hyperledger-fabric/test/webapp/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/root/hyperledger-fabric/test/webapp/node_modules/grpc/src/client_interceptors.js:847:24), status=500, , url=grpc://localhost:7051, name=peer0.sell.trace.com, grpc.max_receive_message_length=-1, grpc.max_send_message_length=-1, grpc.keepalive_time_ms=120000, grpc.http2.min_time_between_pings_ms=120000, grpc.keepalive_timeout_ms=20000, grpc.http2.max_pings_without_data=0, grpc.keepalive_permit_without_calls=1, name=peer0.sell.trace.com, request-timeout=3000000, isProposalResponse=true
Failed to evaluate transaction: Error: cannot retrieve package for chaincode sellcc/1.0, error open /var/hyperledger/production/chaincodes/sellcc.1.0: no such file or directory
In my opinion, the most important message is
error open /var/hyperledger/production/chaincodes/sellcc.1.0: no such file or directory
It once occurred when I forgot install other orgs' chaincodes on the SellOrg(InvokeChaincode API require), but I definitetly install it this time. I dont know what's going on.
I'm a very newbie in both fabric and nodejs, so any kind of help would be great. Thanks in advance.
Now I know where the problem is, all of my peers have the same addr of localhost:7051, and it link to another org's peer. The peer's name in the error message is completely wrong, it just show the name in my connection.json !

The mismatch of chaincode verison within fabric peers

In this situation:
1,Peer X is down
2,Other peer perform upgrade of chaincode with success
3,Peer X is up, it will receive block and tx from the order/other peers, but it lacks of the newest version of chaincode.
4,In my try, if update the chaincode on peer X, it will result to mismatch of the version within peers
How to make all peer have the same verison of chaincode?
You must install the last version of the chaincode in all the endorser peers. Always. The admin of each organization should do that, to be accurate.
Install it in every endorser peer and instantiate/upgrade once.
Be sure that you have the same version in every peer by comparing:
md5sum /var/hyperledger/production/chaincodes/mychaincode.1.0

adding new peer | 'chaincode with name 'cc' already exists' on composer network start

I am facing issues while while starting chaincode on my newly added peer in hyperledger network. Let me explain you the issue I am facing.
I had up and running hyperledger network where I had installed my bna with version 0.0.1. When I ping my network everything works fine. I have added new peer in network without bringing network down. Now I am trying to install bna on newly added peer. I have added new peer in connection profile for both organizations after adding I have created card and installed on organization where I have added new peer. bna is installed on the peer successfully. Now I am trying to start the network with composer network start. this is the point where I am receiving the following error.
Processing these Network Admins:
userName: user1
userName: user2
× Starting business network definition. This may take a minute...
Error: Error trying to start business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: chaincode with name 'cc' already exists
Response from attempted peer comms was an error: Error: chaincode with name 'cc' already exists
Response from attempted peer comms was an error: Error: chaincode with name 'cc' already exists
Response from attempted peer comms was an error: Error: chaincode with name 'cc' already exists
Response from attempted peer comms was an error: Error: chaincode with name 'cc' already exists
Command failed
Please help in this matter. How am I suppose to add bna on newly added peer in network. I dont want bring my network down while adding new peer and install bna file.
So long as the bna is the same on the other peers, then you don't need to do anything else. All you need to do is install it onto the peer (the install command will not install it on peers that already have the bna, but will install it on peers that don't have it), and it sounds like you have done the correct approach by updating your connection profile and run the install command using an identity that is in the same MSP as your new Peer.
You do not need to start the business network because it is already started and that is the meaning of the error you are getting.
Now if you submit a transaction it will be sent to all peers in your connection profile. For your new Peer it will bring up the chaincode (ie the business network) automatically so that it can simulate that submission.

Instantiate chaincode from Java SDK

I am trying to instantiate a chaincode from a Fabric Java SDK Client using code from this
example
When i am trying to add imports inside chaincode ie
github.com/hyperledger/fabric/core/chaincode/lib/ci
I am getting error from the peer
2018-05-30 17:03:24.813 UTC [endorser] simulateProposal -> ERRO 038 [mychannel][6326fbfe] failed to invoke chaincode name:"lscc" , error: Failed to generate platform-specific docker build: Error returned from build: 1 "chaincode/input/src/github.com/ify/ify.go:40:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/lib/cid" in any of:
/opt/go/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOROOT)
/chaincode/input/src/github.com/hyperledger/fabric/core/chaincode/lib/cid (from $GOPATH)
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/lib/cid
where should i install the packages inside peer in order to be visible from the go builder?
You have to put everything in vendor, as stated in the coding guidelines: Hyperledger Fabric uses Go Vendoring for package management.
In this way you can import external libraries in the chaincode.

Resources