All Products
Search
Document Center

Blockchain as a Service:Use Fabric Go SDK

Last Updated:Mar 31, 2026

This guide walks you through running the Hyperledger Fabric Go SDK sample against an Alibaba Cloud Blockchain as a Service (BaaS) network. By the end, you will have enrolled a user, queried channel data, and invoked a chaincode — all through the Go SDK.

Prerequisites

Before you begin, ensure that you have:

  • An Alibaba Cloud BaaS network with at least one channel and one peer

  • Go 1.10.x installed (versions >=1.10.1, <1.11 are tested and supported)

  • A connection-profile.yaml downloaded from the BaaS console for your network

Set up the Go development environment

Verify that Go is installed and GOPATH is set correctly:

$ go version
go version go1.10.1

$ go env GOPATH
/root/gos

If either command fails, follow the official Go installation guide before continuing.

Download and set up the sample

  1. Download go-sdk-demo-1.4.5.

  2. Extract the archive to $GOPATH/src:

    tar -xzf go-sdk-demo-1.4.5.tar.gz -C $GOPATH/src
  3. Copy your connection-profile.yaml into the demo directory:

    cp connection-profile.yaml $GOPATH/src/go-sdk-demo/

After setup, the workspace should look like this:

go-sdk-demo
├── chaincode/
├── main.go
├── play.sh
├── README.md
├── vendor/
└── connection-profile.yaml
FileDescription
play.shEntry script that provides an interactive CLI to drive the demo
main.goSample program built on the Hyperledger Fabric Go SDK
chaincode/sacc.outPre-packaged chaincode, ready to upload directly to the BaaS console
chaincode/srcSource code for sacc.out
vendor/github.com/hyperledger/fabric-sdk-goBundled Fabric Go SDK source

Upload the chaincode

Upload chaincode/sacc.out to BaaS and instantiate it on your channel. For step-by-step instructions, see Deploy chaincodes.

Run the sample

Navigate to the demo directory and start the entry script:

cd $GOPATH/src/go-sdk-demo
bash play.sh

Follow the prompts to enter your network credentials. play.sh drives main.go through six operations in sequence:

StepOperationPurposeExpected result
1Enroll a userDownloads certificates from the Certificate Authority (CA) and stores them locally, so subsequent SDK calls can sign transactionsCertificate files are written to the local filesystem
2Query channel configFetches the channel configuration blockChannel configuration is printed to the console
3Query channel infoFetches the current block height and chain metadataBlock height and chain info are printed to the console
4Query chaincodeReads the current value of a key from the ledgerThe key's current value is printed to the console
5Invoke chaincodeWrites a new value to the ledger by submitting a transactionThe transaction is submitted and the new value is committed
6Query chaincode againRe-reads the key to confirm the invoke succeededThe key's value matches the value written in step 5

A successful run ends with the value queried in step 6 matching the value written in step 5.

What's next