Class

FabricClientAdapter

FabricClientAdapter(config, alias)

Constructor

# new FabricClientAdapter(config, alias)

The FabricAdapter extends CouchDBAdapter to provide a seamless interface for interacting with Hyperledger Fabric networks. It handles connection management, transaction submission, and CRUD operations against Fabric chaincode.

Adapter for interacting with Hyperledger Fabric networks

sequenceDiagram participant Client participant FabricAdapter participant Gateway participant Network participant Contract participant Chaincode Client->>FabricAdapter: create(tableName, id, model, transient, serializer) FabricAdapter->>FabricAdapter: submitTransaction(OperationKeys.CREATE, [serializedModel], transient) FabricAdapter->>Gateway: connect() Gateway->>Network: getNetwork(channelName) Network->>Contract: getContract(chaincodeName, contractName) FabricAdapter->>Contract: submit(api, proposalOptions) Contract->>Chaincode: invoke Chaincode-->>Contract: response Contract-->>FabricAdapter: result FabricAdapter->>FabricAdapter: decode(result) FabricAdapter->>FabricAdapter: serializer.deserialize(decodedResult) FabricAdapter-->>Client: deserializedResult
Parameters:
Name Type Description
config

Configuration for connecting to a Fabric peer

alias

Optional alias for the adapter instance

View Source client/FabricClientAdapter.ts, line 24

Example
```typescript
// Create a new FabricAdapter instance
const config: PeerConfig = {
  mspId: 'Org1MSP',
  peerEndpoint: 'localhost:7051',
  channelName: 'mychannel',
  chaincodeName: 'mycc',
  contractName: 'mycontract',
  tlsCertPath: '/path/to/tls/cert',
  certDirectoryPath: '/path/to/cert/dir',
  keyDirectoryPath: '/path/to/key/dir'
};

const adapter = new FabricAdapter(config, 'org1-adapter');

// Use the adapter to interact with the Fabric network
const result = await adapter.read('users', 'user1', mySerializer);
```

Classes

FabricClientAdapter

Initializes a new adapter for interacting with a Hyperledger Fabric network

FabricClientAdapter

Initializes a new adapter for interacting with a Hyperledger Fabric network

Members

# decoder

Static text decoder for converting Uint8Array to string

.

Static text decoder for converting Uint8Array to string

View Source client/FabricClientAdapter.ts, line 79

Methods

# async protected Contract(contractNameopt) → {Promise.<Contrakt>}

Creates a new Contract instance using the current Gateway

Gets a Contract instance for the Fabric chaincode

Parameters:
Name Type Attributes Description
contractName string <optional>

View Source client/FabricClientAdapter.ts, line 1077

Promise resolving to the Contract instance

Promise.<Contrakt>

# Dispatch() → {Dispatch}

This function is responsible for creating a new FabricClientDispatch instance that can be used to interact with the Fabric network.

Creates a new Dispatch instance for the Fabric client.

View Source client/FabricClientAdapter.ts, line 1224

A new Dispatch instance configured for the Fabric client.

Dispatch
Example
const fabricDispatch = fabricClientAdapter.Dispatch();
fabricDispatch.submitTransaction('createProduct', { name: 'Product A', price: 100 });

# async protected Gateway() → {Promise.<Gateway>}

Creates a new Gateway instance using the current client

Gets a Gateway instance for the Fabric network

View Source client/FabricClientAdapter.ts, line 1067

Promise resolving to the Gateway instance

Promise.<Gateway>

# async close() → {Promise.<void>}

Closes the gRPC client if it exists

Closes the connection to the Fabric network

View Source client/FabricClientAdapter.ts, line 1150

Promise that resolves when the client is closed

Promise.<void>

# async create(tableName, id, model, transient) → {Promise.<Record.<string, any>>}

Submits a transaction to create a record in the Fabric ledger

Creates a single record

Parameters:
Name Type Description
tableName string

The name of the table/collection

id string | number

The record identifier

model Record.<string, any>

The record data

transient Record.<string, any>

Transient data for the transaction

