In Fabric Ledger ,Contract is not called - hyperledger-fabric

I deploy a java chaincode in "fabric-sample" testnetwork. All the life cycles are sucessfully executed like (peer clifecycle chaincode package|install|approve|commit).After that chaincode is instantiaed successfully.But when try to access the chain code functions, I get the below error :
**Error: endorsement failure during invoke. response: status:500 message:"Undefined contract called" **
I used the below code to access chain code function "addNewCar" and get the following error :

The "Undefined contract called" message is returned by the Java chaincode runtime if the contract namespace specified does not exist within the chaincode. A chaincode may contain multiple smart contract definitions, each identified by a namespace. It may also contain one default smart contract, which does not have a namespace (or whose namespace is empty).
Just for reference, and by way of explanation, programmatically in a Java client application you would obtain the default smart contract for a chaincode by calling Network.getContract(String chaincodeName). You would obtain a specific named (or namespaced) smart contract within a chaincode by calling Network.getContract(String chaincodeName, String contractName).
When actually invoking the chaincode, the contract name (or namespace) is prepended to the transaction function name so that the chaincode runtime can identify which smart contract should be invoked. The actual transaction name passed to invoke the AddCar transaction function on a smart contract named car would be car:AddCar. The AddCar transaction on the default (no namespace) smart contract would be invoked just using the name AddCar.
Using the peer CLI command, you need to prepend the correct smart contract name to your transaction function name in order to invoke a specific named smart contract. Your screenshot does not capture the complete CLI command you invoked but I suspect that the transaction function name you supplied does not correctly include the name of the smart contract providing that transaction function.

Related

How to get block hash inside chaincode hyperledger fabric

Currently I'm working with Hyperledger Fabric chaincode and trying to get the hash of last block but I haven't found any way to get it. I need my chaincode to access this hash to do a security check.
I have tried to invoke qscc from my chaincode, which from a client does return blockchain and hash block information, but in this way access is restricted.
Code
#Transaction()
public String getBlockHash(final Context ctx) {
ChaincodeStub stub = ctx.getStub();
String[] argsQscc = {"GetChainInfo","mychannel"};
Response response = stub.invokeChaincodeWithStringArgs("qscc", argsQscc);
System.out.println("Result"+response.getMessage());
return response.getMessage();
}
Error
Rejecting invoke of QSCC from another chaincode because of potential for deadlocks, original invocation for 'mychaincode'.
It is not possible to get from within chaincode. I'm not sure you would want to anyways, because different peers may be at different heights and you would get different endorsement results leading to an invalidation of your transaction.
I'd suggest to have client query this information and pass it into the invoked chaincode as an input.

Get transaction details by TxID in hyperledger farbic

I am currently running hyperledger fabric v2.2. I have developed the chaincode using the contractapi and developing the application using fabric-sdk-go/pkg/gateway
How can i get the transaction status and the transaction payload? I am aware of the GetHistoryByKey() which is available in the contractapi but that doesn't works out for my application.
I know there is hyperledger-explorer which can be used to search transactions by TxID but my use-case is my application will be querying by TxID and then it will verify the status of that particular transaction (TxID).
Also, i have tried to achieve this using the fabsdk but i am getting an error when i try to create instantiate the fabsdk using the fabsdk.New(). There seems to be some compatibility issue with the connection-profile.json which i am using the fabric-sample project.
The error which i am getting is:
failed to create identity manager provider: failed to initialize identity manager for organization: MyOrgName: Either a cryptopath or an embedded list of users is required
The same connection-profile has been used in getting the network up and running, and everything seems to be working all good. I am able to submit and evaluate transactions.
SOLUTION
The system chaincodes are embedded in the peer itself. so we need to set the target otherwise it would just give the discovery error since the contract QSCC is not explicitly deployed on the channel.
Make sure to check the core.yaml file channel.system - the system chaincode should be enabled channel.system.qscc: enable
qsccContract := network.GetContract("qscc")
txn, err := qsccContract.CreateTransaction("GetTransactionByID", gateway.WithEndorsingPeers("peer0.org1.com:8051"))
if err != nil {
fmt.Printf("Failed to create transaction: %s\n", err)
return
}
result, err := txn.Evaluate("mychannel", "4b1175335bdfe074d516a69df180ed6bc14591543eb26c10e21df2c67602b2dc")
if err != nil {
fmt.Printf("Failed to submit transaction: %s\n", err)
return
}
fmt.Println(string(result))
Note: The result needs to decoded to be human readable
Your client application can use the client SDK appropriate to your pogramming language to evaluate the GetTransactionByID transaction function on the qscc system chaincode, which is available on all peers. This transaction function takes a transaction ID as its only argument and returns a peer.ProcessedTransaction protobuf, which contains the transaction envelope and a validation code.

How to get history of asset with block hash in hyperledger fabric using node sdk

I have assets whose state get updated and I want get history of that asset with previous_hash and current Block_hash. I am using CouchDB as State DB of Hyperledger Fabric.
I tried fabcar example function 'getHistoryForAsset' but it can give me only TxID but I need Block hash with this.
Can anybody help me how can we do it.
Thanks
Using the transaction ID you can call (evaluate) the GetBlockByTxID transaction function on the system qscc chaincode to get the block that contained that transaction. It expects a transaction ID as an argument and returns a common.Block protobuf response payload.
https://github.com/hyperledger/fabric-protos/blob/f44816d6f621f1f7615cb4fc65643791eb6d8ce6/common/common.proto#L142
Note that a block only contains the hash of the previous block, not the hash of itself.

Problem with Wallet Creation, signature error

I want to create a wallet for new rest api server, but whenever I call code to generate new Wallet I'm getting error like
"Decoding SignatureHeader failed: Error illegal buffer ..."
Here is screen shot of my code, it is taken from virtual machine
I'm using hyperledger fabric 2.2 and run under the fabric-samples/test-network
I was clone this HyperledgerFabroc
Here is also print screen of the error:
I would appreciate if someone can navigate me how to manage successfully to create a wallet ?
Your error looks to be occurring within a chaincode transaction function. You should not be using the client SDK to do a transaction invocation from within chaincode. Instead look to use the invokeChaincode function on the stub:
https://hyperledger.github.io/fabric-chaincode-node/release-1.4/api/fabric-shim.ChaincodeStub.html#invokeChaincode

Hyperledger Fabric invokeChaincode

I want to invoke another chaincode inside a chaincode using ctx.stub.invokeChaincode("called chaincode name", ["the name of the function (transaction) of the called chaincode", args]), and my both chaincodes has been instantiated on the same channel, but I get the following error:
Calling chaincode Invoke() returned error response [Error: You've
asked to invoke a function that does not exist: Confirm.confirmData].
Sending ERROR message back to peer.
I am not sure if I am wrong with defining the list chainCode arguments.

Resources