【问题标题】:Getting error while invoke chaincode as "Incorrect number of arguments. Expecting 6"调用链代码时出错“参数数量不正确。预期为 6”
【发布时间】:2019-08-06 18:30:23
【问题描述】:

我正在尝试调用链码函数,但出现错误“参数数量不正确。预期为 6”。

我检查了我的链码是否正常且运行良好。我不明白为什么它会出错。因为函数中有正确数量的参数。

链码函数

func (s *SmartContract) recordProduce(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {

    if len(args) != 5 {
        return shim.Error("Incorrect number of arguments. Expecting 5")
    }

    var Produce = Produce{ProduceName: args[1], Health: args[2], Owner : arg[3], FarmID: args[4]}

    ProduceAsBytes, _ := json.Marshal(Produce)
    APIstub.PutState(args[0], ProduceAsBytes)

    return shim.Success(nil)
}

调用.js

'use strict';

const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');

const ccpPath =  path.resolve(__dirname, '..', '..', 'basic-network', 'connection.json');

async function main() {
    try {

        // Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        // Check to see if we've already enrolled the user.
        const userExists = await wallet.exists('user1');
        if (!userExists) {
            console.log('An identity for the user "user1" does not exist in the wallet');
            console.log('Run the registerUser.js application before retrying');
            return;
        }

        // Create a new gateway for connecting to our peer node.
        const gateway = new Gateway();
        await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: false, asLocalhost: true } , eventHandlerOptions: {
            strategy: null
        } 
    });

        // Get the network (channel) our contract is deployed to.
        const network = await gateway.getNetwork('dfarmchannel');

        // Get the contract from the network.
        const contract = network.getContract('produce-app');


        await contract.submitTransaction('recordProduce', 'PR12', 'Banana', 'Good', 'Abhi', 'FARM111');
        console.log('Transaction has been submitted');

        // Disconnect from the gateway.
        await gateway.disconnect();

    } catch (error) {
        console.error(`Failed to submit transaction: ${error}`);
        process.exit(1);
    }
}

main();

错误:

【问题讨论】:

    标签: hyperledger-fabric hyperledger


    【解决方案1】:

    您的源代码有错误消息“参数数量不正确。应为 5”,但您收到“参数数量不正确。应为 6”。 你能确定你使用的是正确版本的链码吗?

    如果您更新了链码,请检查您是否使用正确的源代码和版本号运行 peer chaincode installpeer chaincode upgrade

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多