The `fabric-shim-api` package provides the Node.js API for Hyperledger Fabric chaincode shim, facilitating communication between endorsing peers and user-provided chaincodes. Its primary role is to offer TypeScript type definitions for the `fabric-shim` module, and it serves as a dependency for `fabric-contract-api`, enabling the use of annotations in client applications without pulling in unnecessary runtime dependencies. The current stable version is 2.5.8, part of the v2.5 LTS series. Releases typically follow the Hyperledger Fabric LTS cadence, with point releases addressing fixes and dependency updates. Key differentiators include its lightweight nature as a type-only package, its integral role in the Fabric Node.js chaincode ecosystem, and its support for modern Node.js runtimes (currently Node 22 for the latest versions).
npm install fabric-shim-apiVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic Hyperledger Fabric chaincode in TypeScript, implementing `ChaincodeInterface` with `Init` and `Invoke` methods, and a simple `createAsset` private function. It shows how to interact with the `Stub` and return appropriate `ChaincodeResponse` objects.
Ensure your chaincode Docker images and development environment use Node.js version 18 or higher. For latest stability and features, use Node 20 or Node 22 as specified in the changelog for your target shim-api version.
Update your chaincode logic to expect a parsed JSON object from `stub.getHistory()` instead of a raw `Buffer`.
Upgrade to `fabric-shim-api@2.5.6` or higher (along with `fabric-shim`) to mitigate the `grpc-js` vulnerability. Prioritize updating to the latest stable release.
For optimal compatibility and to benefit from latest fixes, upgrade `fabric-shim-api` and `fabric-shim` to the latest v2.5.x LTS release (e.g., 2.5.8+), which incorporates the relaxed constraint and recent `grpc-js` updates.
Update the Node.js version in your chaincode Dockerfile and local development environment to Node.js 18 or higher. For recent shim versions (2.5.5+), use Node.js 20 or Node.js 22.
Ensure you are using `fabric-shim-api` and `fabric-shim` versions 2.5.2 or higher. Verify your `stub` variable is correctly typed as `Stub` from `fabric-shim-api`.
In your `Invoke` method, safely access custom functions using `(this as any)[ret.fcn]` or implement type guards to ensure the method exists and is callable. Alternatively, define an interface that extends `ChaincodeInterface` and includes your custom methods.
Check network connectivity between the chaincode container and the peer. Verify `CORE_CHAINCODE_ID_NAME` and `CORE_PEER_ADDRESS` environment variables are correctly set. Ensure `fabric-shim` and `grpc-js` versions are compatible; upgrading to the latest `fabric-shim` (2.5.8+) often resolves underlying gRPC issues.