{"id":2439,"date":"2017-12-01T01:48:49","date_gmt":"2017-12-01T01:48:49","guid":{"rendered":"http:\/\/websecuritypatterns.com\/blogs\/?p=2439"},"modified":"2018-01-08T02:00:31","modified_gmt":"2018-01-08T02:00:31","slug":"exploring-hyperledger-fabric-v1-building-first-network-byfn","status":"publish","type":"post","link":"https:\/\/websecuritypatterns.com\/blogs\/2017\/12\/01\/exploring-hyperledger-fabric-v1-building-first-network-byfn\/","title":{"rendered":"Exploring Hyperledger Fabric v1 &#8211; Building your first network (BYFN)"},"content":{"rendered":"<p>It was quite easy ! <em><strong>Building a private blockchain using Hyperledger Fabric<\/strong><\/em> looked relatively simple when I tried building a couple of demos (similar to my <em><strong>Private Ethereum<\/strong> <\/em>experience)! Lately, I don&#8217;t have the luxury of my big old machines at Oracle so I used my own free-tier account on AWS (<em><strong>Thank you AWS<\/strong><\/em>). I was able to quickly put up an Ubuntu instance with 2Gb RAM and 8Gb of storage. For doing the BYFN (Building your first network) demo (<a href=\"https:\/\/hyperledger-fabric.readthedocs.io\/en\/latest\/samples.html\">from Hyperledger Fabric Samples<\/a>), I thought it should be good enough to run few docker VMs running Fabric peers representing two organizations using a Solo orderer (not using Kafka).<\/p>\n<p>Putting altogether (Here is my recipe):<\/p>\n<ol>\n<li>Ubuntu instance details:<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2569 aligncenter\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Ubuntu-hyp.png\" alt=\"\" width=\"900\" height=\"796\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Ubuntu-hyp.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Ubuntu-hyp-768x679.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Ubuntu-hyp-624x552.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>2. \u00a0Before you begin installing Hyperledger, make sure your Ubuntu instance is installed with <em><strong>&#8216;curl&#8217;, \u00a0&#8216;docker.io&#8217; and &#8216;docker-compose&#8217;<\/strong> <\/em>binaries. \u00a0To download and install the latest Hyperledger Docker VMs binaries refer to the following URL:<\/p>\n<pre><strong>https:\/\/hyperledger-fabric.readthedocs.io\/en\/latest\/samples.html#binaries<\/strong><\/pre>\n<p>I used the following URL:<\/p>\n<pre><strong>$ curl -sSL <a href=\"https:\/\/goo.gl\/Q3YRTi\" target=\"_blank\" rel=\"noopener\">https:\/\/goo.gl\/Q3YRTi<\/a>\u00a0| bash<\/strong><\/pre>\n<p>3. To verify install, try running &#8216;docker images&#8217; :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2570\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Docker-VM1.png\" alt=\"\" width=\"900\" height=\"365\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Docker-VM1.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Docker-VM1-768x311.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Docker-VM1-624x253.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>Also, make sure your current directory and the ~\/bin directory is added to $PATH environment variable. \u00a0For example, you would add. <em>#export PATH=\/home\/ubuntu\/hyperledger\/bin:$PATH<\/em><\/p>\n<p>4.\u00a0Now <strong><em>download the Hyperledger Fabric samples from Github<\/em><\/strong>, by running the following commands:<\/p>\n<pre><strong>$ git clone -b master https:\/\/github.com\/hyperledger\/fabric-samples.git <\/strong>\r\n<strong>$ cd fabric-samples<\/strong><\/pre>\n<p>5.\u00a0Now, move to the sub-directory &#8220;<strong><em>first-network<\/em><\/strong>&#8221; and run the following command:<\/p>\n<pre><strong>$ cd fabric-samples\/first-network<\/strong>\r\n<strong>$ .\/byfn -m generate<\/strong><\/pre>\n<p>You should be seeing the following output, which will generate the Certificates for the peers, creates the Orderer genesis block, creates a single channel (mychannel) and the anchor peers representing two organization (Org1 and Org 2).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2572\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/BYFN2.png\" alt=\"\" width=\"900\" height=\"582\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/BYFN2.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/BYFN2-768x497.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/BYFN2-624x404.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<ol start=\"6\">\n<li>Now, bring up your &#8220;<strong><em>first-network<\/em><\/strong>&#8221; and run the following commands:<\/li>\n<\/ol>\n<pre><strong>$ .\/byfn.sh -m up<\/strong><\/pre>\n<p>You should see the following output (I truncated them into multiple screenshots for ease of understanding of what is going on under the hood).<\/p>\n<p>a) Creating the Orgs, Solo Orderer, Peers and the channel (mychannel)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2581\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up1.png\" alt=\"\" width=\"900\" height=\"840\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up1.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up1-768x717.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up1-624x582.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>b) Adding Peers to the Channel<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2583\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up2.png\" alt=\"\" width=\"900\" height=\"951\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up2.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up2-768x812.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up2-624x659.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>c) Identifying the Anchor peers for each org<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2586\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up3.png\" alt=\"\" width=\"900\" height=\"632\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up3.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up3-768x539.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up3-624x438.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>d) Installation and Instantiation of Chaincode on the peers<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2589\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up4.png\" alt=\"\" width=\"900\" height=\"583\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up4.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up4-768x497.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up4-624x404.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>e) Querying chaincode and Invoking transactions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2590\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up5.png\" alt=\"\" width=\"900\" height=\"356\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up5.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up5-768x304.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up5-624x247.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2591\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up6.png\" alt=\"\" width=\"900\" height=\"706\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up6.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up6-768x602.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/Up6-624x489.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>7. \u00a0To shutdown your &#8220;<strong><em>first-network<\/em><\/strong>&#8221; and to delete all\u00a0the artifacts, including stopping the\u00a0<span tabindex=\"0\" role=\"link\" data-index=\"59\" data-start=\"382640\">docker VMs, <\/span><span tabindex=\"0\" role=\"link\" data-index=\"60\" data-start=\"388780\">\u00a0deleting the chaincode images from the docker Registry removing the crypto material (certs) of the peers. By\u00a0<\/span>running the following command:<\/p>\n<pre><strong>$ .\/byfn.sh -m down<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2594\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/down1.png\" alt=\"\" width=\"900\" height=\"766\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/down1.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/down1-768x654.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/down1-624x531.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>To summarize, we executed the &#8220;First Network&#8221; script, beginning with generating the certificate artifacts for the organization, created the default channel that connects the orderer with the peers, \u00a0created orderer genesis block and then brought up the private blockchain network using the Solo orderer that makes use of two organizations joining peers from both organization to a channel, deploying, and instantiating the chaincode, and execute query and invoke transactions against the chaincode.<\/p>\n<p>This exercise only helps to understand the Hyperledge Fabric components and the simple steps to show how we can quickly spin up and bring down a Hyperledger Fabric network using sample chaincode (<strong>chaincode_example02)<\/strong>. \u00a0You should able to modify the scripts and tweak to run other samples (like fabcar under fabric-samples directory).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It was quite easy ! Building a private blockchain using Hyperledger Fabric looked relatively simple when I tried building a couple of demos (similar to my Private Ethereum experience)! Lately, I don&#8217;t have the luxury of my big old machines at Oracle so I used my own free-tier account on AWS (Thank you AWS). I was able to quickly put&#8230; <a href=\"https:\/\/websecuritypatterns.com\/blogs\/2017\/12\/01\/exploring-hyperledger-fabric-v1-building-first-network-byfn\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,82,89,1],"tags":[25,83,102,101],"class_list":["post-2439","post","type-post","status-publish","format-standard","hentry","category-blockchain","category-hyperledger","category-permissioned-blockchain","category-uncategorized","tag-blockchain","tag-hyperledger","tag-hyperledger-fabric","tag-private-blockchain"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/comments?post=2439"}],"version-history":[{"count":26,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2439\/revisions"}],"predecessor-version":[{"id":2600,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2439\/revisions\/2600"}],"wp:attachment":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/media?parent=2439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/categories?post=2439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/tags?post=2439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}