GOPATH/GOROOT setup for Hyperledger fabric chaincode - hyperledger-fabric

I have done basic setup in Hyperledger Fabric 1.4.7 and made all peer's to join the channel. After exploring chaincode in golang, I started trying chaincode install command and I was facing issue's in this step.
error
Error: error getting chaincode code mycc: path to chaincode does not exist: /home/user899/go/src/chaincode
When I just ran go run chaincode.go
error
chaincode.go:7:2: cannot find package "github.com/hyperledger/fabric-chaincode-go/shim" in any of:
/usr/lib/go-1.14/src/github.com/hyperledger/fabric-chaincode-go/shim (from $GOROOT)
/home/user899/go/src/github.com/hyperledger/fabric-chaincode-go/shim (from $GOPATH)
chaincode.go:8:2: cannot find package "github.com/hyperledger/fabric-protos-go/peer" in any of:
/usr/lib/go-1.14/src/github.com/hyperledger/fabric-protos-go/peer (from $GOROOT)
/home/user899/go/src/github.com/hyperledger/fabric-protos-go/peer (from $GOPATH)
Environments
echo $GOPATH
/home/user899/go
Chaincode location
/home/user899/SoloNetwork/chaincode
Can anyone help.
Thanks

I'm answering my own question. Here is the solution, I was not aware of the directory structure that need's to be followed in Go.
So first, I checked my GOPATH(usually the workspace where we can write all our go files) using go env in the terminal it was located under home/dev/go
And coming about the directory structure it should be followed as following :-
$GOPATH + /src/github.com/chaincode, So the final structure will be home/dev/go/src/github.com/chaincode inside chaincode. I can place all Go files.
So after getting chaincode file from here, I have placed in the above location and executed the following commands
go mod init
go mod tidy
Then, I was able to execute peer chaincode install commad
peer chaincode install -n mycc -p "github.com/chaincode" -v 1.0
Here in the command -p "github.com/chaincode" is the folder name that I have created.
So finally chaincode path is created by these : $GOPATH + src + -p flag
If anyone is facing, go binary related issue's set your GOROOT path to the bin location where go is intalled.

Related

Deploying Chaincode Failed

I was following the tutorial of hyperledger fabric "Using the Fabric Test Network", ang upon deploying the chaincode to the channel I encountered errors that I don't know what's the problem with it. I tried everything I have searched so far but no luck on fixing it. I tried uninstalling everything, and starting from the beginning of the installation but again no luck. I am new to this blockchain platform and is an aspiring developer for it. Anyone Please help.
Here is the result upon running the chaincode deployment :
Please do note that I tried installing golang (go1.13.x versions, go1.18.x and go1.19.x)but none solved the problem, anybody please help.
The screenshot shows that you don't have golang on the path. You need to ensure your $PATH variable includes the directory where the go binary is installed. However a further issue is you must ensure that the correct version of Go is installed that matches the version of Hyperledger Fabric you are using. Refer to the release notes of Hyperledger Fabric found here https://github.com/hyperledger/fabric/releases for your version to determine the appropriate version of golang to use.
A simpler option would be to install the javascript chaincode rather than the Go chaincode as this doesn't require any language support to be installed
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript -ccl javascript
I see this error in your screenshot:
go: command not found
Check you can run go from your shell:
go version
You likely need to add the go executable to your shell's PATH, as described in the Go installation instructions.

Error when trying to bring up the test network

I trying to follow tutorials and develope on Ubuntu. Then get an error when comes to "Bring up the test network" part. I successfully run the following command to print the script help text of the test network.
./network.sh -h
When I want to run the next command to bring up the network
./network.sh up
I get the message as follow
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
ERROR! Peer binary and configuration files not found..
May somebody tells me what's happened? Kindly helps.
I had the same issue, looks like you need to fetch system specific binaries:
https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html
I ran the curl command in the root dir without specifying the versions.
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s
Make sure you add the ./bin to .gitignore
Be sure to use
./network.sh up
from the test network folder and that test network folder is contained in fabric samples, because it could use binaries from different directories contained inside fabric samples and moving it could cause your error.
Also try to set this environment variable
FABRIC_CFG_PATH=$PWD
to force Fabric to be launched in your test network folder
first bring down the network to clean up
cd test-network
./network.sh down
start the network agian
./network.sh up
Before you can deploy the test network, you need to follow the instructions to Install the Samples, Binaries and Docker Images in the Hyperledger Fabric documentation.

