IBM Blockchain Platform Node.js客户端应用程序无法提交事务:没有为MSP'org1Admin'定义的对等方可以从中发现

我在IBM Blockchain Platform云中部署了一个非常基本的IBM Blockchain网络:只有一个对等组织和一个订购组织。我已经安装并实例化了一个非常基本的合同(只是CRUD操作),现在我正在尝试使用模板Nodejs客户端应用程序为我的资产提交创建交易;这是我的代码:

'use strict';

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

async function main() {
  try {

    // Parse the connection profile. This would be the path to the file downloaded
    // from the IBM Blockchain Platform operational console.
    const ccpPath = path.resolve(__dirname,'connection.json');
    const ccp = JSON.parse(fs.readFileSync(ccpPath,'utf8'));

    // Configure a wallet. This wallet must already be primed with an identity that
    // the application can use to interact with the peer node.
    const walletPath = path.resolve(__dirname,'wallet');
    const wallet = new FileSystemWallet(walletPath);

    // Create a new gateway,and connect to the gateway peer node(s). The identity
    // specified must already exist in the specified wallet.
    const gateway = new Gateway();

    await gateway.connect(ccp,{ wallet: wallet,identity: 'orgAdmin',discovery: {"enabled": true,"asLocalhost":false }});

    // Get the network channel that the smart contract is deployed to.
    const network = await gateway.getNetwork('erschannel');

    // Get the smart contract from the network channel.
    const contract = network.getcontract('ers_contract');

    // Submit the 'createCar' transaction to the smart contract,and wait for it
    // to be committed to the ledger.
    await contract.submitTransaction('createErsGenHash','ersGenHashId_1','ersGenHashId_1_value');
    console.log('Transaction has been submitted');

    await gateway.disconnect();

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

我已经成功注册了身份 orgAdmin ,并将其下载到我的本地钱包中(至少我没事!!)。执行以上操作时,出现以下错误:

C:\work\hlf>node invoke.js
2020-06-04T18:34:28.213Z - error: [Network]: _initializeInternalChannel: No peers defined for MSP 'orgAdmin' to discover from
Failed to submit transaction: Error: No peers defined for MSP 'orgAdmin' to discover from

这是我的 connection.json 概要文件(我从IBM Blockchain Platform控制台下载了);奇怪的是没有订购信息:

{
    "name": "ORG1MSPprofile","description": "Network on IBP v2","version": "1.0.0","client": {
        "organization": "ORG1MSP"
    },"organizations": {
        "ORG1MSP": {
            "mspid": "ORG1MSP","certificateAuthorities": [
                "184.172.233.238:31951"
            ],"peers": [
                "184.172.233.238:30604"
            ]
        }
    },"peers": {
        "184.172.233.238:30604": {
            "url": "grpcs://184.172.233.238:30604","tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nxxxxxxxxxxx\n-----END CERTIFICATE-----\n"
            },"grpcOptions": {
                "ssl-target-name-override": "184.172.233.238"
            }
        }
    },"certificateAuthorities": {
        "184.172.233.238:31951": {
            "url": "https://184.172.233.238:31951","caName": "ca","tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nxxxxxxxxxxx\n-----END CERTIFICATE-----\n"
            }
        }
    }
}

我怀疑问题出在我如何配置IBM云区块链网络。我遵循了有关从here构建网络的官方教程。

iCMS 回答:IBM Blockchain Platform Node.js客户端应用程序无法提交事务:没有为MSP'org1Admin'定义的对等方可以从中发现

问题的关键是此错误消息

Error: No peers defined for MSP 'orgAdmin' to discover from

您已经以orgAdmin的mspid在钱包中注册了自己的身份。在您的连接配置文件中,定义的mspid为ORG1MSP

    "organizations": {
        "ORG1MSP": {
            "mspid": "ORG1MSP"

因此,当客户端尝试找到与您选择的身份一起使用的对等方时,它会尝试使用mspid orgAdmin来查找属于组织一部分的对等方,而该mspid在您的连接配置文件中不是已知的mspid,这样会导致您看到错误消息。解决方案是删除并重新导入您的身份(或只是从一个新的钱包开始),然后使用正确的mspid再次导入该身份。

还完全可以在连接配置文件中不包含订购者列表。这称为动态连接配置文件,其中包含交互所需的最少信息。客户端sdk从对等方处discovered来其余所需的信息,例如其他对等方和订购者。正如您在代码中看到的那样,您已指定启用发现。

本文链接:https://www.f2er.com/2201812.html

大家都在问