View Source client/FabricClientAdapter.ts, line 991

Promise resolving to the created record

Promise.<Record.<string, any>>

# async createAll(tableName, ids, models, transient) → {Promise.<Array.<Record.<string, any>>>}

Submits a transaction to create multiple records in the Fabric ledger

Creates multiple records in a single transaction

Parameters:
Name Type Description
tableName string

The name of the table/collection

ids Array.<string> | Array.<number>

Array of record identifiers

models Array.<Record.<string, any>>

Array of record data

transient Record.<string, any>

Transient data for the transaction

View Source client/FabricClientAdapter.ts, line 911

Promise resolving to the created records

Promise.<Array.<Record.<string, any>>>

# protected createAllPrefix(tableName, ids, models)

Adds necessary CouchDB fields to multiple records before creation

Prepares multiple records for creation

Parameters:
Name Type Description
tableName string

The name of the table

ids Array.<string> | Array.<number>

The IDs of the records

models

The models to prepare

View Source client/FabricClientAdapter.ts, line 899

If ids and models arrays have different lengths

InternalError

A tuple containing the tableName, ids, and prepared records

# decode(data) → {string}

Converts binary data received from Fabric to a string using UTF-8 encoding

Decodes a Uint8Array to a string

Parameters:
Name Type Description
data Uint8Array

The binary data to decode

View Source client/FabricClientAdapter.ts, line 887

The decoded string

string

# async delete(tableName, id) → {Promise.<Record.<string, any>>}

Submits a transaction to delete a record from the Fabric ledger

Deletes a single record

Parameters:
Name Type Description
tableName string

The name of the table/collection

id string | number

The record identifier to delete

View Source client/FabricClientAdapter.ts, line 1023

Promise resolving to the deleted record

Promise.<Record.<string, any>>

# async deleteAll(tableName, ids, serializer) → {Promise.<Array.<Record.<string, any>>>}

Submits a transaction to delete multiple records from the Fabric ledger

Deletes multiple records in a single transaction

Parameters:
Name Type Description
tableName string

The name of the table/collection

ids Array.<(string|number|bigint)>

Array of record identifiers to delete

serializer Serializer.<any>

Serializer for the model data

View Source client/FabricClientAdapter.ts, line 944

Promise resolving to the deleted records

Promise.<Array.<Record.<string, any>>>

# async evaluateTransaction(api, argsopt, transientDataopt, endorsingOrganizationsopt) → {Promise.<Uint8Array>}

Executes a transaction that does not modify the ledger state

Evaluates a transaction on the Fabric network

Parameters:
Name Type Attributes Description
api string

The chaincode function to call

args Array.<any> <optional>

Arguments to pass to the chaincode function

transientData Record.<string, string> <optional>

Transient data for the transaction

endorsingOrganizations Array.<string> <optional>

Organizations that must endorse the transaction

View Source client/FabricClientAdapter.ts, line 1142

Promise resolving to the transaction result

Promise.<Uint8Array>

# getClient() → {Promise.<Client>}

Returns a cached client or creates a new one if none exists

Gets or creates a gRPC client for the Fabric peer

View Source client/FabricClientAdapter.ts, line 1058

Promise resolving to the gRPC client

Promise.<Client>

# protected index(models) → {Promise.<void>}

This method is not implemented for Fabric and will throw an error

Creates an index for a model

Parameters:
Name Type Description
models Constructor.<M>

The model constructor

View Source client/FabricClientAdapter.ts, line 979

Promise that will throw an error

Promise.<void>

# parseError(err, reasonopt) → {BaseError}

Converts any error into a standardized BaseError

Parses an error into a BaseError

Parameters:
Name Type Attributes Description
err Error | string

The error to parse

reason string <optional>

Optional reason for the error

View Source client/FabricClientAdapter.ts, line 1118

The parsed error

BaseError

# prepare(model, pk)

Converts a model instance into a format suitable for database storage, handling column mapping and separating transient properties

Prepares a model for persistence

Parameters:
Name Type Description
model M

The model instance to prepare

