未能调用链代码名称:“lscc”,错误:事务返回失败:调用了未定义的合约方法

我正在尝试从 fabric-samples 安装 facar 的 java 链代码,但出现错误。

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

在链码上方,我正在尝试并在链码实例化期间出现错误

有人可以帮助我吗,非常感谢并提前致谢。

我正在使用基本网络文件夹和下面的脚本来创建和安装网络,实例化和调用链代码。

#!/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


qq_遁去的一_1
浏览 233回答 3
3回答

Qyouu

也许你忘记了@Default装饰器@Contract(name = "MyContract",&nbsp; &nbsp; &nbsp; &nbsp; info = @Info(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title = "My Contract",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description = "",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; version = "0.0.1"&nbsp; &nbsp; &nbsp; &nbsp; ))@Defaultpublic class MyContract implements ContractInterface {

慕标琳琳

调用了未定义的合约方法在代码的前几行。这意味着您传递给调用的函数不存在于链码中,您可以检查链码并查看 initLedger 是否存在?或者是否存在任何拼写错误。希望这是有用的。

森林海

如果您在实例化链码时遇到此问题,则可以使用您的自定义实现覆盖ContractInterface中给出的以下方法。/**&nbsp;* Invoked for any transaction that does not exist.&nbsp;*&nbsp;* This will throw an exception. If you wish to alter the exception thrown or&nbsp;&nbsp;* if you wish to consider requests for transactions that don't exist as not an&nbsp;* error, subclass this method.&nbsp;*&nbsp;* @param ctx the context as created by {@link #createContext(ChaincodeStub)}.&nbsp;*/default void unknownTransaction(Context ctx) {&nbsp; &nbsp; throw new ChaincodeException("Undefined contract method called");}否则,如果在调用现有事务时出现问题,则确保注释@Transaction() 存在于事务方法中。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java