Class: Client

Client

This class represents a Client, the central place for connection and config information.

new Client(name)

Construct a Client object.
Parameters:
Name Type Description
name string The name of the client.
Returns:
The Client instance.
Type
Client

Methods


<static> getConfigSetting(name, default_value)

Retrieves a setting from the hierarchical configuration and if not found will return the provided default value.

The hierarchical configuration settings search order for a setting aa-bb:
  1. memory: if the setting has been added with
    Client.setConfigSetting('aa-bb', 'value')
  2. Command-line arguments: like
    node app.js --aa-bb value
  3. Environment variables:
    AA_BB=value node app.js
  4. Custom Files: all files added with addConfigFile(path) will be ordered by when added, where same settings in the files added later will override those added earlier
  5. The file located at lib/config/default.json with default settings
Parameters:
Name Type Description
name String The name of a setting
default_value Object The value of a setting if not found in the hierarchical configuration

<static> newClient(name)

Construct a Client object.
Parameters:
Name Type Description
name string The name of the client.

<static> setConfigSetting(name, value)

Adds a setting to override all settings that are part of the hierarchical configuration.
Parameters:
Name Type Description
name String The name of a setting
value Object The value of a setting

addTlsClientCertAndKey(options)

Utility method to add the mutual tls client material to a set of options.
Parameters:
Name Type Description
options ConnectOptions The options object holding the connection settings that will be updated with the mutual TLS clientCert and clientKey.
Throws:
Will throw an error if generating the tls client material fails

getChannel(name)

Returns a Channel instance with the given name. Will return an existing instance or create a new one and store a reference to this instance.
Parameters:
Name Type Description
name string The name of the channel.
Returns:
The channel instance.
Type
Channel

getCommitter(name [, mspid])

Returns a Committer instance with the given name. Will return an existing instance if one exist or it will create a new instance and save a reference.
Parameters:
Name Type Argument Description
name string The name of the committer.
mspid string <optional>
Optional. The MSP id
Returns:
The committer instance.
Type
Committer

getCommitters( [mspid])

Will return an array of Committer instances that have been assigned to this channel instance. Include a MSPID to only return committers in a specific organization.
Parameters:
Name Type Argument Description
mspid string <optional>
Optional. The mspid of the endorsers to return
Returns:
the list of Committers.
Type
Array.<Committer>

getConnectionOptions(options)

Utility method to merge connection options. The tls mutual and default connection options from the config will not override any passed in settings of the same name.
Parameters:
Name Type Description
options ConnectOptions The object holding the application options that will be merged on top of this client's options.
Returns:
- The object holding both the application's options and this client's options.
Type
object

getEndorser(name [, mspid])

Returns a Endorser instance with the given name. Will return an existing instance if one exist or it will create a new instance and save a reference.
Parameters:
Name Type Argument Description
name string The name of the endorser.
mspid string <optional>
Optional. The MSP id
Returns:
The endorser instance.
Type
Endorser

getEndorsers( [mspid])

Will return an array of Endorser instances that have been created by this client instance. Include a MSPID to only return endorsers in a specific organization.
Parameters:
Name Type Argument Description
mspid string <optional>
Optional. The mspid of the endorsers to return
Returns:
the list of Endorsers.
Type
Array.<Endorser>

newChannel(name)

Returns a Channel instance with the given name. Will return a new instance. Does not check for existing instances and does not keep a reference to this instance.
Parameters:
Name Type Description
name string The name of the channel.
Returns:
The channel instance.
Type
Channel

newCommitter(name [, mspid])

Returns a Committer instance with the given name. Will return a new instance. Does not check for existing instances and does not keep a reference to this instance.
Parameters:
Name Type Argument Description
name string The name of the Committer.
mspid string <optional>
Optional. The MSP id
Returns:
The committer instance.
Type
Committer

newDiscoverer(name [, mspid])

Returns a Discoverer instance with the given name. Will return a new instance. Does not check for existing instances and does not keep a reference to this instance.
Parameters:
Name Type Argument Description
name string The name of the Discoverer.
mspid string <optional>
Optional. The MSP id
Returns:
The Discoverer instance.
Type
Discoverer

newEndorser(name [, mspid])

Returns a Endorser instance with the given name. Will return a new instance. Does not check for existing instances and does not keep a reference to this instance.
Parameters:
Name Type Argument Description
name string The name of the endorser.
mspid string <optional>
Optional. The MSP id
Returns:
The endorser instance.
Type
Endorser

newEndpoint(options)

Use this method to build an endpoint options object. This may be reused when connecting to endorsers, committers, discovers and eventers. The input opts must have an "url" for connecting to a fabric service.
Parameters:
Name Type Description
options ConnectOptions

newEventer(name [, mspid])

Returns a Eventer instance with the given name. Will return a new instance. Does not check for existing instances and does not keep a reference to this instance.
Parameters:
Name Type Argument Description
name string The name of the Eventer.
mspid string <optional>
Optional. The MSP id
Returns:
The Eventer instance.
Type
Eventer

newIdentityContext( [user])

Builds an IdentityContext instance with the given user. Will be used when building proposals, commits, and queries.
Parameters:
Name Type Argument Description
user User <optional>
instance

setCentralizedConnectionOptions(options)

Utility method to set the connection options required by this Client (application). These will be merged into new endpoints as this client creates new endpoints. Options provided here will override the default 'conection-options' from the config file ./config/default.json.
Parameters:
Name Type Description
options object The options to be used by gRPC connections.
Returns:
The Client instance.
Type
Client
Example
{
		"grpc.max_receive_message_length": -1,
		"grpc.max_send_message_length": -1,
		"grpc.keepalive_time_ms": 120000,
 		"grpc.http2.min_time_between_pings_ms": 120000,
		"grpc.keepalive_timeout_ms": 20000,
		"grpc.http2.max_pings_without_data": 0,
		"grpc.keepalive_permit_without_calls": 1,
		"grpc-wait-for-ready-timeout": 3000,
		"request-timeout" : 45000
	 }

setTlsClientCertAndKey(clientCert, clientKey)

Sets the mutual TLS client side certificate and key necessary to build network endpoints when working with a common connection profile (connection profile). This must be called before a endorser, committer, or channel eventhub is needed. If the tls client material has not been provided for the client, it will be generated if the user has been assigned to this client. Note that it will always use the default software cryptosuite, not the one assigned to the client.
Parameters:
Name Type Description
clientCert string The pem encoded client certificate.
clientKey Array.<byte> The client key.

toString()

return a printable representation of this object