Your instructor: Lennart [email protected], Developer Advocate at IBM, focusing on Blockchain, Fintech and Watson.
Marek Sadowski, Syed Zaidi. Maya Reyes, Juanita Dion.
Assumption: you have brought your laptop and you know enough about Blockchain to want to write Blockchain apps.
6:00: Sign-in, mingle, food, welcome, form teams
6:20: Lennart: Introduction to IBM Blockchain and Hyperledger
6:40: Coding starts.
Lab 1: Let's run our first application in Hyperledger Fabric
Lab 2: Let's write an app with the Hyperledger Composer
Lab 3: A full app, Decentralized Energy with Hyperledger Composer
8:15: Coding ends.
Where do we go from here?
Developer Journeys for Blockchain
Q1 2018: Advanced Blockchain, a Hands-on Workshop.
8:30: Event ends
October 2008 It all started with Satoshi Nakamoto and his paper Bitcoin: A Peer-to-Peer Electronic Cash System which addressed a key problem in electronic commerce:
In this workshop we will use the Hyperledger implementation of Blockchain : http://hyperledger.org/
Hyperledger, an open source collaborative effort to advance cross-industry blockchain technologies, is hosted by The Linux Foundation®.
Deployed in Docker images.
-
A blockchain emulates a “trusted” computing service through a distributed protocol, run by nodes connected over the Internet.
-
The service represents or creates an asset, in which all nodes have some stake.
-
The nodes share the common goal of running the service but do not necessarily trust each other for more.
....
- On the other hand, blockchains in the “permissioned” model control who participates in validation and in the protocol; these nodes typically have established identities and form a consortium
Consensus protocol is pluggable, currently an implementation of Byzantine fault-tolerant con- sensus using the PBFT protocol.
Source: https://www.zurich.ibm.com/dccl/papers/cachin_dccl.pdf
Hyperledger Composer source code on GitHub https://github.com/hyperledger/composer
Hyperledger Composer is an application development framework which simplifies and expedites the creation of Hyperledger fabric blockchain applications.
Hyperledger Fabric source code on Github https://github.com/hyperledger/fabric
Hyperledger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability. It is designed to support pluggable implementations of different components, and accommodate the complexity and intricacies that exist across the economic ecosystem.
A Business Network Archive (BNA) file is exported by the Hyperledger Composer with the extension of .bna, and contains the definitions all the definitions for a Business Network. It is deployed in a Hyper Ledger Fabric.
http://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html
Please note that it is crucial that you go thru the link above to verify that you have met the requirements for running Hyperledger on your laptop. Especially if the labs do'nt work.
We will be developing on our laptops. MacOS, Ubuntu or Windows.
Original instructions: http://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html
1 docker rm -f $(docker ps -aq)
2 docker rmi dev-peer0.org1.example.com-fabcar-1.0 //delete chaincode image
1. Source file: http://hyperledger-fabric.readthedocs.io/en/release/write_first_app.html
2. Open terminal window on laptop, do: git clone https://github.com/hyperledger/fabric-samples.git
3. cd fabric-samples/fabcar
4. See what's inside the directory: enrollAdmin.js invoke.js package.json query.js registerUser.js startFabric.sh
5. docker rm -f $(docker ps -aq)
6. Start the fabric: ./startFabric.sh
7. Install the SDK Node modules: npm install
8. node enrollAdmin.js
9. node registerUser.js
- node query.js
Output:
Creating network "net_basic" with the default driver Creating couchdb ...
Creating ca.example.com ...
CA: Certificate Authority https://hyperledger-fabric-ca.readthedocs.io/en/latest/
Comment: It provides features such as:
1. Issues certificates to other network participants to enroll in the network,
or connects to LDAP as the user registry
2. issuance of Enrollment Certificates (ECerts)
3. certificate renewal and revocation
Creating orderer.example.com ...
Comment: The Hyperledger fabric ordering service is intended to provide an atomic broadcast
ordering service for consumption by the peers. This means that many clients may
submit messages for ordering, and all clients are delivered the same series of
ordered batches in response.
Creating ca.example.com
Creating orderer.example.com
Creating couchdb ... done
Comment: Transactions are collected into blocks/batches on the Ordering Service.
The blocks are stored locally to disk on every Ordering Service node
along with a LevelDB or CouchDB index to these blocks by number.
The blocks are delivered via RPC to committing peers.
The peers store them locally, and maintain a LevelDB (or CouchDB)based block index.
http://bit.ly/2zORhrC
Creating peer0.org1.example.com ...
Comment: A Peer is a node that validates and commits transactions and maintains the state and a copy
of the ledger.
Every peer stores the data of the blockchain in its container.
In a production envirement this container has a volume (mounted folder) to a real hard drive, NAS, SAN
or any other storage that you may use. Otherwise if the container is stopped all the data that was in the
container will be gone.
Every peer stores exactly the same data. So if a blockchain is 10Gb and you have 5 peers
then 50Gb will be needed to store 5 separate files from every peer and every file is 10Gb.
Creating peer0.org1.example.com ...
done
11 node query.js
output;
Arnes-MBP:fabcar arnelennartfrantzell
$ node query.js
Create 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: 9367267e0e9c66cba821eb79500ffee6f004ced6f53bc01ddf280b00e2a8cb10
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"}}]
1 Open the Invoke.js program, locate the request function and change the args section like this, using your own name and args:
var request = {
targets: targets,
chaincodeId: options.chaincode_id,
fcn: 'createCar',
args: ['CAR10', 'Chevy', 'Volt', 'Red', 'Lennart'],
chainId: options.channel_id,
txId: tx_id
2 Save the file and invoke it like this: node invoke.js.
3 Followed by: node query.js
You should see the new car appear, stored in the blockchain.
1 Change the Invoke.js program as shown below:
// createCar - requires 5 args, ex: args: ['CAR11', 'Honda', 'Accord', 'Black', 'Tom'],
// changeCarOwner - requires 2 args , ex: args: ['CAR10', 'Barry'],
// send proposal to endorser
var request = {
targets: targets,
chaincodeId: options.chaincode_id,
// fcn: 'createCar',
fcn: 'changeCarOwner',
// args: ['CAR10', 'Chevy', 'Volt', 'Red', 'Lennart'],
args: ['CAR10', 'Syed'],
chainId: options.channel_id,
txId: tx_id
};
2 Again, enter node query.js.
You will see that the new owner is now Syed.
This concludes Lab 1.
Run Hyperledger Composer in your browser https://hyperledger.github.io/composer/
This concludes the second lab centered arund the Composer Playground.
This third lab, a Developer Journey written by Raheel Zubairy of IBM, describes a complete blockchain application with a decentralized energy network with a working user interface.
https://developer.ibm.com/code/journey/decentralized-energy-hyperledger-composer/
Lab Instrructions: https://github.com/IBM/Decentralized-Energy-Composer?cm_sp=IBMCode-_-decentralized-energy-hyperledger-composer-_-Get-the-Code
IBM has a series of Developer Journeys covering various aspects of Blockchain, with more being added regularly.
- https://developer.ibm.com/code/journey/build-your-first-blockchain-application/
- https://developer.ibm.com/code/journey/create-and-execute-blockchain-smart-contracts/
- https://developer.ibm.com/code/journey/implement-fda-food-supplier-verification-program-on-hyperledger-composer/
- https://developer.ibm.com/code/journey/build-a-blockchain-network/
- https://developer.ibm.com/code/journey/decentralized-energy-hyperledger-composer/
- https://developer.ibm.com/code/journey/run-blockchain-technology-on-a-linux-mainframe/
- https://developer.ibm.com/code/journey/create-a-to-do-list-app-using-blockchain/
- https://developer.ibm.com/code/journey/deploy-an-asset-transfer-app-using-blockchain/
Blockchain in the IBM Cloud: https://console.bluemix.net/catalog/services/blockchain/
** Initiate a new blockchain network including setting democratic network policies and inviting new members to join. ** Join a network, as a new member, based on an invite from the network initiator.
- Use Issues to log suggestions to this workshop. #1
Instructions below from thess URLs:
- http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
- http://hyperledger-fabric.readthedocs.io/en/latest/samples.html
- http://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html
Only if necessary, execute the following three commands to remove existing Docker instances.
- docker kill $(docker ps -q)
- docker rm $(docker ps -aq)
- docker rmi $(docker images dev-* -q)
Instructions below come from the following URL: http://hyperledger-fabric.readthedocs.io/en/latest/samples.html
From a terminal window on your laptop, execute the following commands:
- git clone https://github.com/hyperledger/fabric-samples.git into a directory on your laptop From that directory on your laptop (see above) invoke:
- curl -sSL https://goo.gl/Q3YRTi | bash
- export PATH=/bin:$PATH
- Instructions below come from the following URL:
http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
Bring up the Hyperledger Fabric:
- cd first-network
- ./byfn.sh -m generate
- ./byfn.sh -m up. //See full output from command on this link http://bit.ly/2yyTeIj
- After checking the output, remember to run ./byfn.sh -m down.
http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
https://hyperledger.github.io/composer/business-network/bnd-deploy.html ``~ Arnes-MBP:bnafile arnelennartfrantzell$ composer network deploy -p hlfv1 -a my-basic-sample.bna -i PeerAdmin -s randomString -A admin -S Deploying business network from archive: my-basic-sample.bna Business network definition: Identifier: [email protected] Description: The Composer basic sample network
✔ Deploying business network definition. This may take a minute...
Command succeeded
## ping application on hyperledger composer
Arnes-MBP:bnafile arnelennartfrantzell$ composer network ping -n my-basic-sample -p hlfv1 -i admin -s adminpw
The connection to the network was successfully tested: my-basic-sample
version: 0.14.1
participant: org.hyperledger.composer.system.NetworkAdmin#admin
Command succeeded