Adventures in Blockchain

Daz Wilkin
Nov 4, 2017 · 4 min read

I’m spending time in November improving my knowledge of Blockchain technologies (and growing a moustache for Movember). I started in my comfort zone by deploying Hyperledger Fabric to a Google Cloud Platform (GCP) VM and spun through the ‘fabcar’ sample app.

Deploying Fabric and running ‘fabcar’ is straightforward so this post mostly serves as a foundational post and may be of interest if you’d like to run Fabric on GCP.

Hyperledger Fabric

I’m running everything on an Ubuntu 16.04 VM on GCP. If you don’t have a GCP account, you can get started for free here. I assume you’re using a Linux machine with Google’s Cloud SDK installed to create the VM:

ZONE=[[YOUR-PREFERRED-ZONE]] // us-west1-c
INSTANCE=hyperledger-fabric-01gcloud alpha projects create $PROJECTgcloud alpha billing projects link $PROJECT --account-id=$BILLINGgcloud services enable --project=$PROJECTgcloud compute instances create ${INSTANCE} \
--project=${PROJECT} \
--zone=${ZONE} \
--machine-type=custom-2-8192 \
--image=ubuntu-1604-xenial-v20171011 \
--image-project=ubuntu-os-cloud \
--boot-disk-size=50 \
--boot-disk-type=pd-standard \
gcloud compute ssh ${INSTANCE} \
--zone=${ZONE} \

From the ssh session on the ‘hyperledger-fabric-01’, we need to install multiple pre-requisite components.

Here we go!


sudo apt-get updatesudo apt-get install \
linux-image-extra-$(uname -r) \
sudo apt-get updatesudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
curl -fsSL | sudo apt-key add -sudo add-apt-repository \
"deb [arch=amd64] \
$(lsb_release -cs) \
sudo apt-get update
sudo apt-get install docker-ce
sudo usermod -aG docker $USER
sudo systemctl enable docker
docker --version


sudo curl -L`uname -s`-`uname -m` -o /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composedocker-compose --version


sudo curl \
--location$VERSION.$OS-$ARCH.tar.gz \
--output go$VERSION.$OS-$ARCH.tar.gz
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gzexport PATH=$PATH:/usr/local/go/bingo version


curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
nodejs --version
npm --version

Downgrade Python (on Ubuntu)

sudo apt-get install pythonpython --version
Python 2.7.12

Fabric Samples: fabcar

git clone fabric-samples/fabcar

Trick: Hyperledger hosts Fabric containers on dockerhub. Because these are built for various runtime architectures, there’s no singular “latest” container. The trick is to identify and download the most recent versions of the containers, they’re versioned in lock-step which is convenient, and then tag these with “latest”. Here’s a script for Linux X86_64:

for IMAGE in orderer couchdb peer ca tools
docker pull hyperledger/fabric-${IMAGE}:${TAG} && \
docker tag hyperledger/fabric-${IMAGE}:${TAG} hyperledger/fabric-${IMAGE}:latest

Once this completes:

docker images \
--format="{{ .Tag }}\t{{ .Repository }}" \
| grep hyperledger \
| sort
latest hyperledger/fabric-ca
latest hyperledger/fabric-couchdb
latest hyperledger/fabric-orderer
latest hyperledger/fabric-peer
latest hyperledger/fabric-tools
x86_64-1.0.3 hyperledger/fabric-ca
x86_64-1.0.3 hyperledger/fabric-ccenv
x86_64-1.0.3 hyperledger/fabric-couchdb
x86_64-1.0.3 hyperledger/fabric-orderer
x86_64-1.0.3 hyperledger/fabric-peer
x86_64-1.0.3 hyperledger/fabric-tools

Then run the following command to run the Fabric test cluster:


You should see a stream of logs ending:

2017-11-04 00:03:42.880 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00a Chaincode invoke successful. result: status:200 
2017-11-04 00:03:42.880 UTC [main] main -> INFO 00b Exiting.....
Total execution time : 33 secs ...

and, you should be able to:

docker ps --format="{{ .ID }}\t{{ .Names }}"bdcad9115060
e3a219fd5c50 cli
5caa3f261c05 couchdb

Alright! There’s one more pre-req step:

sudo apt-get install build-essentialnpm install

and now you should be able to:

node query.jsCreate a client and set the wallet location
Set wallet path, and associate user PeerAdmin with application
Check user is enrolled, and set a query URL in the network
Make query
Assigning transaction_id: 2b7d262eca16c68523fe61331f08114110f6c6b4d6f1d4725063fcb00d8da4d7
returned from query
Query result count = 1
Response is [
{"Key":"CAR0", "Record":{"colour":"blue","make":"Toyota","model":"Prius","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"colour":"red","make":"Ford","model":"Mustang","owner":"Brad"}},{"Key":"CAR2", "Record":{"colour":"green","make":"Hyundai","model":"Tucson","owner":"Jin Soo"}},
{"Key":"CAR3", "Record":{"colour":"yellow","make":"Volkswagen","model":"Passat","owner":"Max"}},{"Key":"CAR4", "Record":{"colour":"black","make":"Tesla","model":"S","owner":"Adriana"}},{"Key":"CAR5", "Record":{"colour":"purple","make":"Peugeot","model":"205","owner":"Michel"}},{"Key":"CAR6", "Record":{"colour":"white","make":"Chery","model":"S22L","owner":"Aarav"}},{"Key":"CAR7", "Record":{"colour":"violet","make":"Fiat","model":"Punto","owner":"Pari"}},{"Key":"CAR8", "Record":{"colour":"indigo","make":"Tata","model":"Nano","owner":"Valeria"}},{"Key":"CAR9", "Record":{"colour":"brown","make":"Holden","model":"Barina","owner":"Shotaro"}}

I won’t replicate the Fabric tutorial here, instead:


Pre-req’s aside, it’s straightforward to get a Fabric test cluster running and to use the ‘fabcar’ sample. Fabric is written in Golang and supports Golang and Java for contracts and, in this case, Node.js as a client.


To shutdown the Fabric cluster:

cd ../basic-network
docker-compose --file ./docker-compose.yml down
Stopping cli ... done
Stopping ... done
Stopping ... done
Stopping couchdb ... done
Stopping ... done
Removing cli ... done
Removing ... done
Removing ... done
Removing couchdb ... done
Removing ... done
Removing network net_basic

You may “exit” from all the ssh sessions.

You should be returned to your host session. The one from which you ran the gcloud commands. You may either stop the hyperledger-fabric-01 VM:

gcloud compute instances stop ${INSTANCE} \
--zone=${ZONE} \

Or (permanently) delete it:

gcloud compute instances delete $(INSTANCE} \
--zone=${ZONE} \

Or simply delete the entire GCP project:

gcloud alpha projects delete ${PROJECT} --quiet

That’s it!

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

 by the author.

Daz Wilkin

Written by

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade