Tutorial for Hyperledger Fabric Network (v1.3) using Hyperledger Composer (v2.0) and Hyperledger Explorer (v0.3.4)
- VirtualBox
- Docker
- Docker Compose
- Node.js
- NPM
- GIT
- Python
If installing Hyperledger Composer using Linux, be aware of the following advice:
- Login as a normal user, rather than root.
- Do not su to root.
- When installing prerequisites, use curl, then unzip using sudo.
- Run prereqs-ubuntu.sh as a normal user. It may prompt for root password as some of it's actions are required to be run as root.
- Do not use npm with sudo or su to root to use it.
- Avoid installing node globally as root.**
- config.json - Hyperledger Explorer config example
- config_v0.3.4.json - Hyperledger Explorer config example (v0.3.4)
- model.cto - Network models example
$ sudo apt update && sudo apt upgrade
$ sudo apt install git make gcc g++ libltdl-dev curl python pkg-config
$ sudo apt update && sudo apt upgrade
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update
$ sudo apt install docker-ce
$ sudo systemctl status docker
$ docker -v
$ sudo su
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ su $USER
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose -v
$ wget https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz
$ tar -xf node-v8.11.2-linux-x64.tar.xz
$ mv node-v8.11.2-linux-x64/ node/
$ echo 'export PATH=~/node/bin:$PATH' >> ~/.profile
$ source .profile
$ npm install -g npm
$ npm install -g grpc
$ node -v
$ npm -v
$ npm install -g [email protected]
$ npm install -g [email protected]
$ npm install -g [email protected]
$ npm install -g yo
$ npm install -g [email protected]
$ mkdir ~/fabric-dev-servers && cd ~/fabric-dev-servers
$ curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
$ tar -xvf fabric-dev-servers.tar.gz
$ cd ~/fabric-dev-servers
$ export FABRIC_VERSION=hlfv12
$ ./downloadFabric.sh
$ git clone https://github.com/hyperledger/fabric-samples.git
$ cd fabric-samples
$ curl -sSL https://bit.ly/2ysbOFE | bash -s 1.3.0
$ echo 'export PATH=~/fabric-samples/bin:$PATH' >> ~/.profile
$ source ~/.profile
$ cd ~/fabric-dev-servers
$ export FABRIC_VERSION=hlfv12 (Old version hlfv11)
$ ./startFabric.sh
$ docker ps
$ ./createPeerAdminCard.sh
$ ~/fabric-dev-servers/startFabric.sh
Check CouchDB: https://localhost:5984/_utils/#
$ composer-playground
Check Composer Playground: https://localhost:8080/login
$ yo hyperledger-composer:businessnetwork
Network Configuration:
- Network Name: tutorial-network
- License: Apache-2.0
- Namespace: org.example.mynetwork
- Empty Network: No Defining a business network
- Modelling network (.cto file)
- Defining JavaScript transaction logic (logic.js file)
- Defining access control (permissions.acl)
$ cd tutorial-network
$ composer archive create -t dir -n .
Note: Fabric network should be running (./startFabric.sh)
$ cd tutorial-network
$ composer network install --card PeerAdmin@hlfv1 --archiveFile [email protected]
$ composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card
$ composer card import --file networkadmin.card
$ composer network ping --card admin@tutorial-network
$ composer-playground
Check Composer Playground: https://localhost:8080
$ cd tutorial-network
$ composer-rest-server
REST Server Configuration:
- Card Name: admin@tutorial-network
- Namespaces: Never Use
- Secure the generated API with API Key: No
- Enable authenticatio using Passport: No
- Enable explorer test interface: Yes
- Enable dynamic logging: No
- Enable event publication over WebSockets: Yes
- Enable TLS security: No Check REST API: https://localhost:3000/explorer/
$ cd tutorial-network
$ yo hyperledger-composer:angular
Application Configuration (Change)
- Connect to running business network: Yes
- Enter standard package.json questions
- Business network card: admin@tutorial-network
- Select: Connect to an existing REST API
- REST Server address: https://localhost
- Server port: 3000
- Select: Namespaces are not usednom
Note: REST Server should be running
$ cd angular-app
$ npm start
Check Angular App: https://localhost:4200 Fix Error message: Invalid Host header
- In node_modules/webpack-dev-server/lib/Server.js change:
- "if(this.disableHostCheck) return true;" to "return true;"
Versions tested:
- Latest - Not working
- v0.3.7.1 - Not working
- v0.3.7 - Not working
- v0.3.6 - Not working
- v0.3.5.1 - Working (Tests failed)
- v0.3.5 - Working (Tests failed)
- v0.3.4 - Working (Current used)
- v0.3.3 - Working
$ sudo apt update && sudo apt upgrade
$ git clone --branch v0.3.4 https://github.com/hyperledger/blockchain-explorer.git
$ wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
$ tar -xvzf jq-1.5.tar.gz
$ cd jq-1.5
$ ./configure && make && sudo make install
$ jq --version
$ sudo apt install postgresql postgresql-contrib
$ sudo pg_createcluster 10 main --start
$ psql --version
$ cd ~/fabric-dev-servers
$ ./startFabric.sh
$ sudo -u postgres psql
$ \i app/persistence/postgreSQL/db/explorerpg.sql
$ \i app/persistence/postgreSQL/db/updatepg.sql
$ \l
$ \d
$ \q
Save backup:
$ cd blockchain-explorer/app/platform/fabric
$ cp config.json config_backup.json
Check info:
$ nano ~/fabric-dev-servers/DevServer_connection.json
Change on:
$ cd blockchain-explorer/app/platform/fabric
$ nano config.json
Add: "channel": "mychannel", "pg": { "host": "127.0.0.1", "port": "5432", "database": "fabricexplorer", "username": "hppoc", "passwd": "password" }
Save backup:
$ cd blockchain-explorer
$ npm install
$ npm audit fix
$ cd app/test
$ npm install
$ npm audit fix
$ npm run test
$ cd ../../client
$ npm install
$ npm audit fix
$ npm test -- -u --coverage
Fix error: getBlockActivity is not a function
$ cd blockchain-explorer
$ nano ~/blockchain-explorer/client/src/components/View/LandingPage.spec.js
Add entry on file client\src\components\View\LandingPage.spec.js:
- Add: getBlockActivity:jest.fn(),
$ npm run build
``
#### Start/Stop Explorer
Save backup:
```sh
$ cd blockchain-explorer
$ ./start.sh
$ ./stop.sh
Check Explorer: https://localhost:8080
https://hyperledger-fabric.readthedocs.io/en/release-1.4/
https://hyperledger.github.io/composer/latest/introduction/introduction.html
https://github.com/hyperledger/blockchain-explorer