# 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
Parameters:
| Name | Type | Description |
|---|---|---|
config |
Configuration for connecting to a Fabric peer |
|
alias |
Optional alias for the adapter instance |
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
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> |
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.
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
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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
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 |
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 |
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 |
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
Parameters:
| Name | Type | Description |
|---|---|---|
rawInput |
MangoQuery
|
The Mango Query to execute |
process |
boolean
|
Whether to process the result |
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 |
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 |
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 |
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 |
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
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 |
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 |
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 |
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 |
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
Parameters:
| Name | Type | Description |
|---|---|---|
client |
Client
|
The gRPC client |
config |
PeerConfig
|
The peer configuration |
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 |
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 |
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 |
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 |
The parsed error
BaseError