Set up Golang development environment
First, make sure Golang binary has been installed correctly. The official Go installation document. The Go versions >=1.10.1, <1.11 have been tested and are suggested to use. To verify Go is correctly installed, you can run the following commands:
$ go versiongo version go1.10.1$ go env GOPATH/root/gos
Download sample codes
Please download go-sdk-demo-1.4.5. Download sample codes to local directory: $GOPATH/src, and decompress it. Copy file connection-profile.yaml to path $GOPATH/src/go-sdk-demo. The layout of the workspace should look like this:
go-sdk-demo├── chaincode/├── main.go├── play.sh├── README.md└── vendor/└── connection-profile.yaml
play.sh: An entry script that provides an interactive command line interface.main.go: An example program based on Hyperledger Fabric Go SDK.chaincode/sacc.out: A packaged chain code, it can be uploaded directly to BaaS console.chaincode/src: The source codes of sacc.out.vendor/github.com/hyperledger/fabric-sdk-go: The source codes of Hyperledger Fabric Go SDK.
Upload the Chaincode
Upload the chaincode: chaincode/sacc.out to BaaS and instantiate it. You can refer to Deploy chaincodes.
Run the sample
cd $GOPATH/src/go-sdk-demobash play.sh
Follow the prompts to enter some necessary information. play.sh will run main.go, which is a sample program based on the Hyperledger Fabric Go SDK, mainly to help you understand the basic usage of Go SDK. It includes the following functions:
- Enroll a user, download certificates.
- Query channel config and print it in console.
- Query channel info and print it in console.
- Query chaincode.
- Invoke chaincode.
- Query chaincode again, to make sure invoking is the success.
To Get more information about Hyperledger Fabric Go SDK, please refer to: fabric-sdk-go.