Golang - Binary Format

Steps to build and zip go binary executable:

  • The OS and the Architecture matter when compiling Golang code. For instance, for an executable to work with Ubuntu OS with amd64 architecture, the binary also needs to be built under similar environments.

  • It is highly recommended to build the chaincode inside docker containers with the hyper ledger fabric runtime environment images to avoid any conflicts with versions of the programming language and the operating systems. For building golang for fabric v2.5, hyperledger/fabric-ccenv:2.5 can be used

  • To build Golang from any other environment the GOOS and GOARCH env variables must be set as follows before/when running the go build command: GOOS=linux GOARCH=amd64 Eg: “GOOS=linux GOARCH=amd64 go build” Note: The GOARCH must be set even building from docker containers if the docker is run on a Mac machine with arm64 architecture or any other machine that is not amd64.

  • Building & Zipping the go binary executable:

    • Using this command “GOOS=linux GOARCH=amd64 go build -o <package-name>” an executable file will be created

    • If you want to zip the asset-transfer-basic chaincode, select the executable file and zip it. For go binary, a single executable file is expected to be present inside the zip.

Last updated