{"id":2604,"date":"2017-12-15T05:46:24","date_gmt":"2017-12-15T05:46:24","guid":{"rendered":"http:\/\/websecuritypatterns.com\/blogs\/?p=2604"},"modified":"2018-01-08T06:04:25","modified_gmt":"2018-01-08T06:04:25","slug":"exploring-hyperledger-fabric-v1-supply-chain-demo-tuna-fish-shipments","status":"publish","type":"post","link":"https:\/\/websecuritypatterns.com\/blogs\/2017\/12\/15\/exploring-hyperledger-fabric-v1-supply-chain-demo-tuna-fish-shipments\/","title":{"rendered":"Exploring Hyperledger Fabric v1 &#8211; Supply chain demo (Tuna fish shipments)!"},"content":{"rendered":"<p>Let&#8217;s begin with some fundamentals! Adopting Blockchain helps to establish a &#8220;System of Proof&#8221;, where we can verify the complete historical record of transactions right from the\u00a0genesis\u00a0of the blockchain &#8211; which is immutable, unbreakable meaning that it cannot be changed, moved, or deleted. The blockchain integrity is protected by Cryptographic hashing, key signature, and timestamping mechanisms.\u00a0\u00a0Every change scheduled and addressed on the blockchain is only appended as a new block to the blockchain in order.<\/p>\n<p>In a supply chain scenario, blockchain brings assurance of integrity while maintaining transparency throughout the process. Linux Foundation has recently introduced a short online course on Hyperledger which is available for free. To showcase this demo, I used the Hyperledger Fabric v1 supply chain example (establish legal Tuna fish shipments) provided. The demo presents how we can transparently manage and regulate tuna fish shipments right from the source and till reaching the end customer while having able to validate the legal source throughout the process and avoid illegal and unrecorded sources. This example uses three actors in the supply chain (Fisherman, Restaurant\/Consumer, and Regulator) and we should able to keep track of the record using the distributed ledger to record all shipments right from the legal source of fishing<span tabindex=\"0\" role=\"link\" data-index=\"9\" data-start=\"58020\">\u00a0from fisherman and till the restaurant where it ends up.\u00a0Regulators can query\u00a0the ledger to verify, and view details of all entries in real-time. Using Hyperledger establishes permissioned private blockchain, where only registered and approved personnel can join the blockchain network using MSPs. <\/span><\/p>\n<p>Let&#8217;s explore the supply chain scenario using Hyperledger Fabric v1 framework components in terms of its role and relevance on the network. The core components are as follows:<\/p>\n<ul>\n<li><em><strong>Shared Permissioned Ledger<\/strong><\/em> contains the current state of all records right from the beginning of the network and the series of transaction invocations. As ledger is an append-only system of records and serves as a single source of all transactions and it is made available to all peers on the network.<\/li>\n<li>All <em><strong>Peers<\/strong><\/em> commit blocks and maintain a copy of the ledger. Two types of peers: <strong>Endorsers<\/strong> and <em><strong>Committer<\/strong><\/em> peers.\u00a0<em><strong>Endorsers<\/strong>\u00a0<\/em>simulate and endorse transactions.\u00a0<em><strong>Committers<\/strong>\u00a0<\/em>verify endorsements and validate transaction results.<\/li>\n<li><em><strong>Channels<\/strong><\/em> establish\u00a0transaction visibility to all the members of the network. \u00a0Each channel maintains independent chain of transaction blocks containing only transactions specific to that channel.<\/li>\n<li><em><em><strong>Chaincode\u00a0<\/strong><\/em><\/em><span style=\"font-size: 1rem;\">\u00a0encapsulates the asset definitions and the business logic (or transactions) for creating and modifying (CRUD) which performs transaction invocations on those assets<\/span><\/li>\n<li><em><strong>Orderer<\/strong><\/em>\u00a0accepts endorsed transactions, orders them into a block, and delivers the blocks to the committing peers.<\/li>\n<li><em><strong>MSP<\/strong><\/em>\u00a0manage user IDs, and authenticate all the participants in the network.<\/li>\n<\/ul>\n<p><span style=\"font-size: 1rem;\">The demo application made available is written using Hyperledger Node.js SDK.<\/span><\/p>\n<p>Try it yourself:<\/p>\n<ol>\n<li>\u00a0Have your Ubuntu instance (atleast\u00a08Gb memory and 16Gb storage) up and running. Make sure you installed the following:\n<ul>\n<li>Docker.io and Docker Compose (docker.io and docker-compose)<\/li>\n<\/ul>\n<\/li>\n<li>Download and install the latest Hyperledger Docker VMs binaries &#8211; refer to the following URL:<\/li>\n<\/ol>\n<pre><strong>https:\/\/hyperledger-fabric.readthedocs.io\/en\/latest\/samples.html#binaries<\/strong><\/pre>\n<p>I used the following URL (please note this changes upon new builds so make sure to download from the latest URL obtained from the link above:<\/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. \u00a0Verify install by running &#8216;<em><strong>$docker images&#8217; <\/strong>(refer output, should look like this)<\/em><\/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>4. Download the Linux Foundation (Hyperledger Fabric v1 Education sample repository) and then change the directory to &#8216;<em>tuna-app<\/em>&#8216;.<\/p>\n<pre><strong>$ git clone https:\/\/github.com\/hyperledger\/education.git<\/strong>\r\n<strong>$ cd education\/LFS171x\/fabric-material\/tuna-app<\/strong><\/pre>\n<p>5. Start the Hyperledger Fabric network using the following command:<\/p>\n<pre><strong>$ .\/startFabric.sh<\/strong><\/pre>\n<p>A typical output would look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2616\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafsh1.png\" alt=\"\" width=\"900\" height=\"622\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafsh1.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafsh1-768x531.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafsh1-624x431.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>6.\u00a0As the application is written using Node.js SDK, it is critical to Node.js binaries installed and available for use. The application also has dependencies to Go SDK. \u00a0So let&#8217;s install beginning with Go language and Node.js binaries.<\/p>\n<pre><strong> $\u00a0apt install golang-go<\/strong>\r\n \r\n <strong>$ go version<\/strong>\r\n \r\n <strong>$\u00a0sudo bash -c \"cat &gt;\/etc\/apt\/sources.list.d\/nodesource.list\" &lt;&lt;EOL<\/strong>\r\n <strong>&gt; \u00a0deb https:\/\/deb.nodesource.com\/node_6.x xenial main<\/strong>\r\n <strong>&gt; \u00a0deb-src https:\/\/deb.nodesource.com\/node_6.x xenial main<\/strong>\r\n <strong>&gt; \u00a0EOL<\/strong>\r\n \r\n <strong>$ curl -s https:\/\/deb.nodesource.com\/gpgkey\/nodesource.gpg.key | sudo apt-key add -<\/strong>\r\n \r\n <strong>$ apt update<\/strong>\r\n \r\n <strong>$ apt install nodejs<\/strong>\r\n \r\n <strong>$ apt install npm<\/strong>\r\n \r\n <strong>$ node --version &amp;&amp; npm --version<\/strong>\r\n \r\n <strong>$ npm install<\/strong>\r\n \r\n <strong>$ npm rebuild<\/strong><\/pre>\n<p>Discard warnings, not errors! If you encounter errors you may want to start from the beginning.<\/p>\n<ol start=\"7\">\n<li>Finally, register the <strong>Admin<\/strong> and <strong>User<\/strong> components of our network, and then start the client application using the following commands:<\/li>\n<\/ol>\n<pre><strong>$ node registerAdmin.js<\/strong><\/pre>\n<p>You should be seeing similar output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2619\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_register.png\" alt=\"\" width=\"991\" height=\"54\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_register.png 899w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_register-768x42.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_register-624x34.png 624w\" sizes=\"auto, (max-width: 991px) 100vw, 991px\" \/><\/p>\n<pre><strong>$ node registerUser.js<\/strong><\/pre>\n<p>You should see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2620\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_user.png\" alt=\"\" width=\"488\" height=\"62\" \/><\/p>\n<p>8. Now, start the server (server.js) and then try accessing client at the servehost_address:8000. \u00a0Make sure port 8000 is accessible from the host. The<span tabindex=\"0\" role=\"link\" data-index=\"4\" data-start=\"31440\">\u00a0user can interact with the Web application that enables users to query and update a ledger. Under the hood, the<\/span><span tabindex=\"0\" role=\"link\" data-index=\"13\" data-start=\"87600\">\u00a0application using the SDK sends\u00a0the endorsed proposal (automatically) to the Solo ordering service where the order is packaged into a block then broadcasted to all the peers on the network.<\/span><\/p>\n<pre><strong>$ <\/strong>nohup<strong> node server.js &amp;<\/strong><\/pre>\n<p>Try accessing the Web application client using the browser (http:\/\/IPaddress:8000\/:<\/p>\n<p><span tabindex=\"0\" role=\"link\" data-index=\"13\" data-start=\"87600\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2635\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo1.png\" alt=\"\" width=\"900\" height=\"753\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo1.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo1-768x643.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo1-624x522.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/span><\/p>\n<p>2) Try &#8220;Query&#8221; All or &#8220;Query a Specific Tuna Catch&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2638\" src=\"http:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo2.png\" alt=\"\" width=\"900\" height=\"670\" srcset=\"https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo2.png 900w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo2-768x572.png 768w, https:\/\/websecuritypatterns.com\/blogs\/wp-content\/uploads\/2018\/01\/tunafish_demo2-624x465.png 624w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>You should able to <em><strong>&#8220;Create a Tuna Record&#8221;<\/strong><\/em> and also <em>&#8220;<strong>Change Tuna Holder&#8221;<\/strong><\/em> and so on.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>THAT&#8217;S ALL FOLKS!<\/strong><\/span><\/p>\n<p>Further References:<\/p>\n<p>https:\/\/hyperledger-fabric.readthedocs.io\/en\/release\/<\/p>\n<p>https:\/\/courses.edx.org\/courses\/course-v1:LinuxFoundationX+LFS171x+3T2017\/course\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s begin with some fundamentals! Adopting Blockchain helps to establish a &#8220;System of Proof&#8221;, where we can verify the complete historical record of transactions right from the\u00a0genesis\u00a0of the blockchain &#8211; which is immutable, unbreakable meaning that it cannot be changed, moved, or deleted. The blockchain integrity is protected by Cryptographic hashing, key signature, and timestamping mechanisms.\u00a0\u00a0Every change scheduled and addressed&#8230; <a href=\"https:\/\/websecuritypatterns.com\/blogs\/2017\/12\/15\/exploring-hyperledger-fabric-v1-supply-chain-demo-tuna-fish-shipments\/\">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":[83,102,104,101],"class_list":["post-2604","post","type-post","status-publish","format-standard","hentry","category-blockchain","category-hyperledger","category-permissioned-blockchain","category-uncategorized","tag-hyperledger","tag-hyperledger-fabric","tag-permssioned-blockchain","tag-private-blockchain"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2604","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=2604"}],"version-history":[{"count":49,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2604\/revisions"}],"predecessor-version":[{"id":2659,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/2604\/revisions\/2659"}],"wp:attachment":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/media?parent=2604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/categories?post=2604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/tags?post=2604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}