Home

Awesome

Hyperledger Fabric Client SDK for Go

Release License GoDoc

Build Status codecov Go Report Card

Note: This API is deprecated and is no longer maintained as of Fabric v2.5. When developing applications for Hyperledger Fabric v2.4 and later, you should use the Fabric Gateway client API.

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

Community

Client SDK

Current Compatibility

The SDK's integration tests run against three tagged Fabric versions:

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.

Running the test suite

Obtain the client SDK packages for Fabric and Fabric CA.

git clone https://github.com/hyperledger/fabric-sdk-go.git
# In the Fabric SDK Go directory
cd fabric-sdk-go/

# Optional - Automatically install Go tools used by test suite
# make depend

# Running test suite
make

# Clean test suite run artifacts
make clean

Go Tags

The following Go tags can be supplied to enable additional functionality:

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:

Notes:

Running a portion of the test suite

# In the Fabric SDK Go directory
cd fabric-sdk-go/

# Optional - Automatically install Go tools used by test suite
# make depend

# Optional - Running only code checks (linters, license, spelling, etc)
# make checks

# Running all unit tests and checks
make unit-test

# Running all integration tests
make integration-test

Running package unit tests manually

# In a package directory
go test

Running integration tests manually

You need:

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:

# In the Fabric SDK Go directory
cd 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

Running Integration Tests

Fabric should now be running. In a different shell, run integration tests

# In the Fabric SDK Go directory
cd fabric-sdk-go

# Use script to setup parameters for integration tests and execute them
# Previously we use to have hostnames like Fabric CA server, orderer and peer pointed to localhost
# Now since we removed this now, We will be using a different configuration
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
# Previously we use to have hostnames like Fabric CA server, orderer and peer pointed to localhost
# Now since we removed this now, We will be using a different config file config_test_local.yaml
# which has the Fabric CA server, orderer and peers pointed to localhost
# It is also possible to run integration tests using go test directly. For example:
#cd fabric-sdk-go/test/integration/
#go test -args testLocal=true

#cd fabric-sdk-go/test/integration/orgs
#go test -args testLocal=true 

# You should review test/scripts/integration.sh for options and details.
# Note: you should generally prefer the scripted version to setup parameters for you.

Testing with Local Build of Fabric (Advanced)

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

License

Hyperledger Fabric SDK Go software is licensed under the Apache License Version 2.0.


This document is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.