Module: fabric-network

Overview

This module provides a higher level API for interacting with smart contracts, and is the recommended API for client applications to interact with smart contracts deployed to a Hyperledger Fabric blockchain network.

Note that administrative capabilities, such as installing and starting smart contracts, are not currently provided by this API. For these tasks or other specific advanced usage, the lower level fabric-client API should be used. Access to related fabric-client objects is provided through the fabric-network API objects.

TypeScript definitions are included in this module.

Getting started

The entry point used to interact with a Hyperledger Fabric blockchain network is the Gateway class. This provides a connection to a peer within the blockchain network, and enables access to any of the blockchain Networks (channels) for which that peer is a member. This in turn provides access to Smart Contracts (chaincode) running within that blockchain network, and to which Transactions can be submitted or queries can be evaluated.

Private data can be submitted to transactions as transient data to prevent it from being recorded on the ledger.

Example

// Obtain the smart contract with which our application wants to interact
const wallet = new FileSystemWallet(walletDirectoryPath);
const gatewayOptions: GatewayOptions = {
    identity: 'user@example.org', // Previously imported identity
    wallet,
};
const gateway = new Gateway();
await gateway.connect(commonConnectionProfile, gatewayOptions);
const network = await gateway.getNetwork(channelName);
const contract = network.getContract(chaincodeId);

// Submit transactions or evaluate queries for the smart contract
const result = await contract.createTransaction(transactionName)
    .setTransient(privateData)
    .submit(arg1, arg2);

Classes

AbstractEventHubSelectionStrategy
AbstractEventListener
BaseCheckpointer
BaseWallet
CommitEventListener
Contract
ContractEventListener
CouchDBWallet
EventHubDisconnectError
EventHubManager
FabricError
FileSystemCheckpointer
FileSystemWallet
Gateway
HSMWalletMixin
InMemoryWallet
Network
Query
RoundRobinEventHubSelectionStrategy
TimeoutError
Transaction
X509WalletMixin

Type Definitions


DefaultEventHandlerStrategies

Properties:
Name Type Description
MSPID_SCOPE_ALLFORTX Listen for transaction commit events from all peers in the client identity's organization. The submitTransaction function will wait until successful events are received from all currently connected peers (minimum 1).
MSPID_SCOPE_ANYFORTX Listen for transaction commit events from all peers in the client identity's organization. The submitTransaction function will wait until a successful event is received from any peer.
NETWORK_SCOPE_ALLFORTX Listen for transaction commit events from all peers in the network. The submitTransaction function will wait until successful events are received from all currently connected peers (minimum 1).
NETWORK_SCOPE_ANYFORTX Listen for transaction commit events from all peers in the network. The submitTransaction function will wait until a successful event is received from any peer.

DefaultQueryHandlerStrategies

Properties:
Name Type Description
MSPID_SCOPE_SINGLE function Query any one of the event hubs for the connected organisation. Continue to use the same event hub for all queries unless it fails.
MSPID_SCOPE_ROUND_ROBIN function Query any one of the event hubs for the connected organisation. Use the next available peer for each successive query.

CheckpointFactories

Properties:
Name Type Description
FILE_SYSTEM_CHECKPOINTER function Checkpoint using the file system

DefaultEventHubSelectionStrategies

Properties:
Name Type Description
MSPID_SCOPE_ROUND_ROBIN function Reconnect to any of the event emitting peers in the org after a disconnect occurs. Select the event hub in a 'round robin' fashion