Installing Hyperledger Fabric as normal user in Linux throws the error

I refered link
https://github.com/jollen/Hyperledger-Fabric-Install
as I started installing hyperledger fabric on commmand "make configtxgen" it throws me the error
Makefile:66: *** "No go in PATH: Check dependencies". Stop.
You do not have the Go compiler installed and/or located in your PATH. There is a section on the link you referenced about installing Go, adding it to your profile and then sourcing the profile. If you don't do this in the current terminal session, Go will not be found in your PATH. (logging in and out will also make it available).
FYI - The link you referenced is pretty old ... if you are in fact just trying to install and get up and running with Fabric I'd suggest you actually use the Fabric getting started documentation ( http://hyperledger-fabric.readthedocs.io/en/release-1.2/getting_started.html ).

Issue bringing up Hyperledger Fabric "Building Your First Network" sample

while I am running this command from my terminal
sudo ./byfn.sh -m up
I am getting below error:
Starting with channel 'my-channel' and CLI timeout of '10' seconds
and CLI delay of '3' seconds Continue (y/n)? y proceeding ...
Pulling orderer.example.com (hyper-ledger/fabric-orderer:latest)...
ERROR: manifest for hyper-ledger/fabric-orderer:latest not found
ERROR !!!! Unable to start network Error response from daemon: No
such container: cli
How do I resolve this please?
You need to download platform specific binaries, please see how to do it here in the following tutorial. Please also make sure you have all per-requisites, you can find more about what needed here.
Ideally, you should download the platform binaries and images as given in the Fabric documentation - Install Binaries and Docker Images
Or
You should make sure that your terminal has internet access & not behind any corporate proxy. Whatever is needed would be pulled by docker anyway. I am guessing that hyperledger/fabric-baseos image is not pulled by the script above.
If you don't find hyperledger/fabric-baseos:latest,then either docker pull hyperledger/fabric-baseos:tag depends on the fabric version on your own
Or, the chaincode instantiate process in byfn- end to end CLI would do it for you.
I had the same issue. Turns out it was just a broken docker-compose installation. I simply figured it out typing docker-compose in my terminal, and I ran into ImportError: No module named ssl_match_hostname
With a clean docker compose install, I got it to work.

How do I resolve the error on hyperledger fabric?

