Class: Gateway

fabric-network~ Gateway

The gateway peer provides the connection point for an application to access the Fabric network. It is instantiated using the default constructor. It can then be connected to a fabric network using the connect method by passing either a CCP definition or an existing Client object. Once connected, it can then access individual Network instances (channels) using the getNetwork method which in turn can access the smart contracts installed on a network and submit transactions to the ledger.

new Gateway()

Methods


<async> connect(config, options)

Connect to the Gateway with a connection profile or a prebuilt Client instance.
Parameters:
Name Type Description
config string | object | Client The configuration for this Gateway which can be:
  • A fully qualified common connection profile file path (String)
  • A common connection profile JSON (Object)
  • A pre-configured client instance
options module:fabric-network.Gateway~GatewayOptions specific options for creating this Gateway instance
Example
const gateway = new Gateway();
const wallet = new FileSystemWallet('./WALLETS/wallet');
const ccpFile = fs.readFileSync('./network.json');
const ccp = JSON.parse(ccpFile.toString());
await gateway.connect(ccp, {
  identity: 'admin',
  wallet: wallet
});

disconnect()

Clean up and disconnect this Gateway connection in preparation for it to be discarded and garbage collected

getClient()

Get the underlying Client object instance
Returns:
The underlying client instance
Type
Client

getCurrentIdentity()

Get the current identity
Returns:
The current identity used by this Gateway.
Type
User

<async> getNetwork(networkName)

Returns an object representing a network
Parameters:
Name Type Description
networkName string The name of the network (channel name)
Returns:
Type
module:fabric-network.Network

getOptions()

Returns the set of options associated with the Gateway connection
Returns:
The Gateway connection options
Type
module:fabric-network.Gateway~GatewayOptions

Type Definitions


AbstractEventHubSelectionStrategy

Type:
  • Object
Properties:
Name Type Description
getNextPeer function Function that returns the next peer in the list of available peers
updateEventHubAvailability function Function that updates the availability of an event hub

DefaultEventHandlerOptions

Type:
  • Object
Properties:
Name Type Argument Default Description
commitTimeout number <optional>
300 The timeout period in seconds to wait for commit notification to complete.
strategy module:fabric-network.Gateway~TxEventHandlerFactory <optional>
<nullable>
MSPID_SCOPE_ALLFORTX Event handling strategy to identify successful transaction commits. A null value indicates that no event handling is desired. The default is MSPID_SCOPE_ALLFORTX.

DefaultEventHubSelectionFactory

Type:
  • Object

DefaultEventHubSelectionOptions

Type:
  • Object
Properties:
Name Type Argument Default Description
strategy module:fabric-network.Gateway~DefaultEventHubSelectionFactory <optional>
<nullable>
MSPID_SCOPE_ROUND_ROBIN Selects the next event hub in the event of a new listener being created or an event hub disconnect

DefaultQueryHandlerOptions

Type:
  • Object
Properties:
Name Type Argument Default Description
strategy module:fabric-network.Gateway~QueryHandlerFactory <optional>
MSPID_SCOPE_SINGLE Query handling strategy used to evaluate queries. The default is MSPID_SCOPE_SINGLE.

DiscoveryOptions

Type:
  • Object
Properties:
Name Type Argument Default Description
enabled boolean <optional>
true True if discovery should be used; otherwise false.
asLocalhost boolean <optional>
true Convert discovered host addresses to be 'localhost'. Will be needed when running a docker composed fabric network on the local system; otherwise should be disabled.

GatewayOptions

Type:
  • Object
Properties:
Name Type Argument Description
wallet module:fabric-network.Wallet The identity wallet implementation for use with this Gateway instance.
identity string The identity in the wallet for all interactions on this Gateway instance.
clientTlsIdentity string <optional>
The identity in the wallet to use as the client TLS identity.
eventHandlerOptions module:fabric-network.Gateway~DefaultEventHandlerOptions <optional>
Options for the inbuilt default event handler capability.
queryHandlerOptions module:fabric-network.Gateway~DefaultQueryHandlerOptions <optional>
Options for the inbuilt default query handler capability.
discovery module:fabric-network.Gateway~DiscoveryOptions <optional>
Discovery options.
eventHubSelectionOptions module:fabric-network.Gateway~DefaultEventHubSelectionOptions <optional>
Event hub selection options.
checkpointer module:fabric-network.Network~CheckpointerFactory <optional>
Event hub selection options.

QueryHandler

Type:
  • Object
Properties:
Name Type Description
evaluate function Async function that takes a Query and resolves with the result of the query evaluation.

QueryHandlerFactory(network)

Parameters:
Name Type Description
network module:fabric-network.Network The network on which queries are being evaluated.
Returns:
A query handler.
Type
module:fabric-network.Gateway~QueryHandler

TxEventHandler

Type:
  • Object
Properties:
Name Type Description
startListening function Async function that resolves when the handler has started listening for transaction commit events. Called after the transaction proposal has been accepted and prior to submission of the transaction to the orderer.
waitForEvents function Async function that resolves (or rejects) when suitable transaction commit events have been received. Called after submission of the transaction to the orderer.
cancelListening function Cancel listening. Called if submission of the transaction to the orderer fails.

TxEventHandlerFactory(transaction, network)

Parameters:
Name Type Description
transaction Transaction The transaction for which the handler should listen for commit events.
network module:fabric-network.Network The network on which this transaction is being submitted.
Returns:
A transaction event handler.
Type
module:fabric-network.Gateway~TxEventHandler