我在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构建网络的官方教程。