This SDK enables Go developers to build solutions that interact with Hyperledger Fabric.
Obtain the client SDK packages for Fabric and Fabric CA.
go get -u github.com/hyperledger/fabric-sdk-go
# Optional - populate vendor directory (if needed by your downstream vendoring solution)
# cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# make populate
You're good to go, happy coding! Check out the examples for usage demonstrations.
- E2E Test: Basic example that uses SDK to query and execute transaction
- 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!
- Discussion is happening in Rocket Chat.
- Issue tracking is handled in Jira.
- Active development occurs in the Gerrit repository.
The SDK's integration tests run against three tagged Fabric versions:
- prev (currently v1.0.0)
- stable (currently latest of v1.0.x)
- prerelease (currently latest of v1.1.0-x)
Additionally for development purposes integration tests also run against the devstable Fabric version as needed.
When the 'prev' code level is updated, the last tested fabric-sdk-go commit or tag is listed below.
- fabric v1.0.0 & fabric-ca v1.0.0
- fabric-sdk-go: master:HEAD
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# Optional - Automatically install Go tools used by test suite
# make depend-install
# Running test suite
make
# Clean test suite run artifacts
make clean
The following Go tags can be supplied to enable additional functionality:
- experimental: includes support for experimental features.
If you want to contribute to the Go SDK, please run the test suite and submit patches to the Gerrit git repostory for review. For general guidelines, please refer to the Fabric project's contribution page.
You need:
- Go 1.9
- Dep
- Make
- Docker
- Docker Compose
- Git
To contribute patches, you will need to clone (or add a remote) from Gerrit with authentication.
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# Ensure dependencies are installed
make depend
# Running code checks (license, linting, spelling, etc)
make checks
# Running all unit tests
make unit-test
# Running all integration tests
make integration-test
# In a package directory
go test
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 intest/fixtures/dockerenv
. See steps below. - Customized settings in the
test/fixtures/config/config_test.yaml
in case your Hyperledger Fabric network is not running onlocalhost
or is using different ports.
You will need to set the following hosts to 127.0.0.1 (typically in /etc/hosts): ca.org1.example.com ca.org2.example.com peer0.org1.example.com peer1.org1.example.com peer0.org2.example.com peer1.org2.example.com orderer.example.com
The test suite defaults to the latest compatible tag of fabric images at Docker Hub. The following commands starts Fabric:
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# Start fabric (stable tag)
make dockerenv-stable-up
# Or more generally, start fabric at a different code level (prev, stable, prerelease, devstable)
# make dockerenv-[CODELEVEL]-up
Fabric should now be running. In a different shell, run integration tests
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go
# Use script to setup parameters for integration tests and execute them
make integration-tests-local
# Or more generally, run integration tests at a different code level (prev, stable, prerelease, devstable)
# and fixture target version
# FABRIC_CODELEVEL_VER=[VER] FABRIC_CODELEVEL_TAG=[CODELEVEL] make integration-tests-local
# It is also possible to run integration tests using go test directly. For example:
#cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
#go test
#cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/orgs
#go test
# You should review test/scripts/integration.sh for options and details.
# Note: you should generally prefer the scripted version to setup parameters for you.
Default SDK Go configurations are found in the code under /pkg/config/config.yaml
To override the default in non Dev environment, set the default path in the following environment variable:
FABRIC_SDK_CONFIG_PATH=/path/to/default/config yaml(without specifying the yaml file name)
This path value must be a directory. It must contain a default 'config.yaml' file. Note that this default config is used only if environment configuration yaml file is missing to ensure all environment variables are created regardless of their values.
Alternatively you can use a local build of Fabric using the following commands:
# Start fabric (devstable codelevel with latest docker tags)
make dockerenv-latest-up
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.