pk

The primary key property name

View Source client/FabricClientAdapter.ts, line 955

The prepared data

# async raw(rawInput, process) → {Promise.<V>}

Evaluates a transaction to perform a query using Mango Query syntax

Executes a raw query against the Fabric ledger

sequenceDiagram participant Client participant FabricAdapter participant Contract participant Chaincode Client->>FabricAdapter: raw(rawInput, process) FabricAdapter->>FabricAdapter: JSON.stringify(rawInput) FabricAdapter->>FabricAdapter: evaluateTransaction("query", [input]) FabricAdapter->>Contract: evaluate("query", proposalOptions) Contract->>Chaincode: invoke Chaincode-->>Contract: response Contract-->>FabricAdapter: result FabricAdapter->>FabricAdapter: JSON.parse(decode(result)) FabricAdapter->>FabricAdapter: Process result based on type FabricAdapter-->>Client: processed result
Parameters:
Name Type Description
rawInput MangoQuery

The Mango Query to execute

process boolean

Whether to process the result

View Source client/FabricClientAdapter.ts, line 1051

Promise resolving to the query result

Promise.<V>

# async read(tableName, id) → {Promise.<Record.<string, any>>}

Evaluates a transaction to read a record from the Fabric ledger

Reads a single record

Parameters:
Name Type Description
tableName string

The name of the table/collection

id string | number

The record identifier

View Source client/FabricClientAdapter.ts, line 1001

Promise resolving to the retrieved record

Promise.<Record.<string, any>>

# async readAll(tableName, ids) → {Promise.<Array.<Record.<string, any>>>}

Submits a transaction to read multiple records from the Fabric ledger

Reads multiple records in a single transaction

Parameters:
Name Type Description
tableName string

The name of the table/collection

ids Array.<string> | Array.<number>

Array of record identifiers to read

View Source client/FabricClientAdapter.ts, line 921

Promise resolving to the retrieved records

Promise.<Array.<Record.<string, any>>>

# revert(obj, clazz, pk, id, transientopt) → {M}

Reconstructs a model instance from database data, handling column mapping and reattaching transient properties

Converts database data back into a model instance

Parameters:
Name Type Attributes Description
obj

The database record

clazz string | Constructor.<M>

The model class or name

pk

The primary key property name

id string | number | bigint

The primary key value

transient <optional>

Transient properties to reattach

View Source client/FabricClientAdapter.ts, line 969

The reconstructed model instance

M

# async submitTransaction(api, argsopt, transientDataopt, endorsingOrganizationsopt) → {Promise.<Uint8Array>}

Executes a transaction that modifies the ledger state

Submits a transaction to the Fabric network

Parameters:
Name Type Attributes Description
api string

The chaincode function to call

args Array.<any> <optional>

Arguments to pass to the chaincode function

transientData Record.<string, string> <optional>

Transient data for the transaction

endorsingOrganizations Array.<string> <optional>

Organizations that must endorse the transaction

View Source client/FabricClientAdapter.ts, line 1130

Promise resolving to the transaction result

Promise.<Uint8Array>

# async protected transaction(api, submit, argsopt, transientDataopt, endorsingOrganizationsopt) → {Promise.<Uint8Array>}

Submits or evaluates a transaction on the Fabric chaincode

Executes a transaction on the Fabric network

sequenceDiagram participant FabricAdapter participant Gateway participant Contract participant Chaincode FabricAdapter->>Gateway: connect() FabricAdapter->>Contract: getContract() alt submit transaction FabricAdapter->>Contract: submit(api, proposalOptions) else evaluate transaction FabricAdapter->>Contract: evaluate(api, proposalOptions) end Contract->>Chaincode: invoke Chaincode-->>Contract: response Contract-->>FabricAdapter: result FabricAdapter->>Gateway: close()
Parameters:
Name Type Attributes Description
api string

The chaincode function to call

submit boolean

Whether to submit (true) or evaluate (false) the transaction

args Array.<any> <optional>

Arguments to pass to the chaincode function

