Getting started
Here we will put together a minimal setup — a chaincode with a single entry point and a client that sends it a command. The example is deliberately skeletal: its goal is to show which parts an hlf-core application is made of, not to replace a full tutorial, which we will add separately.
What you will need
You will need Node.js 18 or newer, TypeScript 5+, and a deployed Hyperledger Fabric 2.x or 3.x network. For which Fabric versions hlf-core supports today and where it is heading, it is worth checking the Compatibility section in advance — this is a case where it is better to verify before you start than after.
Installation
On the chaincode side you install the packages for working with state and receiving commands:
npm install @hlf-core/chaincode @hlf-core/transport-chaincode @hlf-core/common fabric-shim
On the client side — the packages for connecting to the network and sending commands:
npm install @hlf-core/transport @hlf-core/api @hlf-core/common fabric-network
A minimal chaincode
The contract inherits from TransportFabricChaincode and gets a command receiver. Getting ahead
of ourselves: registering handlers by command name lives right here, and adding a new command
does not change the contract's interface.
import {TransportFabricChaincode, TransportFabricChaincodeReceiver} from '@hlf-core/transport-chaincode';
export class MyChaincode extends TransportFabricChaincode<void> {
public get name(): string {
return 'MyChaincode';
}
}
A first call from the client
On the client we bring up the transport, connect to the network, and send a command using the same unified API as in any service:
import {TransportFabric} from '@hlf-core/transport';
const transport = new TransportFabric(logger, settings);
await transport.connect();
const result = await transport.sendListen(new MyGetCommand(uid));
Where to go next
How entities and relationships work is in @hlf-core/chaincode. How
the transport itself and signing work is in @hlf-core/transport. And
working with tokens and balances we cover in @hlf-core/coin.