Skip to main content

@hlf-core/api

@hlf-core/api is the very lowest level of working with the network. It does exactly two things: it establishes a connection to Fabric through fabric-network and turns the network’s raw data into something usable. It knows nothing about commands or the transport protocol — that is already the responsibility of the @hlf-core/transport package, which sits directly above it.

The main class is FabricApiClient. Its connect() assembles the whole chain from the settings: wallet, gateway, network, channel, contract, and after that gives access to network, channel, contract, gateway, and qsccContract. The wallet is created in memory — keys are never written to disk, and that is a deliberate decision. The static parseBlock(block) deserves separate mention: it augments the block with hash, number, and date, bringing the raw block into a convenient shape.

Connection settings are described by IFabricConnectionSettings — the channel and chaincode names, the connection profile, service discovery, the identity (MSP, private key, certificate) and, if needed, a separate TLS identity.

FabricContractQSCC, available as api.qsccContract, deserves special attention — it is a wrapper over the Fabric system contract. Through it you read the height and contents of the ledger: getInfo(), getBlockNumber(), getBlock(n), getBlockByTransactionId(id), getTransaction(id). There is one subtlety here that is easy to get burned by: getBlockNumber() returns the ledger height, not the number of the last block — these are not the same thing, and they should not be confused.

const api = new FabricApiClient(logger, {
fabricNetworkName: 'mychannel',
fabricChaincodeName: 'mychaincode',
// ...identity and connection profile
});
await api.connect();

const result = await api.contract.evaluateTransaction('myFunction', 'arg');
const block = await api.qsccContract.getBlock(42); // block.number, block.hash, block.date

On the subject of reliability: reconnect here makes a single attempt — retry logic lives one level up, in the transport, and that is the correct separation of responsibilities.