0

i'm trying to install java chaincode of facar from fabric-samples but getting error.

https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode/fabcar/java

above chaincode i'm trying & getting error during instantiation of chaincode

can someone please help me on it, much appreciated & thanks in advance.

i'm using basic network folder and below script for network creation & install,instantiate and invoke chaincode.

#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Exit on first error, print all commands.
set -ev

# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1

docker-compose -f docker-compose.yml down

docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb
docker ps -a

# wait for Hyperledger Fabric to start
# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>
export FABRIC_START_TIMEOUT=10
#echo ${FABRIC_START_TIMEOUT}
sleep ${FABRIC_START_TIMEOUT}

# Create the channel
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
# Join peer0.org1.example.com to the channel.
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block

docker-compose -f docker-compose.yml up -d cli
sleep 5

#install chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n mycc -v 1.0 -p /opt/gopath/src/github.com/fabcar/java -l java

#instantiate chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -l java -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

sleep 5

#invoke chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051"  -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc -c '{"function":"initLedger","Args":[""]}'

Output of docker logs peer0.org1.example.com command given below

2019-08-06 09:54:26.150 UTC [endorser] SimulateProposal -> ERRO 043 [mychannel][e0746cf6] failed to invoke chaincode name:"lscc" , error: transaction returned with failure: Undefined contract method called

Output of docker logs dev-peer0.org1.example.com-mycc-1.0 command given below

09:54:26:142 SEVERE  org.hyperledger.fabric.Logger error                                              Undefined contract method

calledorg.hyperledger.fabric.shim.ChaincodeException: Undefined contract method called at org.hyperledger.fabric.contract.ContractInterface.unknownTransaction(ContractInterface.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hyperledger.fabric.contract.execution.impl.ContractExecutionService.executeRequest(ContractExecutionService.java:57) at org.hyperledger.fabric.contract.ContractRouter.processRequest(ContractRouter.java:87) at org.hyperledger.fabric.contract.ContractRouter.init(ContractRouter.java:103) at org.hyperledger.fabric.shim.impl.Handler.lambda$handleInit$0(Handler.java:280) at java.lang.Thread.run(Thread.java:748)

:54:26:147 SEVERE  org.hyperledger.fabric.shim.impl.Handler lambda$handleInit$0                     [e0746cf6] Init failed.

Sending ERROR

Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60

3 Answers3

2

Maybe you have forgotten the @Default decorator

@Contract(name = "MyContract",
        info = @Info(
                title = "My Contract",
                description = "",
                version = "0.0.1"
        )
)
@Default
public class MyContract implements ContractInterface {
David Viejo
  • 751
  • 1
  • 6
  • 6
0

Undefined contract method called

Is in the first few lines of the code.This means the function you passing to invoke is not present in the chaincode,Can you check the chaincode and see if the initLedger is present?or is there any spelling errors. Hope this was usefull.

Risabh Sharma
  • 634
  • 5
  • 15
0

In case you are facing this issue while instantiating a chain code, then you can override following method given in ContractInterface with your custom implementation.

/**
 * Invoked for any transaction that does not exist.
 *
 * This will throw an exception. If you wish to alter the exception thrown or 
 * if you wish to consider requests for transactions that don't exist as not an
 * error, subclass this method.
 *
 * @param ctx the context as created by {@link #createContext(ChaincodeStub)}.
 */
default void unknownTransaction(Context ctx) {
    throw new ChaincodeException("Undefined contract method called");
}

Otherwise, if the issue occurs while invoking existing transaction then ensure that annotation @Transaction() is present on transaction method.

Sanjay
  • 53
  • 6