While trying to follow tutorial on building your first network I've got following output:
$ ./byfn.sh -m generate
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10000'
Continue (y/n)? y
proceeding ...
which: no cryptogen in (/c/users/ayush/fabric-samples/first-network/../bin:/c/users/ayush/fabric-samples/first-network:c:/users/ayush/bin:/c/Users/ayush/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Program Files/Docker Toolbox:/c/Users/ayush/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/ayush/bin:/c/ProgramData/Oracle/Java/javapath:/c/Program Files/Docker/Docker/Resources/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/Intel/WiFi/bin:/c/Program Files/Common Files/Intel/WirelessCommon:/cmd:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/Gradle/gradle-3.3/bin:/c/Go/bin:/c/Program Files/nodejs:/c/Users/ayush/AppData/Local/Programs/Python/Python36/Scripts:/c/Users/ayush/AppData/Local/Programs/Python/Python36:/c/Users/ayush/AppData/Local/Microsoft/WindowsApps:/c/python:/c/Program Files/Docker Toolbox:/c/Users/ayush/AppData/Roaming/npm:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
cryptogen tool not found. exiting
What is the problem and how can I get it solved?
The key of you problem is in the last sentence:
cryptogen tool not found. exiting
You need to make sure to have cryptogen tool compiled prior to trying run the example with ./byfn.sh. Just run from fabric home folder:
make cryptogen configtxgen peer orderer peer-docker orderer-docker tools-docker
Update
You are missing: "Platform specific binaries", see here how to get them.
If you're using a mac, do the following in terminal:
brew tap hyperledger/fabric
brew install fabric-tools
and then try again with ./byfn.sh -m generate command
I got the answer now.
This issue is caused by the lack of cryptogen, which is indeed a command tool. The simplest way to get it is to download the platform specific binaries into your local machine,
here is the sh:
cd fabric-samples
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap-1.0.1.sh | bash
This sh will download a bash file which would pull the latest Fabric docker images and the platform specific tools, its content is as below:
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
export VERSION=1.0.1
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
#Set MARCH variable i.e ppc64le,s390x,x86_64,i386
MARCH=`uname -m`
dockerFabricPull() {
local FABRIC_TAG=$1
for IMAGES in peer orderer couchdb ccenv javaenv kafka zookeeper tools; do
echo "==> FABRIC IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
done
}
dockerCaPull() {
local CA_TAG=$1
echo "==> FABRIC CA IMAGE"
echo
docker pull hyperledger/fabric-ca:$CA_TAG
docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}
: ${CA_TAG:="$MARCH-$VERSION"}
: ${FABRIC_TAG:="$MARCH-$VERSION"}
echo "===> Downloading platform binaries"
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz
echo "===> Pulling fabric Images"
dockerFabricPull ${FABRIC_TAG}
echo "===> Pulling fabric ca Image"
dockerCaPull ${CA_TAG}
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger*
Now it is based on Fabric 1.0.1, you can find the latest version of this bash from here :
http://hyperledger-fabric.readthedocs.io/en/latest/samples.html
After the sh execution is completed, there will be a folder named bin in current directory, then copy the files under this folder into a searchable folder, such as
cp ./bin/* $GOROOT/bin
Then you can test if the cryptogen exists by type command:
which cryptogen
The main problem is in the last line of error which says
"cryptogen tool not found. exiting"
Please follow below steps to resolve this issue-
Download the platform-specific binaries using command
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/v1.0.5/scripts/bootstrap.sh | bash -s 1.0.5
Once you run the command it will download various tools like cryptogen, configtxgen etc under bin directory.
add the bin directory to your PATH variable using below command
export PATH=$PATH:[path-to-bin-directory]
now try to build the network again.
I hope this helps someone.
Please follow below steps to resolve this issue:
1.Download the platform-specific binaries using command
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.1.0"
Once you run the command it will download various tools like cryptogen, configtxgen etc under bin directory.
1.add the bin directory to your PATH variable using below command
export PATH=./bin:$PATH
Step1: cd fabric-samples
Step2:
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/v1.0.5/scripts/bootstrap.sh | bash -s 1.0.5
Step3: cd fabric-samples/first-network
Step4: ./byfn.sh -m generate
You will see a brief description as to what will occur, along with a yes/no command line prompt. Respond with a y or hit the return key to execute the described action.
Not sure if its still an issue or not.....
You can either try to use what #Artem already mentioned,
or
you can add the ......fabric-samples/bin folder to your path, which has the tools. its the same fabric-samples folder that has the byfn.sh
cryptogen command is under the bin directory where you installed (or uncompressed) the fabric tarball. So you just need to update your $PATH variable so that the shell knows where the cryptogen command can be found.
This code should work:
export "$PATH:/<home>/<fabric>/bin"
Where <home> is your home directory, such as /home/sindelio
and <fabric> is where the fabric was installed.
Unless you close the terminal, following solution works:
export PATH=$PATH:PATH_TO_FABRIC_SAMPLES/bin
Probably have missed this Step
Download Platform-specific Binaries
https://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html
run command in
cd Fabric-Samples
Download the platform-specific binaries after cd into your workspace.
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/v1.4.0/scripts/bootstrap.sh | bash
and make sure your version of binaries matches your configuration file.

Resources