hyperledger-fabricibm-blockchain

IBM Blockchain Platform Nodejs client app can't submit transaction: No peers defined for MSP 'org1Admin' to discover from


I have deployed a very basic IBM Blockchain network in the IBM Blockchain Platform cloud: just one peer organization and one orderer org. I have installed and instantiated a very basic contract (just CRUD operations) and I am now trying to submit the create transaction for my asset using the template Nodejs client app; here is my code:

'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();

I have successfully enrolled the identity orgAdmin and downloaded it in my local wallet (at least I got something right !!). When executing the above I get the following error:

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

Here is my connection.json profile (which I downloaded from the IBM Blockchain Platform console); it is strange that there is no orderer information:

{
    "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"
            }
        }
    }
}

I suspect the problem is in how I configured the IBM cloud blockchain network. I followed the official tutorial on building a network from here .


Solution

  • The key to your problem is this error message

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

    you have registered your identity in your wallet with an mspid of orgAdmin. In your connection profile the defined mspid is ORG1MSP

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

    so when the client tries to find a peer to use with the identity you have selected it tries to find a peer which is part of the org with mspid orgAdmin which is not a known mspid in your connection profile, so that results in the error message you see. The solution will be to delete and re-import your identity (or just start with a new wallet) and import the identity again with the correct mspid.

    Also it's totally expected to not have the list of orderers in the connection profile. This is called a dynamic connection profile and contains the minimum information needed to interact. The rest of the required information such as other peers and orderers are discovered from a peer by the client sdk. As you can see in your code you have specified to enable discovery.