A Dart implementation of Hyperledger Fabric Gateway client library.
- Complete Hyperledger Fabric Gateway API implementation
- ECDSA cryptographic signing with proper canonicalization
- X.509 identity management
- Protobuf-based communication with Fabric peers
- Support for proposal evaluation and transaction submission
Add to your pubspec.yaml:
dependencies:
fabric_gateway:
path: ../fabric-gateway-dartThe lib/src/protos/ directory contains Dart files generated from Hyperledger Fabric .proto definitions.
These are not committed to the repo and must be generated before building.
-
protoc— Protocol Buffers compiler:brew install protobuf # macOS -
protoc-gen-dart— Dart plugin for protoc (requiresprotoc_plugin ^25.0.0, which targetsprotobuf ^6.0.0):dart pub global activate protoc_plugin
Add the pub-cache bin to your PATH (add to
~/.zshrcor~/.bashrc):export PATH="$PATH:$HOME/.pub-cache/bin"
-
fabric-protos— Hyperledger Fabric.protosource files, cloned at~/github/fabric-protos:git clone https://github.com/hyperledger/fabric-protos ~/github/fabric-protosThe script defaults to that path; pass a custom path as the first argument if needed.
./tool/gen_protos.sh
# or with a custom fabric-protos path:
./tool/gen_protos.sh /path/to/fabric-protosNote:
protoc-gen-dartmust be on yourPATHwhen running the script. If you getprotoc-gen-dart: program not found, prepend the pub-cache bin:PATH="$PATH:$HOME/.pub-cache/bin" ./tool/gen_protos.sh
| Package | Required version |
|---|---|
protobuf |
^6.0.0 |
grpc |
^5.1.0 |
protoc_plugin |
^25.0.0 |
protoc_plugin 25.0.0 generates well-known type imports from package:protobuf/well_known_types/…
which requires protobuf 6.0.0+. Do not use an older protoc_plugin with this project.
import 'package:fabric_gateway/fabric_gateway.dart';
// Create gateway connection
final gateway = await Gateway.newGateway(
mspId: 'Org1MSP',
peerEndpoint: 'localhost:7051',
tlsRootCert: tlsCertBytes,
clientCert: clientCertBytes,
clientKey: clientKeyBytes,
peerHostAlias: 'peer0.org1.example.com',
);
// Evaluate transaction
final result = await gateway.evaluateTransaction(
channelName: 'mychannel',
chaincodeName: 'mychaincode',
transactionName: 'GetAsset',
args: ['asset1'],
);