Problem with Node-SDk with fabric-network package when invoke transaction

Tharindu Sandaruwan <TharinduSA@...>
 

Dear Sir/Madam

 

I have set up a network and create a nodejs application to connect with it using nodejs SDK. When I try to invoke a transaction it leaves me this output on the terminal.

Failed to submit transaction: Error: PEM encoded certificate is required.

Then I look for the logs of dev-peers it leaves me an error like this.

17 ssl_transport_security.cc:238] Could not get common name of subject from certificate.

This is how my connection.json file looks like.

{
"name": "basic-network",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"orderers": ["orderer.example.com"],
"peers": {
"peer0.org1.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
},
"peer0.org2.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": ["ca.org1.example.com"],
"adminPrivateKey": {
"path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@.../msp/keystore/8f3055ee24c8e4575f2fea297a7bbde998i63b7451ea8f7880b5cb91ec24a7d_sk"
},
"signedCert": {
"path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@.../msp/signcerts/Admin@..."
}
},
"Org2": {
"mspid": "Org2MSP",
"peers": [
"peer0.org2.example.com",
"peer1.org2.example.com"
],
"certificateAuthorities": ["ca.org2.example.com"],
"adminPrivateKey": {
"path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@.../msp/keystore/e2537a15b0609866b4ec1f70e7a4f77qf915653980f9788af8d2f2b67bdf910_sk"
},
"signedCert": {
"path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@.../msp/signcerts/Admin@..."
}
}
},
"orderers": {
"orderer.example.com": {
"url": "grpcs://localhost:7050",
"grpcOptions": {
"ssl-target-name-override": "orderer.example.com",
"grpc-max-send-message-length": 15
},
" tlsCACerts": {
"path": "../crypto-config/ordererOrganizations/trafficfine.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
}
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"eventUrl": "grpcs://localhost:8053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
}
},
"peer0.org2.example.com": {
"url": "grpcs://localhost:9051",
"eventUrl": "grpcs://localhost:9053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org2.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
}
},
"peer1.org2.example.com": {
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"httpOptions": {
"verify": false
},
"caName": "ca.org1.example.com",
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
}
},
"ca.org2.example.com": {
"url": "https://localhost:7054",
"httpOptions": {
"verify": false
},
"caName": "ca.org2.example.com",
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem"
}
}
}
}

This is how my invoke.js file looks like.

/*
* SPDX-License-Identifier: Apache-2.0
*/

"use strict";

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

const ccpPath = path.resolve(__dirname, ".", "connection.json");
const ccpJSON = fs.readFileSync(ccpPath, "utf8");
const ccp = JSON.parse(ccpJSON);

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("TharinduSA");
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(ccp, {
wallet,
identity: "TharinduSA",
discovery: { enabled: false }
});

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork("mychannel");
// console.log(network);

// Get the contract from the network.
const contract = network.getContract("fabcar");
// console.log(contract);

// Submit the specified transaction.
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR10', 'Dave')
await contract.submitTransaction(
"createCar",
"CAR12",
"Honda",
"Accord",
"Black",
"Tom"
);
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();

 

I tried to figure it out. But I was unable to find any solution for this Issue if you can give me any solution to this problem It would be grateful for me. Thank you!

Join fabric@lists.hyperledger.org to automatically receive all group messages.