Hyperledger Fabric Client SDK for Go
This SDK enables Go developers to build solutions that interact with Hyperledger Fabric.
Getting started
Obtain the client SDK packages for Fabric and Fabric CA.
go get github.com/hyperledger/fabric-sdk-go
You're good to go, happy coding! Check out the examples for usage demonstrations.
Documentation
SDK documentation can be viewed at GoDoc.
The packages intended for end developer usage are within the pkg/client folder along with the main SDK package (pkg/fabsdk).
If you wish to use the Fabric 'Gateway' programming model, then the API is in the pkg/gateway folder.
Examples
- E2E Test: Basic example that uses SDK to query and execute transaction
- Ledger Query Test: Basic example that uses SDK to query a channel's underlying ledger
- Multi Org Test: An example that has multiple organisations involved in transaction
- Dynamic Endorser Selection: An example that uses dynamic endorser selection (based on chaincode policy)
- E2E PKCS11 Test: E2E Test using a PKCS11 crypto suite and configuration
- CLI: An example CLI for Fabric built with the Go SDK.
- More examples needed!
Client SDK
Current Compatibility
The SDK's integration tests run against three tagged Fabric versions:
- prev (currently v1.4.7)
- stable (currently v2.2.0)
- prerelease (currently disabled)
Additionally for development purposes integration tests also run against the devstable Fabric version as needed.
Retired versions
When the 'prev' code level is updated, the last tested fabric-sdk-go commit or tag is listed below.
- fabric v1.3: ac70276
- fabric v1.2: 5e291d3
- fabric v1.1: f7ae259
- fabric v1.0: 5ac5226
Running the test suite
Obtain the client SDK packages for Fabric and Fabric CA.
git clone https://github.com/hyperledger/fabric-sdk-go.git
cd fabric-sdk-go/
make
make clean
Go Tags
The following Go tags can be supplied to enable additional functionality:
- experimental: includes support for experimental features.
Contributing to the Go SDK
If you want to contribute to the Go SDK, please run the test suite and submit patches for review. For general guidelines, please refer to the Fabric project's contribution page.
You need:
- Go 1.14
- Make
- Docker
- Docker Compose
- Git
- gobin (GO111MODULE=off go get -u github.com/myitcv/gobin)
- libtool
Notes:
Running a portion of the test suite
cd fabric-sdk-go/
make unit-test
make integration-test
Running package unit tests manually
go test
Running integration tests manually
You need:
- A working fabric and fabric-ca set up. It is recommended that you use the docker-compose file provided in
test/fixtures/dockerenv
. It is also recommended that you use the default .env settings provided in test/fixtures/dockerenv
. See steps below. - Customized settings in the
test/fixtures/config/config_test.yaml
in case your Hyperledger Fabric network is not running on localhost
or is using different ports.
Testing with Fabric Images at Docker Hub
The test suite defaults to the latest compatible tag of fabric images at Docker Hub.
The following commands starts Fabric:
cd fabric-sdk-go
make dockerenv-stable-up
Running Integration Tests
Fabric should now be running. In a different shell, run integration tests
cd fabric-sdk-go
make integration-tests-local
Testing with Local Build of Fabric (Advanced)
Alternatively you can use a local build of Fabric using the following commands:
make dockerenv-latest-up
License
Hyperledger Fabric SDK Go software is licensed under the Apache License Version 2.0.
This document is licensed under a Creative Commons Attribution 4.0 International License.