Hyperledger Fabric: Unable to build Chaincode

Problem Scenario:

You are working on Hyperledger Fabric and you are following this tutorial: Chaincode for Developers and when you try building your chaincode, it hungs up forever.

You run the following command on your terminal to build the chaincode you wrote:


go get -u --tags nopkcs11 github.com/hyperledger/fabric/core/chaincode/shim

But, you get no result (either success or error). The command just hangs up forever on your terminal.

Solution:

The most probable cause of this issue is that of the missing folder of fabric project inside your GOPATH directory.

The GOPATH directory is generally present inside your user directory in the folder go or .go.

You can echo the GOPATH directory in your terminal as well (if you have set the GOPATH environment variable via export command or writing it in your .bashrc/.bash_profile file):


echo $GOPATH;

Mine GOPATH is set at:

/Users/mukeshchapagain/.go/

  • Go to your GOPATH directory
  • Then go to src/github.com/hyperledger sub-directory
  • So, the full path will be:

/Users/mukeshchapagain/.go/src/github.com/hyperledger

  • Now, see if there is fabric folder inside it
  • There should not be any fabric folder. You have to clone the fabric github repository over here:

git clone git@github.com:hyperledger/fabric.git
  • Additionally, also clone the fabric-ca repository:

git clone git@github.com:hyperledger/fabric-ca.git
  • After these steps, two folders fabric and fabric-ca will be created inside your hyperledger folder:

/Users/mukeshchapagain/.go/src/github.com/hyperledger/fabric
/Users/mukeshchapagain/.go/src/github.com/hyperledger/fabric-ca

Now, go to $GOPATH/src/sacc folder.

When you run the command to build the chaincode, it should run successfully.


go get -u --tags nopkcs11 github.com/hyperledger/fabric/core/chaincode/shim

Hope this helps. Thanks.