Getting error as : Error: Client.createUser parameter 'opts mspid' is required
Getting error as : Error: Client.createUser parameter 'opts mspid' is required
我正在尝试使用 IBM 区块链。我已经在 IBM 区块链上创建了设置,现在我正尝试通过 IBM 区块链上的节点 SDK 注册用户,但是,当我尝试将应用程序管理员注册到 IBM 区块链时,我遇到了问题。
请帮我找出问题所在,或者让我知道哪里做错了。
连接文件。
{
"name": "mychannel",
"description": "Network on IBP v2",
"version": "1.0.0",
"client": {
"organization": "org1msp"
},
"organizations": {
"org1msp": {
"mspid": "org1msp",
"peers": [
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
],
"certificateAuthorities": [
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054"
]
},
"org2MSP": {
"mspid": "org2MSP",
"peers": [
"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
]
}
},
"orderers": {
"n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
}
},
"peers": {
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051",
"tlsCACerts": {
},
"grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
},
"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051",
"tlsCACerts": {
},
"grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1retail.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
}
},
"certificateAuthorities": {
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054": {
"url": "https://n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054",
"caName": "ca",
"tlsCACerts": {
}
}
}
}
我的配置文件。
{
"connection_file": "connection.json",
"appAdmin": "admin",
"appAdminSecret": "org1capw",
"orgMSPIiD": "dFarmMSP",
"caName": "n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054",
"channelname": "mychannle",
"username":" ",
"role":" ",
"chaincodeName":"dfarmsm",
"gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}
node.js管理员注册码
'use strict';
const FabricCAServices = require('fabric-ca-client');
const {
FileSystemWallet,
Gateway,
X509WalletMixin
} = require('fabric-network');
const fs = require('fs');
const path = require('path');
var MongoClient = require('mongodb').MongoClient;
var Client = require('node-rest-client').Client;
var client = new Client();
const configPath = path.resolve(__dirname, '..', 'config', 'Config.json');
const configJSON = fs.readFileSync(configPath, 'utf8');
const config1 = JSON.parse(configJSON);
var connection_file = config1.connection_file;
var appAdmin = config1.appAdmin;
var gatewayDiscovery = config1.gatewayDiscovery;
var appAdminSecret = config1.appAdminSecret;
var orgMSPID = config1.orgMSPID;
var caName = config1.caName;
const ccpPath = path.resolve(__dirname, '..', 'config', 'connection.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);
let response = {};
class FabricClientRegister {
constructor() {
console.log("called constructer");
}
async RegisterAdmin() {
try {
const setAsyncTimeout = (cb, timeout = 0) => new Promise(resolve => {
setTimeout(() => {
cb();
resolve();
}, timeout);
});
// Create a new CA client for interacting with the CA.
const caURL = ccp.certificateAuthorities[caName].url;
const ca = new FabricCAServices(caURL);
// 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}`);
// logger.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the admin user.
const adminExists = await wallet.exists(appAdmin);
// console.log('here is admin exit')
// console.log('AdminExits', adminExists);
if (adminExists) {
response.data = null;
response.httpstatus = 400;
response.message = `An identity for the admin user ${appAdmin} already exists in the wallet`
// console.log('res', response)
return response;
}
// Enroll the admin user and import the new identity into the wallet.
const enrollment = await ca.enroll({
enrollmentID: appAdmin,
enrollmentSecret: appAdminSecret
});
const identity = X509WalletMixin.createIdentity(orgMSPID, enrollment.certificate, enrollment.key.toBytes());
wallet.import(appAdmin, identity);
// logger.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
console.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
response.data = identity;
response.httpstatus = 200;
response.message = "admin enrolled successfully"
return response;
} catch (error) {
response.error = error;
response.httpstatus = 500;
response.message = "Failed to enroll admin due to above error";
return response;
}
};
如果我遗漏了什么,请告诉我。并感谢您的提前。
您传递给 createIdentity
的 mspid 值为空。在您的配置中,您将 msp id 定义为
"orgMSPIiD": "dFarmMSP",
而在您的代码中您尝试将其检索为
var orgMSPID = config1.orgMSPID;
(注意 iD
与 ID
之间的区别)
所以基本上 orgMSPID
的值将是 undefined
。
但是,由于没有给出 mspid,因此 createIdentity 报告错误会很有用,因此我建议您在 https://jira.hyperledger.org 为 fabric-sdk-node 项目 (FABN) 提出一个 jira,并建议createIdentity 应检查输入参数中是否存在未定义的 mspid
我正在尝试使用 IBM 区块链。我已经在 IBM 区块链上创建了设置,现在我正尝试通过 IBM 区块链上的节点 SDK 注册用户,但是,当我尝试将应用程序管理员注册到 IBM 区块链时,我遇到了问题。
请帮我找出问题所在,或者让我知道哪里做错了。
连接文件。
{
"name": "mychannel",
"description": "Network on IBP v2",
"version": "1.0.0",
"client": {
"organization": "org1msp"
},
"organizations": {
"org1msp": {
"mspid": "org1msp",
"peers": [
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
],
"certificateAuthorities": [
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054"
]
},
"org2MSP": {
"mspid": "org2MSP",
"peers": [
"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
]
}
},
"orderers": {
"n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
},
"n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050",
"tlsCACerts": {
}
}
},
"peers": {
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051",
"tlsCACerts": {
},
"grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
},
"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051",
"tlsCACerts": {
},
"grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1retail.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
}
},
"certificateAuthorities": {
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054": {
"url": "https://n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054",
"caName": "ca",
"tlsCACerts": {
}
}
}
}
我的配置文件。
{
"connection_file": "connection.json",
"appAdmin": "admin",
"appAdminSecret": "org1capw",
"orgMSPIiD": "dFarmMSP",
"caName": "n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054",
"channelname": "mychannle",
"username":" ",
"role":" ",
"chaincodeName":"dfarmsm",
"gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}
node.js管理员注册码
'use strict';
const FabricCAServices = require('fabric-ca-client');
const {
FileSystemWallet,
Gateway,
X509WalletMixin
} = require('fabric-network');
const fs = require('fs');
const path = require('path');
var MongoClient = require('mongodb').MongoClient;
var Client = require('node-rest-client').Client;
var client = new Client();
const configPath = path.resolve(__dirname, '..', 'config', 'Config.json');
const configJSON = fs.readFileSync(configPath, 'utf8');
const config1 = JSON.parse(configJSON);
var connection_file = config1.connection_file;
var appAdmin = config1.appAdmin;
var gatewayDiscovery = config1.gatewayDiscovery;
var appAdminSecret = config1.appAdminSecret;
var orgMSPID = config1.orgMSPID;
var caName = config1.caName;
const ccpPath = path.resolve(__dirname, '..', 'config', 'connection.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);
let response = {};
class FabricClientRegister {
constructor() {
console.log("called constructer");
}
async RegisterAdmin() {
try {
const setAsyncTimeout = (cb, timeout = 0) => new Promise(resolve => {
setTimeout(() => {
cb();
resolve();
}, timeout);
});
// Create a new CA client for interacting with the CA.
const caURL = ccp.certificateAuthorities[caName].url;
const ca = new FabricCAServices(caURL);
// 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}`);
// logger.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the admin user.
const adminExists = await wallet.exists(appAdmin);
// console.log('here is admin exit')
// console.log('AdminExits', adminExists);
if (adminExists) {
response.data = null;
response.httpstatus = 400;
response.message = `An identity for the admin user ${appAdmin} already exists in the wallet`
// console.log('res', response)
return response;
}
// Enroll the admin user and import the new identity into the wallet.
const enrollment = await ca.enroll({
enrollmentID: appAdmin,
enrollmentSecret: appAdminSecret
});
const identity = X509WalletMixin.createIdentity(orgMSPID, enrollment.certificate, enrollment.key.toBytes());
wallet.import(appAdmin, identity);
// logger.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
console.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
response.data = identity;
response.httpstatus = 200;
response.message = "admin enrolled successfully"
return response;
} catch (error) {
response.error = error;
response.httpstatus = 500;
response.message = "Failed to enroll admin due to above error";
return response;
}
};
如果我遗漏了什么,请告诉我。并感谢您的提前。
您传递给 createIdentity
的 mspid 值为空。在您的配置中,您将 msp id 定义为
"orgMSPIiD": "dFarmMSP",
而在您的代码中您尝试将其检索为
var orgMSPID = config1.orgMSPID;
(注意 iD
与 ID
之间的区别)
所以基本上 orgMSPID
的值将是 undefined
。
但是,由于没有给出 mspid,因此 createIdentity 报告错误会很有用,因此我建议您在 https://jira.hyperledger.org 为 fabric-sdk-node 项目 (FABN) 提出一个 jira,并建议createIdentity 应检查输入参数中是否存在未定义的 mspid