The Fabric Gateway is a core component of a Fabric blockchain network and coordinates the actions required to submit transactions and query ledger state on behalf of client applications. By using the Gateway, client applications only need to connect to a single endpoint in the Fabric network.
The Gateway SDKs implement the Fabric programming model as described in the Developing Applications chapter of the Fabric documentation.
The original proposal is described in the Fabric Gateway RFC. Adding a Gateway component to the Fabric Peer provides a single entry point to a Fabric network, and removes much of the transaction submission logic from the client application.
The Gateway component in the Fabric Peer exposes a simple gRPC interface to client applications and manages the lifecycle of transaction invocation on behalf of the client. This minimises the network traffic passing between the client and the blockchain network as well as minimising the number of network ports that need to be opened.
See the gateway.proto file for details of the gRPC interface.
Enable the Gateway feature flag in core.yaml
by adding the following:
peer:
gateway:
enabled: true
Alternatively, using yq:
docker run --rm -v "${PWD}":/workdir mikefarah/yq eval '.peer.gateway.enabled = true' --inplace core.yaml
Three SDKs are available to support the development of client applications that interact with the Fabric network via the Gateway.
The Go SDK provides a high-level API for client applications written in Go.
Read the quickstart guide for more details.
The Node SDK provides a high-level API for client applications written in Javascript or Typescript.
Read the quickstart guide for more details.
The Java SDK provides a high-level API for client applications written in Java.
Read the quickstart guide for more details.
This repo comprises the Gateway server (written in Go) and three SDKs (written in Go, Typescript and Java). In order to build these components, the following needs to be installed and available in the PATH:
- Go (v1.14)
- Node (optional for Node SDK)
- Typescript (optional for Node SDK)
- Java 11 (optional for Java SDK)
- Docker
- Protobuf compiler (https://developers.google.com/protocol-buffers/docs/downloads)
- Some Go tools:
GO111MODULE=on go get github.com/cucumber/godog/cmd/[email protected]
go get -u golang.org/x/lint/golint
go get -u golang.org/x/tools/cmd/goimports
go get google.golang.org/grpc google.golang.org/protobuf/cmd/protoc-gen-go google.golang.org/grpc/cmd/protoc-gen-go-grpc
go get honnef.co/go/tools/cmd/staticcheck
go get github.com/golang/mock/mockgen
The following Makefile targets are available
make build-go
- compile the gateway server executablemake pull-latest-peer
- fetch the latest peer docker image containing the gateway servermake unit-test-go
- run unit tests for the gateway server and Go SDKmake unit-test-node
- run unit tests for the Node SDKmake unit-test-java
- run unit tests for the Java SDKmake unit-test
- run unit tests for the gateway server and all three SDKsmake scenario-test-go
- run the scenario (end to end integration) tests for Go SDKmake scenario-test-node
- run the scenario tests for Node SDKmake scenario-test-java
- run the scenario tests for Java SDKmake scenario-test
- run the scenario tests for all SDKsmake test
- run all unit and scenario testsmake generate
- generate mock implementations used by unit tests
Note that immediately after creating a fresh copy of this repository, auto-generated test mocks will not be preset so
Go code will show errors. Running the unit-test
make target will generate the required mock implementations, and they
can also be generated explicitly by running make generate
.
The scenario tests create a Fabric network comprising two orgs (one peer in each org) and a single gateway within a set of docker containers. The clients connect to the gateway to submit transactions and query the ledger state.
The tests are defined as feature files using the Cucumber BDD framework. The same set of feature files is used across all three SDKs to ensure consistency of behaviour.