Sunday, October 11, 2020

Blockchain | Hyperledger Fabric | Package Chaincode - Chaincode LifeCycle

In Hyperledger Fabric chaincode Lifecyle, package of chaincode is very important step so I will show you how to package your chaincode in chaincode LifeCycle.

You need to ensure that you have chaincode development and compiled. You can develop your chaincode in Go Lang, Java, Node, Type Script, Java Script.

In ideal scenario, packaging of chaincode is done by only one organization in network rather that need to be done by each organization. One of the organization can package the chaincode and then send that package to all other organizations.

When you package the chaincode, it create a file with extension .tar.gz.

Now let's see what steps you need to follow for chaincode packaging. 

First you need to ensure that your network is up & running and channel is also created.

Before you package the chaincode, you need to set some variable so you can simply run below commands for that.

export CORE_PEER_TLS_ENABLED=true

export CORE_PEER_LOCALMSPID="Org1MSP"

export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

export CORE_PEER_ADDRESS=localhost:7051

Now run below command to package your chaincode. You need to ensure that you are under fabric-samples/test-network folder.

peer lifecycle chaincode package car.tar.gz --path ../chaincode/car/go/ --lang golang --label car_1

Here

car.tar.gz is your packaged chaincode

../chaincode/car/go is the path of your compiled chaincode

golang is chaincode language 

car_1 is label of your chaincode package



Blockchain: Hyperledger Fabric 2.2 Setup on Ubuntu

This post explains how to setup Hyperledger Fabric 2.2 on Linux operating system.

Before you install Hyperledger Fabric, you need to do prerequisites setup where you will install

Curl , NodeJs, Git, Python, Go Language, Libtool, Docker CE & Docker Compose

 Now let's see how to install all these one by one.

Curl Installation

 Run below command to install Curl.

 sudo apt-get install curl

 To verify the installation, run below command.

 curl --version

 NodeJs Installation

 Open the terminal window and run below command to download and execute the nodejs file.

 curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –

 Then run below command.

 sudo apt-get update

 Run below command to start the installation for NodeJs.

 sudo apt-get install nodejs

 Run below command to check if Nodejs is successfully installed or not. This should return the version of NodeJs.

 node --version

 Git Installation

 Open the terminal window and run below command. This will start the installation for Git.

 sudo apt-get install git

Run below command to check if Git is successfully installed or not. This should return the version of Git.

 git --version

 Python Installation

 In the terminal window, run below command to install Python.

 sudo apt-get install python

 Verify the installation by running below command and that should return the version of Python.

 python --version

 Go Language

Step 1: Very first step is to download the installer, for that go to https://golang.org/ site. Click on "Download Go" button and that should take you to next page.

Step 2: Click on Linux tar file which is Linux installer and that should download the installer for you.

Step 3: First untar the downloaded file. Since the file is downloaded in Downloads folder so first you need to go to that folder and then run below command.

 cd Downloads

sudo tar -xvf go1.13.4.linux-amd64.tar.gz

Step 4: You should be able to see newly created "go" folder under Downloads folder, to verify that run "ls" command.

Step 5: Move the go folder from Downloads to /usr/local folder using below command.

 sudo mv go /usr/local

Step 6: Next step is to set few variables and update the PATH variables. There are two ways to do that.

First way is to set is temporary and second way is to set permanent variables so that you need not to do the same steps again and again.

If you want to go with first step then follow below steps.

 export GOROOT=/usr/local/go

 cd $HOME

mkdir gowork

export GOPATH=$HOME/gowork

export PATH=$PATH:$GOROOT/bin

export PATH=$PATH:$GOPATH/bin

 

If you want to go with second step which I recommend then follow below steps.

go to home location and press " ctrl+H" to see the hidden files

open .profile file and add below entries

GOROOT=/usr/local/go

GOPATH=$HOME/gowork

 

Update the PATH variable to append both GOROOT and GOPATH bin folders and your PATH variable should look like below.

 PATH="$HOME/bin:$HOME/.local/bin:/usr/local/go/bin:$HOME/gowork/bin:$PATH"

 Step 7: Validate if golang is successfully installed in your system by running below command. This command should return version of go language installed.

 go version

 Lib Tools Installation 

Install Lib tools using below command.

 sudo apt-get install libltdl-dev

 Docker CE (Community Edition) Installation 

Download and install it using below commands.

wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_17.06.2~ce- 0~ubuntu_amd64.deb

sudodpkg -i<file>

 Check the version of docker using below command and this should return the version of docker.

docker --version

 

Docker Compose Installation

 Run below commands to setup Docker compose.

sudo apt-get install python-pip

pip --version

