new AdminConnection( [options])
Create an instance of the AdminConnection class.
Parameters:
Name | Type | Argument | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
an optional set of options to configure the instance. Properties
|
Methods
-
connect(connectionProfile, enrollmentID, enrollmentSecret, businessNetworkIdentifier)
-
Connects and logs in to the Hyperledger Fabric using a named connection
profile. The connection profile must exist in the profile store.Parameters:
Name Type Description connectionProfile
string The name of the connection profile
enrollmentID
string the enrollment ID of the user
enrollmentSecret
string the enrollment secret of the user
businessNetworkIdentifier
string the id of the network (for update) or null
Returns:
A promise that indicates the connection is complete
- Type
- Promise
Example
// Connect to Hyperledger Fabric var adminConnection = new AdminConnection(); adminConnection.connect('testprofile', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(){ // Connected. }) .catch(function(error){ // Add optional error handling here. });
-
createProfile(connectionProfile, data)
-
Stores a connection profile into the profile store being used by this
AdminConnection.Parameters:
Name Type Description connectionProfile
string The name of the connection profile
data
Object The connection profile data
Returns:
A promise that indicates that the connection profile is deployed
- Type
- Promise
Example
// Create a connection profile var adminConnection = new AdminConnection(); var adminOptions = { type: 'hlf', keyValStore: '/tmp/keyValStore', membershipServicesURL: 'grpc://membersrvc:7054', peerURL: 'grpc://vp0:7051', eventHubURL: 'grpc://vp0:7053' }; return adminConnection.createProfile('testprofile', adminOptions) .then(function(){ // Created profile }) .catch(function(error){ // Add optional error handling here. });
-
deleteProfile(connectionProfile)
-
Deletes the specified connection profile from the profile store being used by this
AdminConnection.Parameters:
Name Type Description connectionProfile
string The name of the connection profile
Returns:
A promise that indicates that the connection profile is deployed
- Type
- Promise
Example
// Delete a connection profile var adminConnection = new AdminConnection(); return adminConnection.deleteProfile('testprofile') .then(function(){ // Deleted profile }) .catch(function(error){ // Add optional error handling here. });
-
deploy(businessNetworkDefinition)
-
Deploys a new BusinessNetworkDefinition to the fabric. The connection must
be connected for this method to succeed.Parameters:
Name Type Description businessNetworkDefinition
BusinessNetworkDefinition The business network to deploy
Returns:
A promise that will be fufilled when the business network has been
deployed.- Type
- Promise
Example
// Deploy a Business Network Definition var adminConnection = new AdminConnection(); var businessNetworkDefinition = BusinessNetworkDefinition.fromArchive(myArchive); return adminConnection.deploy(businessNetworkDefinition) .then(function(){ // Business network definition deployed }) .catch(function(error){ // Add optional error handling here. });
-
disconnect()
-
Disconnects this connection.
Returns:
A promise that will be resolved when the connection is
terminated.- Type
- Promise
Example
// Disconnect from a Business Network var adminConnection = new AdminConnection(); return adminConnection.disconnect() .then(function(){ // Disconnected. }) .catch(function(error){ // Add optional error handling here. });
-
getAllProfiles()
-
Retrieve all connection profiles from the profile store being used by this
AdminConnection.Returns:
A promise that is resolved with the connection profile data.
- Type
- Promise
Example
// Retrieve all the connection profiles. const adminConnection = new AdminConnection(); return adminConnection.getAllProfiles() .then((profiles) => { // Retrieved profiles for (let profile in profiles) { console.log(profile, profiles[profile]); } });
-
getProfile(connectionProfile)
-
Retrieve the specified connection profile from the profile store being
used by this AdminConnection.Parameters:
Name Type Description connectionProfile
string The name of the connection profile
Returns:
A promise that is resolved with the connection profile data.
- Type
- Promise
Example
// Retrieve the connection profile. const adminConnection = new AdminConnection(); return adminConnection.getProfile('testprofile') .then((profile) => { // Retrieved profile console.log(profile); });
-
list()
-
List all of the deployed business networks. The connection must
be connected for this method to succeed.Returns:
A promise that will be resolved with an array of
business network identifiers, or rejected with an error.- Type
- Promise
Example
// List all of the deployed business networks. var adminConnection = new AdminConnection(); return adminConnection.list() .then((businessNetworks) => { // Connection has been tested return businessNetworks.forEach((businessNetwork) => { console.log('Deployed business network', businessNetwork); }); }) .catch(function(error){ // Add optional error handling here. });
-
ping()
-
Test the connection to the runtime and verify that the version of the
runtime is compatible with this level of the node.js module.Returns:
A promise that will be fufilled when the connection has
been tested. The promise will be rejected if the version is incompatible.- Type
- Promise
Example
// Test the connection to the runtime var adminConnection = new AdminConnection(); return adminConnection.ping() .then(function(){ // Connection has been tested }) .catch(function(error){ // Add optional error handling here. });
-
undeploy(businessNetworkIdentifier)
-
Undeploys a BusinessNetworkDefinition from the fabric. The business network will no
longer be able to process transactions.Parameters:
Name Type Description businessNetworkIdentifier
string The identifier of the network to undeploy
Returns:
A promise that will be fufilled when the business network has been
undeployed.- Type
- Promise
Example
// Undeploy a Business Network Definition var adminConnection = new AdminConnection(); return adminConnection.undeploy('identifier') .then(function(){ // Undeployed Business Network Definition }) .catch(function(error){ // Add optional error handling here. })
-
update(businessNetworkDefinition)
-
Updates an existing BusinessNetworkDefinition on the fabric. The BusinessNetworkDefinition
must have been previously deployed.Parameters:
Name Type Description businessNetworkDefinition
BusinessNetworkDefinition The new BusinessNetworkDefinition
Returns:
A promise that will be fufilled when the business network has been
updated.- Type
- Promise
Example
// Updates a Business Network Definition var adminConnection = new AdminConnection(); var businessNetworkDefinition = BusinessNetworkDefinition.fromArchive(myArchive); return adminConnection.update(businessNetworkDefinition) .then(function(){ // Business network definition updated }) .catch(function(error){ // Add optional error handling here. });