transientData Record.<string, string> <optional>

Transient data for the transaction

endorsingOrganizations Array.<string> <optional>

Organizations that must endorse the transaction

View Source client/FabricClientAdapter.ts, line 1109

Promise resolving to the transaction result

Promise.<Uint8Array>

# async update(tableName, id, model, transient) → {Promise.<Record.<string, any>>}

Submits a transaction to update a record in the Fabric ledger

Updates a single record

Parameters:
Name Type Description
tableName string

The name of the table/collection

id string | number

The record identifier

model Record.<string, any>

The updated record data

transient Record.<string, any>

Transient data for the transaction

View Source client/FabricClientAdapter.ts, line 1013

Promise resolving to the updated record

Promise.<Record.<string, any>>

# async updateAll(tableName, ids, models, transient) → {Promise.<Array.<Record.<string, any>>>}

Submits a transaction to update multiple records in the Fabric ledger

Updates multiple records in a single transaction

Parameters:
Name Type Description
tableName string

The name of the table/collection

ids Array.<string> | Array.<number>

Array of record identifiers

models Array.<Record.<string, any>>

Array of updated record data

transient Record.<string, any>

Transient data for the transaction

View Source client/FabricClientAdapter.ts, line 933

Promise resolving to the updated records

Promise.<Array.<Record.<string, any>>>

# static getClient(config) → {Client}

Initializes a client with TLS credentials for secure communication

Creates a gRPC client for connecting to a Fabric peer

Parameters:
Name Type Description
config PeerConfig

The peer configuration

View Source client/FabricClientAdapter.ts, line 1186

Promise resolving to the gRPC client

Client

# async static getConnection(client, config) → {Promise.<Gateway>}

Creates a Gateway connection with identity and signer

Establishes a connection to the Fabric network

sequenceDiagram participant Caller participant FabricAdapter participant Identity participant Signer participant Gateway Caller->>FabricAdapter: getConnection(client, config) FabricAdapter->>Identity: getIdentity(mspId, certDirectoryPath) Identity-->>FabricAdapter: identity FabricAdapter->>Signer: getSigner(keyDirectoryPath) Signer-->>FabricAdapter: signer FabricAdapter->>FabricAdapter: Create ConnectOptions FabricAdapter->>Gateway: connect(options) Gateway-->>FabricAdapter: gateway FabricAdapter-->>Caller: gateway
Parameters:
Name Type Description
client Client

The gRPC client

config PeerConfig

The peer configuration

View Source client/FabricClientAdapter.ts, line 1213

Promise resolving to the connected Gateway

Promise.<Gateway>

# static getContract(gateway, config) → {Contrakt}

Retrieves a chaincode contract from the specified network

Gets a Contract instance from a Gateway

Parameters:
Name Type Description
gateway Gateway

The Gateway instance

config PeerConfig

The peer configuration

View Source client/FabricClientAdapter.ts, line 1159

The Contract instance

Contrakt

# async static getGateway(config, clientopt) → {Promise.<Gateway>}

Creates a Gateway using the provided configuration and client

Gets a Gateway instance for connecting to the Fabric network

Parameters:
Name Type Attributes Description
config PeerConfig

The peer configuration

client Client <optional>

Optional gRPC client, will be created if not provided

View Source client/FabricClientAdapter.ts, line 1178

Promise resolving to the Gateway instance

Promise.<Gateway>

# static getNetwork(gateway, channelName) → {Network}

Connects to a specific channel on the Fabric network

Gets a Network instance from a Gateway

Parameters:
Name Type Description
gateway Gateway

The Gateway instance

channelName string

The name of the channel to connect to

View Source client/FabricClientAdapter.ts, line 1168

The Network instance

Network

# protected static parseError(err, reasonopt) → {BaseError}

Converts any error into a standardized BaseError using the parent class implementation

Parses an error into a BaseError

Parameters:
Name Type Attributes Description
err Error | string

The error to parse

reason string <optional>

Optional reason for the error

View Source client/FabricClientAdapter.ts, line 1234

The parsed error

BaseError