sudo pip install docker-compose

 Verify the installation and check the version from below command.

 docker-compose version


One you perform all above prerequisites then you need to perform below steps to complete fabric 2.2 setup.

Hyperledger Fabric Setup

Run below command to download and setup Fabric.

curl -sSL https://bit.ly/2ysbOFE | bash -s

You may encounter below issue when you run above command.

failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:

To fix this you need run below command.

sudo chmod 666 /var/run/docker.sock

After running this command, run the command that is mentioned in previous step again and you should be able to download and setup on your system.


Friday, June 26, 2020

Ethereum Blockchain - Understand Ganache Blockchain User Interface

In Previous post, I have explained how to install Ganache Blockchain on Windows system. Next step for you is to understand the Ganache Blockchain user interface once you complete the installation. This post will help you to understand that.

Let's try to understand different options that you see on Ganache Blockchain.

Let's first understand the below header that you see below menu bar.


Current Block: 
As you are aware, Blockchain is chain of block so whenever you perform any transaction, it gets added to block so this field show the current block number in that blockchain. It's value will be always zero when you perform fresh installation and when you restart your ganache blockchain.

E.g. If you see value 145 here that means total 145 blocks are there in Blockchain and latest block number is 145.

Gas Price and Gas Limit

These two parameters are related to Ethereum gas. For now, you remember that when ever you perform any action in Ethereum blockchain then need to pay some amount (money) and that amount is measured in Gas. we will discuss about these two parameters in details in upcoming posts.

HardFork

There is concept of fork in Blockchain and there are two types of Fork, one is soft fork and other is hard fork. At very high level, when we perform fork that means you break the blockchain and create a new chain from existing chain so you may have two versions running of same blockchain at given time.

Network Id

This is network Id of this Ganache Blockchain network. The default value for this is 5777.

Every network in Ethereum has unique network Id so you can't have two networks with same network Id.

RPC Server

The default value of this field is http://localhost:7545. This helps clients to connect to Ganache network. Suppose, you install this ganache blockchain on one machine and you need to access that ganache blockchain from another machine that is in network then you will use this URL to connect to blockchain.

7545 is the default port but this can be changed by clicking on setting option.

Mining Status

In Production ethereum blockchain network, mining is done by miner but for ganache blockchain mining is always set to automatic as this is your local blockchain that means all your transactions gets automatically mined in ganache blockchain.

Switch

This button helps you to switch from current environment to another environment.

Settings

Under setting, you find different options but the main thing that you can do here is to change your RPC server details and network Id as shown below.


 Now let's understand the Menu bar options.



Accounts

In production ethereum network, you need to first create the account before you access that network but ganache blockchain provide some free account with the installation. You get 10 default accounts and each account has 100 ETH balance. 

Every account is indexed from 0 to 9 and every account has public and private keys. You will use these accounts when you will perform some transactions in ganache blockchain.



Blocks

This shows the blockchain blocks, as you already learnt in above section that block gets created when you perform some transactions so you can that blocks in this window.



Transactions

In this section, you see all the transactions performed. Initially it is blank but you started to see some data as you perform some transactions.

Contracts
 
Here you see list of all smart contracts deployed on ganache blockchain. Smart contract is new concept that we have in Ethereum blockchain where you write piece of code and deploy as application on blockchain.


Events

Events are defined in your smart contracts and get fired when certain conditions are met.

Logs

In this section, you see all the logs. Whatever action is perform, log of that action can be seen in this section.


Ethereum Blockchain- How to Install Ganache Blockchain on Windows 10 ?

As a technology beginner, you always look for something that you can simply install on your local laptop or system and perform some hands-on to learn that new technology.

If you are starting with Blockchain, mainly with Ethereum and you need to perform some hands then you need to have local setup of Ethereum blockchain  network.

Ethereum does provide some test blockchain networks but it is always best to have setup on your local system to start with.

In this post, we will see how you can install Ganache Blockchain on your windows machine which acts your local ethereum blockchain network.

Step 1: First of you all, you need to download the setup file. To do that, go to below link and click on "Download Windows" option as shown below.

https://www.trufflesuite.com/ganache



Step 2: Once you download the file, double click on that and it start the installation. 

 


You see below Pop-Up where you need to click on "Install" button.



It starts the installation and you can see the progress as shown below.



 Click on Launch when installation is completed. 

You see below window get opened once it launches the application.



Click on "Continue" button and on next screen choose "QuickStart Ethereum" option as that will set all default options for you.



You will see below screen. If you are able to see below screen that means your installation is successful. 


Thanks for reading this post.

In Next post, I will explain what all different options you have in Ganache Blockchain.