<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhinav Garg on Medium]]></title>
        <description><![CDATA[Stories by Abhinav Garg on Medium]]></description>
        <link>https://medium.com/@abhinav.garg_90821?source=rss-2b2e8cdc0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*X6Ogl01m9OlreKNQ.</url>
            <title>Stories by Abhinav Garg on Medium</title>
            <link>https://medium.com/@abhinav.garg_90821?source=rss-2b2e8cdc0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:03:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhinav.garg_90821/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hyperledger — Chapter 10| Blockchain Application on Hyperledger Fabric]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-10-blockchain-application-on-hyperledger-fabric-6e40de190512?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e40de190512</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 07:18:24 GMT</pubDate>
            <atom:updated>2018-07-31T07:18:24.601Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the final chapter of this ten part series in which we will put everything together. Right from setting up the peer network and use the Node.js SDK to develop the tuna fish application which tracks a tuna’s story from its capture till a chef cooks it.</p><p>In this blockchain application, the blockchain will store the state of the system, in addition to the immutable record of transactions that created that state. A client application will be used to send transactions to the blockchain. The smart contracts (Chaincode) will encode some (if not all) of the business logic.</p><h4>What will we learn in this chapter?</h4><ul><li>Write your first application</li><li>Start with a test Hyperledger Fabric network</li><li>Learn the parameters of the sample smart contract</li><li>Develop the application to query and update ledger records</li></ul><p><strong>Recap:</strong></p><p>Distributed ledger technology generally consists of three basic components:</p><ul><li>A <strong>data model</strong> that captures the current state of the ledger ( a time-stamped series of transactions cryptographically secured)</li><li>A <strong>language of transactions</strong> that changes the ledger state [Smart Contracts / Chain code]</li><li>A <strong>protocol</strong> used to build consensus among participants around which transactions will be accepted, and in what order, by the ledger.</li></ul><p>We are using Hyperledger Fabric, <a href="https://medium.com/swlh/hyperledger-chapter-2-hyperledger-frameworks-modules-cabf50e12105">one of the 5 frameworks</a> available within the Hyperledger universe to explore a way to bring some transparency to the Tuna Fish supply chain. Read more about the problem structure <a href="https://medium.com/swlh/hyperledger-chapter-5-tuna-fishing-supplychain-context-f593b03e2cf0">here</a>, incase you are lost.</p><p><strong>Tuna Fish Application — High Level Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*q_6n7MZVa1Ul-D646hD8EQ.png" /></figure><p><strong>Tuna Fish Application — Transaction Flow within Hyperledger Fabric</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*f7UGD-zzjPn56zCpiRxBsA.gif" /></figure><h4>How Applications Interact with the Network</h4><p>Applications use APIs to run smart contracts. In Hyperledger Fabric, these smart contracts are called <strong>chaincode</strong>. These contracts are hosted on the network, and identified by name and version. APIs are accessible with a software development kit, or SDK. Currently, Hyperledger Fabric has three options for developers: Node.js SDK, Java SDK, and CLI.</p><h4>Fabric Node.js SDK</h4><p>In this exercise, we will be using the Node.js SDK (<a href="https://fabric-sdk-node.github.io/">https://fabric-sdk-node.github.io/</a>) to interact with the network, and, therefore, the ledger. The Hyperledger Fabric Client SDK makes it easy to use APIs to interact with a Hyperledger Fabric blockchain. This section will help you write your first application, starting with a test Hyperledger Fabric network, then learning the parameters of the sample smart contract, and lastly, developing the application to query and update ledger records.</p><p>For additional information, visit the Hyperledger Fabric Node SDK documentation: <a href="https://fabric-sdk-node.github.io/tutorial-app-dev-env-setup.html">https://fabric-sdk-node.github.io/tutorial-app-dev-env-setup.html</a>.</p><h4>Fun Part : BlockChain Application</h4><p>Be sure that you have the technical dependencies sorted out before you try to run this blockchain application.</p><h4>Step 1: Clone the repo</h4><pre>git clone <a href="https://github.com/hyperledger/education.git">https://github.com/hyperledger/education.git</a></pre><pre>cd education/LFS171x/fabric-material/tuna-app</pre><p>Make sure you have Docker running on your machine before you run the next command. If you do not have Docker installed, return to Chapter 4, <em>Technical Requirements</em>.</p><p>Also, make sure that you have completed the <em>Installing Hyperledger Fabric</em> section in this chapter before moving on to this application section, as you will likely experience errors.</p><p>First, remove any pre-existing containers, as it may conflict with commands in this tutorial:</p><pre>docker rm -f $(docker ps -aq)</pre><p>Let’s explore the folder structure here for a bit:</p><p>Once you executed the git clone it would have created this folder structure within your system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*c83VNmAj94qk5P_3SNv1ng.png" /></figure><p>Now open the fabric-material in your favorite text editor. (I’m using Sublime)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EckypnCzYc6pA1WVrL78Ug.png" /></figure><h4>Step 2: Start Fabric Network</h4><p>Next, let’s start the Hyperledger Fabric network with the following command:</p><pre>./startFabric.sh</pre><p>Let’s break down what’s happening when you run this command in your terminal.</p><ol><li>Existing Network Artifacts are removed from Docker and just one organisation with a peer &amp; couch DB is created along with an orderer.</li></ol><p>As you can see in the code, the startfabric.Sh internally calls start.sh within basic-network folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*YMBMXf9Slf8SbVxGVaw7uQ.png" /></figure><p>Now, if you traverse to start.sh , you can see how the docker container is cleared and re-populated. Also, a channel is created and a peer is added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*loGHOX6uBJbJkqy4A_a2Ew.png" /></figure><p>So you see this in your terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*1bv18HUiYy_Sf8kIXs46jA.png" /></figure><p>&amp; the channel creation along with few dummy records are created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Pg6O-PWAqQQ_HHMe4XqMg.png" /></figure><h4>Step 3: RegisterAdmin</h4><p>Cool. Now that the network is up. Let’s registerAdmin.</p><pre>node registerAdmin.js</pre><p>You should get this output, basically an Admin is created with the required keys. YOu can open up registerAdmin.js to see the code. Basically, withe the Fabric CA client we check if an Admin is already registered, if not it enrolls with the CA client. Basic parameters such as enrollmentID, Secret are set. Then the user is created with FabricClient with membership ID, along with the public private key pair.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*oDCBjZTurXMh5mX9fYCYnA.png" /><figcaption>registerAdmin.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnZL4vjhbYPhoq5RP8Y7jg.png" /><figcaption>output on terminal after running “node regiserAdmin.js”</figcaption></figure><p><strong>Step 4: RegisterUser</strong></p><p>Now that the network and admin are set, let’s register an User.</p><pre>mosess-mbp:tuna-app Sam$ <strong><em>node registerUser.js</em></strong></pre><pre>Store path:/Users/Sam/.hfc-key-store</pre><pre>Successfully loaded admin from persistence</pre><pre>Failed to register: Error: fabric-ca request register failed with errors [[{&quot;code&quot;:20,&quot;message&quot;:&quot;Authorization failure&quot;}]]</pre><pre>Authorization failures may be caused by having admin credentials from a previous CA instance.</pre><pre>Try again after deleting the contents of the store directory /Users/Sam/.hfc-key-store</pre><p>Delete the key directory &amp; Register Admin again.</p><pre>mosess-mbp:tuna-app Sam$ <strong><em>rm ~/.hfc-key-store/*</em></strong></pre><pre>mosess-mbp:tuna-app Sam$ node registerUser.js</pre><pre>Store path:/Users/Sam/.hfc-key-store</pre><pre>Failed to register: Error: Failed to get admin.... run registerAdmin.js</pre><pre>mosess-mbp:tuna-app Sam$ <strong><em>node registerAdmin.js</em></strong></pre><pre>Store path:/Users/Sam/.hfc-key-store</pre><pre>Successfully enrolled admin user &quot;admin&quot;</pre><pre>Assigned the admin user to the fabric client ::{&quot;name&quot;:&quot;admin&quot;,&quot;mspid&quot;:&quot;Org1MSP&quot;,&quot;roles&quot;:null,&quot;affiliation&quot;:&quot;&quot;,&quot;enrollmentSecret&quot;:&quot;&quot;,&quot;enrollment&quot;:{&quot;signingIdentity&quot;:&quot;174630b086dc3d165c65b139fc2bee92bfe6f0749bf93672b28b823784349ebf&quot;,&quot;identity&quot;:{&quot;certificate&quot;:&quot;-----BEGIN CERTIFICATE-----\nMIICAjCCAaigAwIBAgIUVA8TjKrtWvmuTkghyW5fGylwvvIwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwNTEzMTcxMzAwWhcNMTkwNTEzMTcx\nODAwWjAhMQ8wDQYDVQQLEwZjbGllbnQxDjAMBgNVBAMTBWFkbWluMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAEnfxwodId3gRqKsdwxv6zVzuVeRakg4u9MvPf3eGE\nnkGrS9YZ0MW+QVUnbfeS1xS0jpSUUGGqWT9TKMgnunKe6aNsMGowDgYDVR0PAQH/\nBAQDAgeAMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFPPzep8ev4FHiQBTbZu3ud7Z\nG8u3MCsGA1UdIwQkMCKAIEI5qg3NdtruuLoM2nAYUdFFBNMarRst3dusalc2Xkl8\nMAoGCCqGSM49BAMCA0gAMEUCIQDcbAn2549BIfGjCE4vmyF38LY0F5JhFbuGcQC9\nFAK9awIgWV1GODLV/OhPnR42yNa+fdwkry/8IgWU27PcFN15oFQ=\n-----END CERTIFICATE-----\n&quot;}}}</pre><p>let’s try and register user again.</p><pre>mosess-mbp:tuna-app Sam$ <strong>node registerUser.js</strong></pre><pre>Store path:/Users/Sam/.hfc-key-store</pre><pre>Successfully loaded admin from persistence</pre><pre>Successfully registered user1 - secret:oDSXCnPBMrUC</pre><pre>Successfully enrolled member user &quot;user1&quot;</pre><pre>User1 was successfully registered and enrolled and is ready to intreact with the fabric network</pre><p>If you open up <strong>registerUser.js</strong>, you can see that we register user with the CA server and then enroll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*sbTH1rpNqUd1sfvXfHyoxg.png" /></figure><h4>Step 5: Run the server</h4><p>This step is the final step to run the application. For that we gotta setup the nodejs server, call the needed packages, instantiate the app and listen on a particular port.</p><pre>mosess-mbp:tuna-app Sam$ <strong><em>node server.js</em></strong></pre><pre>Live on port: 8000</pre><p>voila..our applcation is live on port 8000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IaCePrcwPHRYUmfLcTSGFw.png" /><figcaption>Query All, Query Tuna</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Sds_Q_ucJ0glM20ROxYnkg.png" /><figcaption>create tuna record, change tuna holder</figcaption></figure><p>The UI has a button under 4 headings.</p><p>Query All Tuna Catches — triggers — <strong><em>queryAllTuna.js</em></strong></p><p>Query Specific Tuna — triggers — <strong><em>queryTuna.js</em></strong></p><p>Create Tuna Record — triggers — <strong><em>recordTuna.js</em></strong></p><p>Change Tuna Holder — triggers — <strong><em>changeTunaHolder.js</em></strong></p><p>All these js files are inturn defined within the chaincode <strong><em>tuna-chaincode.go</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WmxH18VcXYJ29SisqUxdw.png" /></figure><h4>Output</h4><p>Let’s play around with the UI</p><ol><li><strong>Query All Tuna</strong> &lt;All the data we used in the chaincode to initLedger is pulled and shown here&gt;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKRw0oCw2NIwA5RschGXGw.png" /></figure><p>2. Query Tuna (I am retrieving record 6 below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T4nLXzSpRNGDKMLDrHKMTw.png" /></figure><p>3. Log a Tuna Catch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*-3rgsA3Fw4eeimiP3O64gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXcn9qzBABuH3W6vDpn62w.png" /><figcaption>creating a new tuna record &amp; see it recorded in the ledger</figcaption></figure><p>4. Change the Owner of Tuna Fish</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*4eyXrh9YBLrvuFDLfNnIhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLBNX5caZIY_yxhiLfHUdQ.png" /><figcaption>The record 13’s owner changes from Thanos to Avengers here</figcaption></figure><p>If you have made it till here, reward yourself!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fs9R7FEH0zcdSE%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fs9R7FEH0zcdSE%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fs9R7FEH0zcdSE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8dc0fdc09d60077b6d2a3d724fe47f2/href">https://medium.com/media/a8dc0fdc09d60077b6d2a3d724fe47f2/href</a></iframe><p>This brings the 10 part series of Hyperledger fabric to and end.</p><h4>Recap:</h4><pre>A)<strong> Blockchain</strong> is a specific form or <strong>subset of distributed ledger technologies, </strong>which constructs a chronological chain of blocks, hence the name ‘block-chain&#39;.</pre><pre>B)<strong> Hyperledger</strong> is the umbrella open source project that the Linux Foundation has created and hosted since 2015.</pre><pre>C) We explored <strong>Hyperledger Fabric</strong> deeper by creating a permissioned blockchain for the tuna fish scenario.</pre><pre>D) <strong>Hyperledger Fabric Elements</strong></pre><pre><strong>Channels</strong> are data partitioning mechanisms that allow transaction visibility for stakeholders only. Each channel is an independent chain of transaction blocks containing only transactions for that particular channel.</pre><pre><strong>Chaincode /(Smart Contract)</strong> | It encapsulates both the asset definitions and the business logic (or transactions) for modifying those assets. Transaction invocations result in changes to the ledger.</pre><pre><strong>Ledger</strong> contains the current world state of the network and a chain of transaction invocations. A shared, permissioned ledger is an append-only system of records and serves as a single source of truth.</pre><pre><strong>Network</strong> is the collection of data processing peers that form a blockchain network. The network is responsible for maintaining a consistently replicated ledger.</pre><pre><strong>Ordering Service</strong> is a collection of nodes that orders transactions into a block.</pre><pre><strong>World State</strong> reflects the current data about all the assets in the network. This data is stored in a database for efficient access. Current supported databases are LevelDB and CouchDB.</pre><pre><strong>Membership Service Provider (MSP)</strong> manages identity and permissioned access for clients and peers.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e40de190512" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 9| Chaincode in Tunafish Scenario using Hyperledger Fabric]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-9-chaincode-in-tunafish-scenario-using-hyperledger-fabric-1fdd2a87cb96?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fdd2a87cb96</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 07:15:43 GMT</pubDate>
            <atom:updated>2018-07-31T07:15:43.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Context</h3><p>we will walk through a simple chaincode that creates assets on a ledger, based on our demonstrated scenario of creating records for tuna fish.</p><p>Sometimes, code snippets can get lost in translation, especially if the context doesn’t make much sense. In hopes of avoiding this, we have adjusted our example chaincode to address our demonstration scenario. The chaincode we will be examining in this section will record a tuna catch by storing it to the ledger, as well as allow for queries and updates to tuna catch records.</p><h4>Stakeholders</h4><ul><li><strong>Sarah</strong> is the fisherman who sustainably and legally catches tuna.</li><li><strong>Regulators</strong> verify that the tuna has been legally and sustainably caught.</li><li><strong>Miriam</strong> is a restaurant owner who will serve as the end user, in this situation.</li><li><strong>Carl</strong> is another restaurant owner fisherman Sarah can sell tuna to.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/0*1SZ3MPzINqzfg1p6.png" /></figure><p><strong>Big Picture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/0*EG1YQtXr1nGCzIFJ.png" /></figure><p><strong>Transaction Flow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*0HyKsOag1W68z5aJOahcBA.gif" /></figure><h4>Defining Asset Attributes</h4><p>Here are the four example attributes of tuna fish that we will be recording on the ledger:</p><ul><li>Vessel (string)</li><li>Location (string)</li><li>Date and Time (datetime)</li><li>Holder (string)</li></ul><p>We create a Tuna Structure that has four properties. Structure tags are used by the <strong>encoding/json</strong> library.</p><pre>type Tuna struct {<br>Vessel string ‘json:”vessel”’<br>Datetime string ‘json:”datetime”’<br>Location string ‘json:”location”’<br>Holder string ‘json:”holder”’<br>}</pre><h4>Chain Code: Invoke Method</h4><p>As described earlier, the <strong>Invoke</strong> method is the one which gets called when a transaction is proposed by a client application. Within this method, we have three different types of transactions — <em>recordTuna</em>, <em>queryTuna</em>, and <em>changeTunaHolder</em>, which we will look at a little later.</p><p>As a reminder, Sarah, the fisherman, will invoke the <em>recordTuna</em> when she catches each tuna.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*U6RQ-BEGc8KabOAY.png" /></figure><p><em>changeTunaHolder</em> can be invoked by Miriam, the restaurateur, when she confirms receiving and passing on a particular tuna fish as it passes through the supply chain. <em>queryTuna</em> can be invoked by Miriam, the restaurateur, to view the state of a particular tuna.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/0*OHJBvHlTr4ZeySPx.png" /></figure><p>Regulators will invoke <em>queryTuna</em> and <em>queryAllTuna</em> based on their need to verify and check for sustainability of the supply chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*gt3DGXyDQYV0Nh00.png" /></figure><p>We’ll be getting into the different tuna chaincode methods in the following sections. But here is the <strong>Invoke</strong> method. As you can see, this method will look at the first parameter to determine which function should be called, and invoke the appropriate tuna chaincode method.</p><pre>func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {</pre><pre>// Retrieve the requested Smart Contract function and arguments</pre><pre>function, args := APIstub.GetFunctionAndParameters()</pre><pre>// Route to the appropriate handler function to interact with the ledger appropriately</pre><pre>if function == &quot;queryTuna&quot; {</pre><pre>return s.queryTuna(APIstub, args)</pre><pre>} else if function == &quot;initLedger&quot; {</pre><pre>return s.initLedger(APIstub)</pre><pre>} else if function == &quot;recordTuna&quot; {</pre><pre>return s.recordTuna(APIstub, args)</pre><pre>} else if function == &quot;queryAllTuna&quot; {</pre><pre>return s.queryAllTuna(APIstub)</pre><pre>} else if function == &quot;changeTunaHolder&quot; {</pre><pre>return s.changeTunaHolder(APIstub, args)</pre><pre>}</pre><pre>return shim.Error(&quot;Invalid Smart Contract function name.&quot;)</pre><pre>}</pre><h4>Chaincode Methods — queryTuna</h4><p>The queryTuna method would be used by a fisherman, regulator, or restaurateur to view the record of one particular tuna. It takes one argument — the key for the tuna in question.</p><pre>func (s *SmartContract) queryTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {</pre><pre>if len(args) != 1 {</pre><pre>return shim.Error(&quot;Incorrect number of arguments. Expecting 1&quot;)</pre><pre>}</pre><pre>tunaAsBytes, _ := APIstub.GetState(args[0])</pre><pre>if tunaAsBytes == nil {</pre><pre>return shim.Error(“Could not locate tuna”)</pre><pre>}</pre><pre>return shim.Success(tunaAsBytes)</pre><pre>}</pre><h4>Chaincode Methods — initLedger</h4><p>The <em>initLedger</em> method will add test data to our network.</p><pre>func (s *SmartContract) initLedger(APIstub shim.ChaincodeStubInterface) sc.Response {</pre><pre>tuna := []Tuna{</pre><pre>Tuna{Vessel: &quot;923F&quot;, Location: &quot;67.0006, -70.5476&quot;, Timestamp: &quot;1504054225&quot;, Holder: &quot;Miriam&quot;},</pre><pre>Tuna{Vessel: &quot;M83T&quot;, Location: &quot;91.2395, -49.4594&quot;, Timestamp: &quot;1504057825&quot;, Holder: &quot;Dave&quot;},</pre><pre>Tuna{Vessel: &quot;T012&quot;, Location: &quot;58.0148, 59.01391&quot;, Timestamp: &quot;1493517025&quot;, Holder: &quot;Igor&quot;},</pre><pre>Tuna{Vessel: &quot;P490&quot;, Location: &quot;-45.0945, 0.7949&quot;, Timestamp: &quot;1496105425&quot;, Holder: &quot;Amalea&quot;},</pre><pre>Tuna{Vessel: &quot;S439&quot;, Location: &quot;-107.6043, 19.5003&quot;, Timestamp: &quot;1493512301&quot;, Holder: &quot;Rafa&quot;},</pre><pre>Tuna{Vessel: &quot;J205&quot;, Location: &quot;-155.2304, -15.8723&quot;, Timestamp: &quot;1494117101&quot;, Holder: &quot;Shen&quot;},</pre><pre>Tuna{Vessel: &quot;S22L&quot;, Location: &quot;103.8842, 22.1277&quot;, Timestamp: &quot;1496104301&quot;, Holder: &quot;Leila&quot;},</pre><pre>Tuna{Vessel: &quot;EI89&quot;, Location: &quot;-132.3207, -34.0983&quot;, Timestamp: &quot;1485066691&quot;, Holder: &quot;Yuan&quot;},</pre><pre>Tuna{Vessel: &quot;129R&quot;, Location: &quot;153.0054, 12.6429&quot;, Timestamp: &quot;1485153091&quot;, Holder: &quot;Carlo&quot;},</pre><pre>Tuna{Vessel: &quot;49W4&quot;, Location: &quot;51.9435, 8.2735&quot;, Timestamp: &quot;1487745091&quot;, Holder: &quot;Fatima&quot;},</pre><pre>}</pre><pre>i := 0</pre><pre>for i &lt; len(tuna) {</pre><pre>fmt.Println(&quot;i is &quot;, i)</pre><pre>tunaAsBytes, _ := json.Marshal(tuna[i])</pre><pre>APIstub.PutState(strconv.Itoa(i+1), tunaAsBytes)</pre><pre>fmt.Println(&quot;Added&quot;, tuna[i])</pre><pre>i = i + 1</pre><pre>}</pre><pre>return shim.Success(nil)</pre><pre>}</pre><h4>Chaincode Methods — recordTuna</h4><p>The <em>recordTuna</em> method is the method a fisherman like Sarah would use to record each of her tuna catches. This method takes in five arguments (attributes to be saved in the ledger).</p><pre>func (s *SmartContract) recordTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {</pre><pre>if len(args) != 5 {</pre><pre>return shim.Error(&quot;Incorrect number of arguments. Expecting 5&quot;)</pre><pre>}</pre><pre>var tuna = Tuna{ Vessel: args[1], Location: args[2], Timestamp: args[3], Holder: args[4]}</pre><pre>tunaAsBytes, _ := json.Marshal(tuna)</pre><pre>err := APIstub.PutState(args[0], tunaAsBytes)</pre><pre>if err != nil {</pre><pre>return shim.Error(fmt.Sprintf(&quot;Failed to record tuna catch: %s&quot;, args[0]))</pre><pre>}</pre><pre>return shim.Success(nil)</pre><pre>}</pre><h4>Chaincode Methods — queryAllTuna</h4><p>The <em>queryAllTuna</em> method allows for assessing all the records; in this case, all the Tuna records added to the ledger. This method does not take any arguments. It will return a JSON string containing the results.</p><pre>func (s *SmartContract) queryAllTuna(APIstub shim.ChaincodeStubInterface) sc.Response {</pre><pre>startKey := &quot;0&quot;</pre><pre>endKey := &quot;999&quot;</pre><pre>resultsIterator, err := APIstub.GetStateByRange(startKey, endKey)</pre><pre>if err != nil {</pre><pre>return shim.Error(err.Error())</pre><pre>}</pre><pre>defer resultsIterator.Close()</pre><pre>// buffer is a JSON array containing QueryResults</pre><pre>var buffer bytes.Buffer</pre><pre>buffer.WriteString(&quot;[&quot;)</pre><pre>bArrayMemberAlreadyWritten := false</pre><pre>for resultsIterator.HasNext() {</pre><pre>queryResponse, err := resultsIterator.Next()</pre><pre>if err != nil {</pre><pre>return shim.Error(err.Error())</pre><pre>}</pre><pre>// Add a comma before array members, suppress it for the first array member</pre><pre>if bArrayMemberAlreadyWritten == true {</pre><pre>buffer.WriteString(&quot;,&quot;)</pre><pre>}</pre><pre>buffer.WriteString(&quot;{\&quot;Key\&quot;:&quot;)</pre><pre>buffer.WriteString(&quot;\&quot;&quot;)</pre><pre>buffer.WriteString(queryResponse.Key)</pre><pre>buffer.WriteString(&quot;\&quot;&quot;)</pre><pre>buffer.WriteString(&quot;, \&quot;Record\&quot;:&quot;)</pre><pre>// Record is a JSON object, so we write as-is</pre><pre>buffer.WriteString(string(queryResponse.Value))</pre><pre>buffer.WriteString(&quot;}&quot;)</pre><pre>bArrayMemberAlreadyWritten = true</pre><pre>}</pre><pre>buffer.WriteString(&quot;]&quot;)</pre><pre>fmt.Printf(&quot;- queryAllTuna:\n%s\n&quot;, buffer.String())</pre><pre>return shim.Success(buffer.Bytes())</pre><pre>}</pre><h4>Chaincode Methods — changeTunaHolder</h4><p>As the tuna fish is passed to different parties in the supply chain, the data in the world state can be updated with who has possession. The <em>changeTunaHolder</em> method takes in 2 arguments, <strong>tuna id</strong> and <strong>new holder name</strong>.</p><pre>func (s *SmartContract) changeTunaHolder(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {</pre><pre>if len(args) != 2 {</pre><pre>return shim.Error(&quot;Incorrect number of arguments. Expecting 2&quot;)</pre><pre>}</pre><pre>tunaAsBytes, _ := APIstub.GetState(args[0])</pre><pre>if tunaAsBytes != nil {</pre><pre>return shim.Error(&quot;Could not locate tuna&quot;)</pre><pre>}</pre><pre>tuna := Tuna{}</pre><pre>json.Unmarshal(tunaAsBytes, &amp;tuna)</pre><pre><em>// Normally check that the specified argument is a valid holder of tuna but here we are skipping this check for this example.</em></pre><pre>tuna.Holder = args[1]</pre><pre>tunaAsBytes, _ = json.Marshal(tuna)</pre><pre>err := APIstub.PutState(args[0], tunaAsBytes)</pre><pre>if err != nil {</pre><pre>return shim.Error(fmt.Sprintf(&quot;Failed to change tuna holder: %s&quot;, args[0]))</pre><pre>}</pre><pre>return shim.Success(nil)</pre><pre>}</pre><p>so what did we learn?</p><p>How chaincode is constructed and written, especially when applied to a simple example.</p><p><a href="https://github.com/hyperledger/education/blob/master/LFS171x/fabric-material/chaincode/tuna-app/tuna-chaincode.go">https://github.com/hyperledger/education/blob/master/LFS171x/fabric-material/chaincode/tuna-app/tuna-chaincode.go</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fdd2a87cb96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 8 | What is Hyperledger Fabric Chaincode ?]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-8-what-is-hyperledger-fabric-chaincode-f0c23002467e?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0c23002467e</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:10:59 GMT</pubDate>
            <atom:updated>2018-07-30T06:10:59.876Z</atom:updated>
            <content:encoded><![CDATA[<p>So in the previous chapter we had installed Hyperledger Fabric and we started and stopped a test network on which peers and chain codes run. Now let’s dive deep into the chaincode portion of Hyperledger Fabric as that’s where business logic lies.</p><p>In this post,</p><p>We will go through a Sample chaincode and understand the following</p><ul><li>Dependencies</li><li>Struct</li><li>Init Method</li><li>Invoke Method (Get &amp; Set)</li><li>Main Function</li></ul><h4>Recap — Chaincode</h4><p>Chaincode is a program (smart contract) that is written to read and update the ledger state. All the business logic is inside the chaincode.</p><p><a href="http://hyperledger-fabric.readthedocs.io/en/release-1.1/chaincode4ade.html">Right now,</a> it can be written in Go / Node.JS.</p><p>In Hyperledger Fabric, <strong>chaincode</strong> is the ‘smart contract’ that runs on the peers and creates transactions. More broadly, it enables users to create transactions in the Hyperledger Fabric network’s shared ledger and update the world state of the assets.</p><p>Chaincode is programmable code, written in Go, and instantiated on a channel. Developers use chaincode to develop business contracts, asset definitions, and collectively-manage decentralized applications. The chaincode manages the ledger state through transactions invoked by applications. Assets are created and updated by a specific chaincode, and cannot be accessed by another chaincode.</p><p><strong>Applications interact with the blockchain ledger through the chaincode. </strong>Therefore, the chaincode needs to be installed on every peer that will endorse a transaction and instantiated on the channel.</p><p><strong>Remember the Transaction Flow?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*0HyKsOag1W68z5aJOahcBA.gif" /></figure><pre><strong>Quick High Level Overview:</strong></pre><pre>Peer can be part of one or more channel</pre><pre>Every channel has a separate ledger</pre><pre>Every Channel has one or more chain codes</pre><pre>Every Chain code has a different endorsement policy</pre><pre>Chaincode must be part of a channel. As the ledger is part of a channel. One channel can have as many chaincodes as possible.</pre><pre>Chaincode must be installed in each peer that is part of the channel and instantiated.</pre><pre>When a Chaincode gets instantiated a policy (endorsing) has to be defined. [consensus: before a transaction can be recorded in the ledger only if a rule is met]</pre><p>There are two ways to develop smart contracts with Hyperledger Fabric:</p><ul><li>Code individual contracts into standalone instances of chaincode</li><li>Use chaincode to create decentralized applications that manage the lifecycle of one or multiple types of business contracts, and let the end users instantiate instances of contracts within these applications. [More Efficient]</li></ul><h4>Chaincode Key APIs</h4><p>An important interface that you can use when writing your chaincode is defined by Hyperledger Fabric —</p><ul><li><a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#Chaincode"><em>ChaincodeStub</em></a></li><li><a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub"><em>ChaincodeStubInterface</em></a></li></ul><p>The <em>ChaincodeStub</em> provides functions that allow you to interact with the underlying ledger to query, update, and delete assets.</p><p>The key APIs for chaincode include:</p><ul><li><strong>func (stub *</strong><a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub"><strong>ChaincodeStub</strong></a><strong>) GetState(key </strong><a href="https://godoc.org/builtin#string"><strong>string</strong></a><strong>) ([]</strong><a href="https://godoc.org/builtin#byte"><strong>byte</strong></a><strong>, </strong><a href="https://godoc.org/builtin#error"><strong>error</strong></a><strong>)</strong><br>Returns the value of the specified <em>key</em> from the ledger. Note that <strong>GetState</strong> doesn’t read data from the Write set, which has not been committed to the ledger. In other words, <strong>GetState</strong> doesn’t consider data modified by <strong>PutState</strong> that has not been committed. If the key does not exist in the state database, <strong>(nil, nil)</strong> is returned.</li><li><strong>func (stub *</strong><a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub"><strong>ChaincodeStub</strong></a><strong>) PutState(key </strong><a href="https://godoc.org/builtin#string"><strong>string</strong></a><strong>, value []</strong><a href="https://godoc.org/builtin#byte"><strong>byte</strong></a><strong>) </strong><a href="https://godoc.org/builtin#error"><strong>error</strong></a><br>Puts the specified <em>key</em> and <em>value</em> into the transaction’s Write set as a data-write proposal. <strong>PutState</strong> doesn’t affect the ledger until the transaction is validated and successfully committed.</li><li><strong>func (stub *</strong><a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub"><strong>ChaincodeStub</strong></a><strong>) DelState(key </strong><a href="https://godoc.org/builtin#string"><strong>string</strong></a><strong>) </strong><a href="https://godoc.org/builtin#error"><strong>error</strong></a><br>Records the specified <em>key</em> to be deleted in the Write set of the transaction proposal. The <em>key</em> and its <em>value</em> will be deleted from the ledger when the transaction is validated and successfully committed.</li></ul><h4>Overview of a Chaincode Program</h4><p>When creating a chaincode, there are two methods that you will need to implement:</p><ul><li><strong>Init</strong><br>Called when a chaincode receives an <strong><em>instantiate</em></strong> or <strong><em>upgrade</em></strong> transaction. This is where you will initialize any application state.</li><li><strong>Invoke</strong><br>Called when the <strong><em>invoke</em></strong> transaction is received to process any transaction proposals.</li></ul><p>As a developer, one must create both an <strong>Init</strong> and an <strong>Invoke</strong> method within your chaincode. The chaincode must be installed using the <strong>peer chaincode install</strong> command, and instantiated using the <strong>peer chaincode instantiate</strong> command before the chaincode can be invoked. Then, transactions can be created using the <strong>peer chaincode invoke</strong> or <strong>peer chaincode query</strong> commands.</p><h4>Sample Chaincode Decomposed — Dependencies</h4><p>Let’s now walk through a sample chaincode written in Go, piece by piece:</p><pre>package main<br>import (<br>“fmt”<br>“github.com/hyperledger/fabric/core/chaincode/shim”<br>“github.com/hyperledger/fabric/protos/peer”<br>)</pre><p>The <strong>import</strong> statement lists a few dependencies that you will need for your chaincode to build successfully.</p><ul><li><strong>fmt</strong> — contains <strong>Println</strong> for debugging/logging</li><li><strong>github.com/hyperledger/fabric/core/chaincode/shim</strong> — contains the definition for the chaincode interface and the chaincode stub, which you will need to interact with the ledger, as we described in the <em>Chaincode Key APIs</em> section</li><li><strong>github.com/hyperledger/fabric/protos/peer</strong> — contains the peer protobuf package.</li></ul><h4>Sample Chaincode Decomposed — Struct</h4><pre>type SampleChaincode struct {</pre><pre>}</pre><p>This might not look like much, but this is the statement that begins the definition of an object/class in Go.</p><p><strong>SampleChaincode</strong> implements a simple chaincode to manage an asset.</p><h4>Sample Chaincode Decomposed — Init Method</h4><pre>func (t *SampleChaincode) Init(stub shim.ChainCodeStubInterface) peer.Response {</pre><pre>// Get the args from the transaction proposal</pre><pre>args := stub.GetStringArgs()</pre><pre>if len(args) != 2 {</pre><pre>return shim.Error(&quot;Incorrect arguments. Expecting a key and a value&quot;)</pre><pre>}</pre><pre>// We store the key and the value on the ledger</pre><pre>err := stub.PutState(args[0], []byte(args[1]))</pre><pre>if err != nil {</pre><pre>return shim.Error(fmt.Sprintf(&quot;Failed to create asset: %s&quot;, args[0]))</pre><pre>}</pre><pre>return shim.Success(nil)</pre><pre>}</pre><p>The <strong>Init</strong> implementation accepts two parameters as inputs, and proposes to write a key/value pair to the ledger by using the <strong>stub.PutState </strong>function.</p><p><strong>stub.GetStringArgs</strong> retrieves and checks the validity of arguments which we expect to be a key/value pair. Therefore, we check to ensure that there are two arguments specified. If not, we return an error from the <strong>Init</strong> method, to indicate that something went wrong.</p><p><strong>stub.PutState </strong>function<strong> </strong>is used to<strong> </strong>store the initial state in the ledger. In order to accomplish this, we call the function, specifying the first argument as the key, and the second argument as the value for that key. If no errors are returned, we will return success from the <strong>Init</strong> method.</p><h4>Sample Chaincode Decomposed — Invoke Method</h4><p>Now, we’ll explore the <strong>Invoke</strong> method, which gets called when a transaction is proposed by a client application. In our sample, we will either get the value for a given asset, or propose to update the value for a specific asset.</p><pre>func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response {</pre><pre>// Extract the function and args from the transaction proposal</pre><pre>fn, args := stub.GetFunctionAndParameters()</pre><pre>var result string</pre><pre>var err error</pre><pre>if fn == &quot;set&quot; {</pre><pre>result, err = set(stub, args)</pre><pre>} else { // assume &#39;get&#39; even if fn is nil</pre><pre>result, err = get(stub, args)</pre><pre>}</pre><pre>if err != nil { //Failed to get function and/or arguments from transaction proposal</pre><pre>return shim.Error(err.Error())</pre><pre>}</pre><pre>// Return the result as success payload</pre><pre>return shim.Success([]byte(result))</pre><pre>}</pre><p>There are two basic actions a client can invoke: <em>get</em> and <em>set</em>.</p><ul><li>The <em>get</em> method will be used to query and return the value of an existing asset.</li><li>The <em>set</em> method will be used to create a new asset or update the value of an existing asset.</li></ul><p>To start, we’ll call <strong>GetFunctionandParameters</strong> to isolate the function name and parameter variables. Each transaction is either a <em>set</em> or a <em>get</em>. Let’s first look at how the <em>set</em> method is implemented:</p><pre>func set(stub shim.ChaincodeStubInterface, args []string) (string, error) {</pre><pre>if len(args) != 2 {</pre><pre>return &quot;&quot;, fmt.Errorf(&quot;Incorrect arguments. Expecting a key and a value&quot;)</pre><pre>}</pre><pre>err := stub.PutState(args[0], []byte(args[1]))</pre><pre>if err != nil {</pre><pre>return &quot;&quot;, fmt.Errorf(&quot;Failed to set asset: %s&quot;, args[0])</pre><pre>}</pre><pre>return args[1], nil</pre><pre>}</pre><blockquote>The set method will create or modify an asset identified by a key with the specified value. The set method will modify the world state to include the key/value pair specified. If the key exists, it will override the value with the new one, using the PutState method; otherwise, a new asset will be created with the specified value.</blockquote><p>Next, let’s look at how the <em>get</em> method is implemented:</p><pre>func get(stub shim.ChaincodeStubInterface, args []string) (string, error) {</pre><pre>if len(args) != 1 {</pre><pre>return &quot;&quot;, fmt.Errorf(&quot;Incorrect arguments. Expecting a key&quot;)</pre><pre>}</pre><pre>value, err := stub.GetState(args[0])</pre><pre>if err != nil {</pre><pre>return &quot;&quot;, fmt.Errorf(&quot;Failed to get asset: %s with error: %s&quot;, args[0], err)</pre><pre>}</pre><pre>if value == nil {</pre><pre>return &quot;&quot;, fmt.Errorf(&quot;Asset not found: %s&quot;, args[0])</pre><pre>}</pre><pre>return string(value), nil</pre><pre>}</pre><blockquote>The <em>get</em> method will attempt to retrieve the value for the specified key. If the application does not pass in a single key, an error will be returned; otherwise, the <strong>GetState</strong> method will be used to query the world state for the specified key. If the key has not yet been added to the ledger (and world state), then an error will be returned; otherwise, the value that was set for the specified key is returned from the method.</blockquote><h4>Sample Chaincode Decomposed — Main Function</h4><p>The last piece of code in this sample is the main function, which will call the Start function. The main function starts the chaincode in the container during instantiation.</p><pre>func main() {</pre><pre>err := shim.Start(new(SampleChaincode))</pre><pre>if err != nil {</pre><pre>fmt.Println(“Could not start SampleChaincode”)</pre><pre>} else {</pre><pre>fmt.Println(“SampleChaincode successfully started”)</pre><pre>}</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*IdLllmWzXqYWQ5Cg45hfVg.png" /></figure><pre><strong>Recap:</strong></pre><pre>Peer can be part of one or more channel</pre><pre>Every channel has a separate ledger</pre><pre>Every Channel has one or more chain codes getting &amp; setting values in the ledger</pre><pre>Every Chain code has a different endorsement policy</pre><pre>Chaincode must be installed in each peer that is part of the channel and instantiated.</pre><pre>When a Chaincode gets instantiated a policy (endorsing) has to be defined. [consensus: before a transaction can be recorded in the ledger only if a rule is met]</pre><p>I know, it’s a lot to take in but we’ll use the Tuna Fish Application’s chain code in the next chapter and then it should be easy to digest.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0c23002467e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 7 | Installing Hyperledger Fabric]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-7-installing-hyperledger-fabric-3915739a9d49?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3915739a9d49</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:09:56 GMT</pubDate>
            <atom:updated>2018-07-30T06:09:56.769Z</atom:updated>
            <content:encoded><![CDATA[<p>The first step in implementing the solution to fix the tuna fish supplychain is setting up the technical environment and this is the first step to that. Installing Hyperledger Fabric and making sure the network is up and running.</p><h4>Installing Hyperledger Fabric</h4><p>If you are using Docker Toolbox on Windows 7 or macOS, you will need to use a location under C:\Users (Windows 7) or /Users (macOS) when installing and running the samples.</p><p>If you are using Docker for Mac, you will need to use a location under /Users, /Volumes, /private, or /tmp. To use a different location, please consult the Docker documentation for <a href="https://docs.docker.com/docker-for-mac/#file-sharing">file sharing</a>.</p><p>Determine a location on your machine where you want to place the Hyperledger Fabric samples applications repository and open that in a terminal window. Then, execute the following commands:</p><pre>git clone <strong>-</strong>b master <a href="https://github.com/hyperledger/fabric-samples.git">https:<strong>//</strong>github<strong>.</strong>com<strong>/</strong>hyperledger<strong>/</strong>fabric<strong>-</strong>samples<strong>.</strong>git</a></pre><pre>cd fabric<strong>-</strong>samples</pre><pre>git checkout {TAG}</pre><p>Note</p><p>To ensure the samples are compatible with the version of Fabric binaries you download below, checkout the samples {TAG} that matches your Fabric version, for example, v1.1.0. To see a list of all fabric-samples tags, use command “git tag”.</p><h3>Download Platform-specific Binaries</h3><p>Next, we will install the Hyperledger Fabric platform-specific binaries. This process was designed to complement the Hyperledger Fabric Samples above, but can be used independently. If you are not installing the samples above, then simply create and enter a directory into which to extract the contents of the platform-specific binaries.</p><p>Please execute the following command from within the directory into which you will extract the platform-specific binaries:</p><pre>curl <strong>-</strong>sSL <a href="https://goo.gl/6wtTN5">https:<strong>//</strong>goo<strong>.</strong>gl<strong>/</strong>6wtTN5</a> <strong>|</strong> bash <strong>-</strong>s 1.1<strong>.</strong>0</pre><pre>## comment: &lt;full URL&gt;<br><a href="https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh">https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh</a></pre><p>The command above downloads and executes a bash script that will download and extract all of the platform-specific binaries you will need to set up your network and place them into the cloned repo you created above. It retrieves four platform-specific binaries:</p><ul><li>cryptogen,</li><li>configtxgen,</li><li>configtxlator,</li><li>peer</li><li>orderer and</li><li>fabric-ca-client</li></ul><p>and places them in the bin sub-directory of the current working directory.</p><p>You may want to add that to your PATH environment variable so that these can be picked up without fully qualifying the path to each binary. e.g.:</p><pre>export PATH=&lt;path to download location&gt;/bin:$PATH</pre><p>Test:</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*G_ICekALh2Rz7fLNGveZBA.png" /><figcaption>Expected Output</figcaption></figure><p><strong>Note </strong>the tags for each of the repositories above boxed in red. If the Docker images are not already tagged with the <strong>latest</strong> tag, perform the following command for each of the Docker images:</p><pre>docker tag hyperledger/fabric-tools:x86_64–1.0.2 hyperledger/fabric-tools:latest</pre><p>Swap out the blue portion with the tags you see in your list of repositories. Also, swap out the red portion with the name of the Docker image you are switching the tag for (e.g.: <strong>fabric-tools</strong>, <strong>fabric-ccenv</strong>, <strong>fabric-orderer</strong>, etc.). Repeat this step for all Docker images you see in the list.</p><p>In the screenshot above, the Docker images are already tagged. If this is the case for you, you do not need to do this extra step.</p><h4>Starting a Test Hyperledger Fabric Network</h4><p>Now that we have successfully installed Hyperledger Fabric, we can walk through setting up a simple network that has two members. To refer back to our demonstrated scenario, the network includes asset management of each tuna verified, transferred, and purchased between Sarah, the fisherman, and Miriam, the restaurateur. We’ll create a simple two member network consisting of two organizations (effectively, Sarah and Miriam), each maintaining two peers and an ordering service.</p><p>We will use Docker images to bootstrap our first Hyperledger Fabric network. It will also launch a container to run a scripted execution that will join peers to a channel, deploy, and instantiate the chaincode, and execute transactions against the chaincode.</p><pre>cd first-network</pre><pre>./byfn.sh -m generate</pre><p>A brief description will appear, along with a <strong>Y/N</strong> command line prompt. Respond with a <strong>Y &lt;Enter&gt;</strong> to continue.</p><p>This step generates all of the certificates and keys for all our various network entities, including the genesis block used to bootstrap the ordering service and a collection of configuration transactions required to create a channel.</p><p>Next, you can start the network with the following command:</p><pre>./byfn.sh -m up</pre><p>Another command line will appear, reply with <strong>Y &lt;Enter&gt;</strong> to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*zTvsvfAArUqJKm1lPPzv2w.png" /></figure><p><strong>Troubleshooting Note:</strong> <br>If you have difficulties with the two previous commands and you suspect that your Docker images may be at fault, you can start back from scratch, which will delete and untag the Docker images.</p><pre>docker rmi -f $(docker images -q)</pre><p>Once you run this command, return to the <em>Installing Hyperledger Fabric Docker Images and Binaries</em> page, at the beginning of this section.</p><p>Finally, let’s test bringing down this network.</p><p>Within the same terminal, do <strong>Control+C</strong> to exit the current execution.</p><p>Then, run the following command:</p><pre>./byfn.sh -m down</pre><p>Another command line will appear, reply with <strong>Y &lt;Enter&gt;</strong> to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*AWZvFi89NSrs1PAvI5IMuA.png" /></figure><p>This command will kill your containers, remove the crypto material and four artifacts, and delete the chaincode images from your Docker Registry.</p><p>That’s all for now folks. We have installed Hyperledger Fabric and we started and stopped a test network on which peers and chain codes run. In the next chapter we shall dive deeper into the chain code part of the Hyperledger Fabric.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3915739a9d49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 6 | Hyperledger Fabric Components — Technical Context]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-6-hyperledger-fabric-components-technical-context-15d2901a5c41?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/15d2901a5c41</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:09:05 GMT</pubDate>
            <atom:updated>2018-07-30T06:09:05.195Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that we understand the real world context of the tuna fish supplychain `scenario, let’s get to know Hyperledger <strong>Fabric</strong> Components a little deeper in this post so that we can structure the same problem (tuna fish supplychain) technically.</p><p>By the end of this post, you will know</p><ul><li>Roles within Hyperledger Fabric</li><li>Consensus</li><li>Transaction Flow</li><li>Channels</li><li>State Database</li><li>Chaincode / Smart Contracts</li><li>MSP [Membership Service Provider]</li></ul><h4>Roles within a Hyperledger Fabric Network</h4><ol><li><strong>Clients</strong> <br>Clients are applications that act on behalf of a person to propose transactions on the network.</li><li><strong>Peers</strong><br>Peers maintain the state of the network and a copy of the ledger. There are two different types of peers: <strong>endorsing</strong> and <strong>committing</strong> peers. However, there is an overlap between endorsing and committing peers, in that endorsing peers are a special kind of committing peers. All peers commit blocks to the distributed ledger.<br>- <strong><em>Endorsers</em></strong><em> </em>simulate and endorse transactions<br>- <strong><em>Committers</em></strong><em> </em>verify endorsements and validate transaction results, prior to committing transactions to the blockchain.</li><li><strong>Ordering Service </strong><br>The ordering service accepts endorsed transactions, orders them into a block, and delivers the blocks to the committing peers.</li></ol><h4>Consensus</h4><p>In a distributed ledger system, <strong>consensus</strong> is the process of reaching agreement on the next set of transactions to be added to the ledger. In Hyperledger Fabric, consensus is made up of three distinct steps:</p><ul><li>Transaction endorsement</li><li>Ordering</li><li>Validation and commitment.</li></ul><h4>Transaction Flow (Step 1)</h4><p>Within a Hyperledger Fabric network, transactions start out with client applications sending transaction proposals, or, in other words, proposing a transaction to endorsing peers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*hqGVfLMXDaYFBVE0.png" /></figure><p><strong>Client applications</strong> are commonly referred to as <strong>applications</strong> or <strong>clients</strong>, and allow people to communicate with the blockchain network. Application developers can leverage the Hyperledger Fabric network through the application SDK.</p><h4>Transaction Flow (Step 2)</h4><p>Each endorsing peer simulates the proposed transaction, without updating the ledger. The endorsing peers will capture the set of <strong>R</strong>ead and <strong>W</strong>ritten data, called <strong>RW Sets</strong>. These RW sets capture what was read from the current world state while simulating the transaction, as well as what would have been written to the world state had the transaction been executed. These RW sets are then signed by the endorsing peer, and returned to the client application to be used in future steps of the transaction flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/0*ALetLn_NrA-k-xiz.png" /></figure><p>Endorsing peers must hold smart contracts in order to simulate the transaction proposals.</p><h4>Transaction Endorsement</h4><p>A transaction endorsement is a <strong>signed response to the results of the simulated transaction</strong>. The method of transaction endorsements depends on the endorsement policy which is specified when the chaincode is deployed. An example of an endorsement policy would be <strong>“the majority of the endorsing peers must endorse the transaction”</strong>. Since an endorsement policy is specified for a specific chaincode, different channels can have different endorsement policies.</p><h4>Transaction Flow (Step 3)</h4><p>The application then submits the endorsed transaction and the RW sets to the ordering service. Ordering happens across the network, in parallel with endorsed transactions and RW sets submitted by other applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*VehGAv6uHU_5DlYZYP-85w.png" /></figure><h4>Transaction Flow (Step 4)</h4><p>The ordering service takes the endorsed transactions and RW sets, orders this information into a block, and delivers the block to all committing peers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*9154z8gH5WD0SYjj.png" /></figure><p>The <strong>ordering service</strong>, which is made up of a cluster of orderers, does not process transactions, smart contracts, or maintains the shared ledger. The ordering service accepts the endorsed transactions and specifies the order in which those transactions will be committed to the ledger. The Fabric v1.0 architecture has been designed such that the specific implementation of ‘ordering’ (Solo, Kafka, BFT) becomes a pluggable component. The default ordering service for Hyperledger Fabric is Kafka.</p><h4>Ordering (Part 1)</h4><pre><em>Transactions within a timeframe are sorted into a block and are committed in sequential order.</em></pre><p>In a blockchain network, transactions have to be written to the shared ledger in a consistent order. The order of transactions has to be established to ensure that the updates to the world state are valid when they are committed to the network. Unlike the Bitcoin blockchain, where ordering occurs through the solving of a cryptographic puzzle, or <em>mining</em>, Hyperledger Fabric allows the organizations running the network to choose the ordering mechanism that best suits that network. This modularity and flexibility makes Hyperledger Fabric incredibly advantageous for enterprise applications.</p><h4>Ordering (Part 2)</h4><p>Hyperledger Fabric provides three ordering mechanisms: SOLO, Kafka, and Simplified Byzantine Fault Tolerance (SBFT)</p><ul><li><strong>SOLO</strong> is the Hyperledger Fabric ordering mechanism most typically used by developers experimenting with Hyperledger Fabric networks. SOLO involves a single ordering node.</li><li><strong>Kafka</strong> is the Hyperledger Fabric ordering mechanism that is recommended for production use. This ordering mechanism utilizes Apache Kafka, an open source stream processing platform that provides a unified, high-throughput, low-latency platform for handling real-time data feeds. In this case, the data consists of endorsed transactions and RW sets. The Kafka mechanism provides a crash fault-tolerant solution to ordering.</li><li><strong>SBFT</strong> stands for Simplified Byzantine Fault Tolerance. This ordering mechanism is both crash fault-tolerant and byzantine fault-tolerant, meaning that it can reach agreement even in the presence of malicious or faulty nodes. The Hyperledger Fabric community has not yet implemented this mechanism, but it is on their roadmap.</li></ul><h4>Transaction Flow (Step 5)</h4><p>The committing peer validates the transaction by checking to make sure that the RW sets still match the current world state. Specifically, that the Read data that existed when the endorsers simulated the transaction is identical to the current world state. When the committing peer validates the transaction, the transaction is written to the ledger, and the world state is updated with the Write data from the RW Set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/0*Lx2WIHMayEwE4Hp5.png" /></figure><p>If the transaction fails, that is, if the committing peer finds that the RW set does not match the current world state, the transaction ordered into a block will still be included in that block, but it will be marked as <strong>invalid</strong>, and the world state will not be updated.</p><p><strong>Committing peers are responsible for adding blocks of transactions to the shared ledger</strong> and updating the world state. They may hold smart contracts, but it is not a requirement.</p><h4>Transaction Flow (Step 6)</h4><p>Lastly, the committing peers <strong>asynchronously</strong> notify the client application of the success or failure of the transaction. Applications will be notified by each committing peer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*VY7cjTUh8d3IECm0.png" /></figure><h4>Identity Verification</h4><p>In addition to the multitude of endorsement, validity, and versioning checks that take place, there are also <strong>ongoing identity verifications</strong> happening during each step of the transaction flow.</p><p>Access control lists are implemented on the hierarchical layers of the network (from the ordering service down to channels), and payloads are repeatedly signed, verified, and authenticated as a transaction proposal passes through the different architectural components.</p><h4>Transaction Flow Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*0HyKsOag1W68z5aJOahcBA.gif" /></figure><p><strong>Channels:</strong></p><p>Channels allow organizations to utilize the same network, while maintaining separation between multiple blockchains. Only the members of the channel on which the transaction was performed can see the specifics of the transaction.</p><blockquote><strong>Channels partition the network in order to allow transaction visibility for stakeholders only</strong>.</blockquote><p>This mechanism works by delegating transactions to different ledgers. Only the members of the channel are involved in consensus, while other members of the network do not see the transactions on the channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/0*tAHOUfXYRPipyyB2.png" /></figure><p>The diagram above shows three distinct channels — blue, orange, and grey. Each channel has its own application, ledger, and peers.</p><p>Peers can belong to multiple networks or channels. Peers that do participate in multiple channels simulate and commit transactions to different ledgers. The ordering service is the same across any network or channel.</p><p>A few things to remember:</p><ul><li>The network setup allows for the creation of channels.</li><li>The same chaincode logic can be applied to multiple channels.</li><li>A given user can participate in multiple channels.</li></ul><h4>State Database</h4><p>The current state data represents the latest values for all assets in the ledger. Since the current state represents all the committed transactions on the channel, it is sometimes referred to as world state.</p><p>Chaincode invocations execute transactions against the current state data. To make these chaincode interactions extremely efficient, the latest key/value pairs for each asset are stored in a state database.</p><p>The state database is simply an indexed view into the <strong>chain’s committed transactions</strong>. It can therefore be regenerated from the chain at any time. The state database will automatically get recovered (or generated, if needed) upon peer startup, before new transactions are accepted. The default state database, <strong>LevelDB</strong>, can be replaced with <strong>CouchDB</strong>.</p><ul><li>LevelDB is the default key/value state database for Hyperledger Fabric, and simply stores key/value pairs.</li><li>CouchDB is an alternative to LevelDB. Unlike LevelDB, CouchDB stores <strong>JSON objects</strong>. CouchDB is unique in that it supports keyed, composite, key range, and full data-rich queries.</li></ul><p>Hyperledger Fabric’s LevelDB and CouchDB are very similar in their structure and function. Both LevelDB and CouchDB support core chaincode operations, such as getting and setting key assets, and querying based on these keys. With both, keys can be queried by range, and composite keys can be modeled to enable equivalence queries against multiple parameters. But, as a JSON document store, CouchDB additionally enables rich query against the chaincode data, when chaincode values (e.g. assets) are modeled as JSON data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*4C9OUve7ztb3md6s.png" /></figure><h4>Smart Contracts (Chain Code)</h4><p>As a reminder, smart contracts are computer programs that <strong>contain logic</strong> to execute transactions and modify the state of the assets stored within the ledger (world state).</p><p>Hyperledger Fabric smart contracts are called <strong>chaincode</strong> and are written in <strong>Go</strong>. The chaincode serves as the business logic for a Hyperledger Fabric network, in that the chaincode directs how you manipulate assets within the network.</p><h4>Membership Service Provider (MSP) | Identities</h4><p>The membership service provider, or MSP, is a component that defines the <strong>rules in which identities are validated, authenticated, and allowed access to a network</strong>.</p><p>The MSP manages user IDs and authenticates clients who want to join the network. This includes providing credentials for these clients to propose transactions.</p><p>The MSP makes use of a <em>Certificate Authority</em>, which is a pluggable interface that verifies and revokes user certificates upon confirmed identity. The default interface used for the MSP is the <strong>Fabric-CA API</strong>, however, organizations can implement an External Certificate Authority of their choice. This is another feature of Hyperledger Fabric that is modular.</p><p>Hyperledger Fabric supports many credential architectures, which allows for many types of External Certificate Authority interfaces to be used. As a result, a single Hyperledger Fabric network can be controlled by multiple MSPs, where each organization brings their favorite.</p><h4>What Does the MSP Do?</h4><p>To start, users are authenticated using a certificate authority. The certificate authority identifies the application, peer, endorser, and orderer identities, and verifies these credentials. A signature is generated through the use of a <em>Signing Algorithm</em> and a <em>Signature Verification Algorithm</em>.</p><p>Specifically, generating a signature starts with a <em>Signing Algorithm</em>, which utilizes the credentials of the entities associated with their respective identities, and outputs an endorsement. A signature is generated, which is a byte array that is bound to a specific identity.</p><p>Next, the <em>Signature Verification Algorithm</em> takes the identity, endorsement, and signature as inputs, and outputs ‘accept’ if the signature byte array corresponds with a valid signature for the inputted endorsement, or outputs ‘reject’ if not. If the output is ‘accept’, the user can see the transactions in the network and perform transactions with other actors in the network. If the output is ‘reject’, the user has not been properly authenticated, and is not able to submit transactions to the network, or view any previous transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*plB9OGZST49mnDE3.jpg" /></figure><h4>Fabric-Certificate Authority</h4><p>In general, <em>Certificate Authorities</em> manage enrollment certificates for a permissioned blockchain.</p><p><strong>Fabric-CA</strong> is the default certificate authority for Hyperledger Fabric, and handles the registration of user identities. The Fabric-CA certificate authority is in charge of issuing and revoking Enrollment Certificates (E-Certs).</p><p>The current implementation of Fabric-CA only issues E-Certs, which supply long term identity certificates. E-Certs, which are issued by the Enrollment Certificate Authority (E-CA), assign peers their identity and give them permission to join the network and submit transactions.</p><p><strong>Recap:</strong></p><p>So in this post, we understood the components of <strong><em>Hyperledger Fabric</em></strong> which will help us define the Tuna Fishing Supplychain problem from a technical stand point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d2901a5c41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 5 | Tuna Fishing Supplychain — Context]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-5-tuna-fishing-supplychain-context-553d4a0be5a?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/553d4a0be5a</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:07:59 GMT</pubDate>
            <atom:updated>2018-07-30T06:07:59.692Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that we understand the fundamentals of blockchain and the high level structure of Hyperledger let’s use this knowledge to tackle a real world scenario.</p><p><strong>Problem Context:</strong></p><p>With the Tuna 2020 Traceability Declaration in mind, our goal is to eliminate illegal, unreported, and unregulated fishing. We will use Hyperledger Fabric to bring transparency and clarity to a real-world example: <strong>the supply chain of tuna fishing.</strong></p><p>We will be describing how tuna fishing can be improved, starting from the source, fisherman Sarah, and the process by which her tuna ends up at Miriam’s restaurant. In between, we’ll have other parties involved, such as the regulator who verify the validity of the data and the sustainability of the tuna catches.</p><p>We will be using Hyperledger Fabric’s framework to keep track of each part of this process.</p><p>Two things to keep in mind:</p><ol><li>There are many actors within the network, and you will see how these actors interact, and how a transaction is conducted.</li><li>Private channels allow Sarah and Miriam to privately agree on the terms of their interaction, while still maintaining transparency, so other actors can corroborate and confirm their transaction.</li></ol><p>Using private channels, regulators and restaurateurs can confirm whether a particular shipment of tuna was sustainably and legally sourced, without needing to see the details of the entire journey.</p><h4>Stakeholders</h4><ul><li><strong>Sarah</strong> is the fisherman who sustainably and legally catches tuna.</li><li><strong>Regulators</strong> verify that the tuna has been legally and sustainably caught.</li><li><strong>Miriam</strong> is a restaurant owner who will serve as the end user, in this situation.</li><li><strong>Carl</strong> is another restaurant owner fisherman Sarah can sell tuna to.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/0*1SZ3MPzINqzfg1p6.png" /></figure><h4>Hyperledger Fabric Elements</h4><ol><li><strong>Channels</strong> are data partitioning mechanisms that allow transaction visibility for stakeholders only. Each channel is an independent chain of transaction blocks containing only transactions for that particular channel.</li><li><strong>Chaincode /</strong>(Smart Contract) | It encapsulates both the asset definitions and the business logic (or transactions) for modifying those assets. Transaction invocations result in changes to the ledger.</li><li><strong>Ledger</strong> contains the current world state of the network and a chain of transaction invocations. A shared, permissioned ledger is an append-only system of records and serves as a single source of truth.</li><li><strong>Network</strong> is the collection of data processing <strong>peers</strong> that form a blockchain network. The network is responsible for maintaining a consistently replicated ledger.</li><li><strong>Ordering Service</strong> is a collection of nodes that orders transactions into a block.</li><li><strong>World State </strong>reflects the current data about all the assets in the network. This data is stored in a database for efficient access. Current supported databases are LevelDB and CouchDB.</li><li><strong>Membership Service Provider</strong> (MSP) manages identity and permissioned access for clients and peers.</li></ol><h4>Fisherman | Sarah</h4><p>After each catch, Sarah records information about each individual tuna, including: a unique ID number, the location and time of the catch, its weight, the vessel type, and who caught the fish. For the sake of simplicity, we will stick with these six data attributes. However, in an actual application, many more details would be recorded, from toxicology, to other physical characteristics.</p><p>These details are saved in the world state as a key/value pair based on the specifications of a chaincode contract, allowing Sarah’s application to effectively create a transaction on the ledger. You can see the example below:</p><pre><strong>var tuna = { id: ‘0001’, holder: ‘Sarah’, location: { latitude: ‘41.40238’, longitude: ‘2.170328’}, when: ‘20170630123546’, weight: ‘58lbs’, vessel : ‘9548E’ }</strong></pre><h4>Restaurant Owner | Miriam | Buyer</h4><p>Miriam is a restaurant owner looking to source low cost, yet high quality tuna that have been responsibly caught. Whenever Miriam buys tuna, she is always uncertain whether she can trust that the tuna she is purchasing is legally and sustainably caught, given the prominence of illegal and unreported tuna fishing.</p><p>At the same time, as a legitimate and experienced fisherman, Sarah strives to make a living selling her tuna at a reasonable price. She would also like autonomy over who she sells to and at what price.</p><h4>Restaurant Owners | Miriam &amp; Cole | Sale</h4><p>Normally, Sarah sells her tuna to restaurateurs, such as Carl, for $80 per pound. However, Sarah agrees to give Miriam a special price of $50 per pound of tuna, rather than her usual rate. In a traditional public blockchain, once Sarah and Miriam have completed their transaction, the entire network is able to view the details of this agreement, especially the fact that Sarah gave Miriam a special price. As you can imagine, having other restaurateurs, such as Carl, aware of this deal is not economically advantageous for Sarah.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*qyt5uXNsRIeSGGhG.png" /></figure><p>To remedy this, Sarah wants the specifics of her deal to not be available to everyone on the network, but still have every actor in the network be able to view the details of the fish she is selling. Using Hyperledger Fabric’s feature of <strong>channels</strong>, Sarah can privately agree on the terms with Miriam, such that only the two of them can see them, without anyone else knowing the specifics.</p><p>Additionally, other fishermen, who are not part of Sarah and Miriam’s transaction, will not see this transaction on their ledger. This ensures that another fisherman cannot undercut the bid by having information about the prices that Sarah is charging different restaurateurs.</p><h4>Regulators | Contract Enforcers</h4><p>Regulators will also gain entry to this Hyperledger Fabric blockchain network to confirm, verify, and view details from the ledger. Their application will allow these actors to <strong>query the ledger</strong> and see the details of each of Sarah’s catches to confirm that she is legally catching her fish.</p><p>Regulators only need to have query access, and do not need to add entries to the ledger. With that being said, they may be able to adjust who can gain entry to the network and/or be able to remove fishermen from the network, if found to be partaking in illegal activities.</p><h4>Gaining Network Membership</h4><p>Hyperledger Fabric is a permissioned network, meaning that only participants who have been approved can gain entry to the network. To handle network membership and identity, <strong>membership service providers</strong> (MSP) manage user IDs, and authenticate all the participants in the network.</p><p>In our scenario, the regulator, the approved fishermen, and the approved restaurateurs should be the only ones allowed to join the network.</p><p>Our scenario has two separate chaincodes, which are run on three separate channels.</p><p><strong>Chaincodes</strong></p><ol><li>One for the price agreement between the fisherman and the restaurateur</li><li>One for the transfer of tuna.</li></ol><p><strong>Channels</strong></p><ol><li>One for the price agreement between Seller (Sarah) and Buyer (Miriam)</li><li>One for the price agreement between Seller (Sarah) and Buyer (Carl)</li><li>One for the transfer of tuna.</li></ol><p>Each member of this network knows about each other and their identity. The channels provide privacy and confidentiality of transactions.</p><h4>Summary of the Problem Architecture:</h4><p>Below is a summary of the tuna catch scenario presented in this section:</p><ol><li>Sarah catches a tuna and uses the supply chain application’s user interface to record all the details about the catch to the ledger. Before it reaches the ledger, the transaction is passed to the endorsing peers on the network, where it is then endorsed. The endorsed transaction is sent to the ordering service, to be ordered into a block. This block is then sent to the committing peers in the network, where it is committed after being validated. [Note: <strong>Endorsing Peers, Ordering Service, Committing Peers </strong>will be explained in the coming chapters]</li><li>As the tuna is passed along the supply chain, regulators may use their own application to <strong>query the ledger</strong> for details about specific catches (excluding price, since they do not have access to the price-related chaincode)</li><li>Sarah may enter into an agreement with a restaurateur Carl, and agree on a price of $80 per pound. They use the blue channel for the chaincode contract stipulating $80/lb. <strong>The blue channel’s ledger</strong> is updated with a block containing this transaction.</li><li>In a separate business agreement, Sarah and Miriam agree on a special price of $50 per pound. They use the red channel’s chaincode contract stipulating $50/lb. <strong>The red channel’s ledger</strong> is updated with a block containing this transaction.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/0*EG1YQtXr1nGCzIFJ.png" /></figure><p><strong>Recap:</strong></p><p>So in this post, we defined a real world problem that can be solved using Hyperledger Fabric.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=553d4a0be5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 4 | Technical Dependencies]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-4-technical-dependencies-e63ae2391a20?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e63ae2391a20</guid>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:07:10 GMT</pubDate>
            <atom:updated>2018-07-30T06:07:10.292Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ll discuss different prerequisites that need to be fulfilled to ensure that our system is prepared for the technical requirements of this series.</p><p>By the end of this post you would know how to</p><ul><li>Install cURL.</li><li>Install Node.js and npm package manager.</li><li>Install Go Language.</li><li>Install Docker and Docker Compose.</li></ul><h4>Install cURL</h4><p><strong>cURL</strong> is a tool to transfer data from or to a server, using one of the supported protocols. The name is a play on ‘Client for URLs’, originally with URL spelled in uppercase to make it obvious it deals with URLs. A command line tool for getting or sending files using URL syntax. Since <strong>curl</strong> uses libcurl, <strong>curl</strong> supports the same wide range of common Internet protocols that libcurl does.</p><p>Type the following command in your terminal and enter your password:</p><pre><strong>$ sudo apt install curl</strong></pre><p>To check, run the following command in your terminal/command line:</p><pre><strong>$ curl -V</strong></pre><p><strong>Note</strong>: The “V” is capitalized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*c1BUVukl3eaQkrddSM9png.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DKfxnzauM-qoGPGPo8rVDg.jpeg" /></figure><h3>Docker</h3><h4>what is Docker?</h4><p><strong>Docker</strong> is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.</p><p><strong>Docker Cloud</strong> is where developers and IT ops meet to build, ship and run any application, anywhere.</p><h4>How is Docker different from a Virtual Machine?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*_OrVf4AJBdnrsSgRnUmLDA.jpeg" /></figure><h4>Docker Installation guide</h4><p><a href="https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac">Install Docker Desktop on Mac</a></p><h4>Test your Docker Instllation</h4><pre>docker --version &amp;&amp; docker-compose --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*FApPx92jvg_phj6Z_4KlFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uOGeXcOZq80aJUHo5DI43w.png" /></figure><h3>Node.js &amp; npm</h3><h4>What is Node.js?</h4><ul><li>Node.js is an open source server environment</li><li>Node.js is free</li><li>Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)</li><li>Node.js uses JavaScript on the server</li></ul><h4>Why Node.js?</h4><p><strong>Node.js uses asynchronous programming!</strong></p><p>A common task for a web server can be to open a file on the server and return the content to the client.</p><p>Here is how PHP or ASP handles a file request:</p><ol><li>Sends the task to the computer’s file system.</li><li>Waits while the file system opens and reads the file.</li><li>Returns the content to the client.</li><li>Ready to handle the next request.</li></ol><p>Here is how Node.js handles a file request:</p><ol><li>Sends the task to the computer’s file system.</li><li>Ready to handle the next request.</li><li>When the file system has opened and read the file, the server returns the content to the client.</li></ol><p><strong>Node.js eliminates the waiting, and simply continues with the next request.</strong></p><p>Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient.</p><h4>What is npm?</h4><p>NPM is a package manager for Node.js packages, or modules if you like.</p><p><a href="https://www.npmjs.com/">www.npmjs.com</a> hosts thousands of free packages to download and use.</p><p>The NPM program is installed on your computer when you install Node.js</p><p>NPM is already ready to run on your computer!</p><h4>What is a Package?</h4><p>A package in Node.js contains all the files you need for a module.Modules are JavaScript libraries you can include in your project. npm opens up an entire world of JavaScript talent for you and your team. It’s the world’s largest software registry, with approximately 3 billion downloads per week. The registry contains over 600,000 <em>packages</em> (building blocks of code).</p><h4>Node.Js Installation</h4><p>Visit <a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a> for details about installing or updating <strong>Node.js</strong> and <strong>npm</strong> for MacOS [or your OS]</p><h4>Verify the Installation</h4><p>Verify as well as the versions of both <strong>Node.js</strong> and npm,<strong> </strong>and make sure the <strong>Node.js</strong> version you are installing is greater than v6.9 (do not use v7), and the <strong>npm</strong> version is greater than 3.x:</p><pre><strong>node — version &amp;&amp; npm — version</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*E2iLJL3Mxdazdd_bm7QVow.png" /></figure><h3>GO</h3><h4>what is Go?</h4><p><strong>Go</strong> is an open source programming <strong>language</strong> that makes it easy to build simple, reliable, and efficient software. Go is created at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson.</p><p>Visit <a href="https://golang.org/dl/">https://golang.org/dl/</a> and make note of the latest stable release (<strong>v1.8 or later</strong>):</p><p><strong>$ cd ~</strong></p><p><strong>$ sudo curl -O </strong><a href="https://storage.googleapis.com/golang/go1.9.2.darwin-amd64.pkg"><strong>https://storage.googleapis.com/golang/go1.9.2.darwin-amd64.pkg</strong></a></p><p><strong>Note</strong>: Switch out the black portion of the URL with the correct filename.</p><p>Open the downloaded file to run the installation package:</p><p><strong>$ open go1.9.2.darwin-amd64.pkg</strong></p><p>After completing the installation, <strong>go</strong> will have been installed at <strong>/usr/local/bin/go</strong>. You can check by running:</p><pre>which go</pre><pre>go version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*WmRprB6xHvkbYiR0uuUg_g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e63ae2391a20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 3| When to use the Blockchain Technology]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-3-when-to-use-the-blockchain-technology-f9c9ae97669a?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9c9ae97669a</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:05:47 GMT</pubDate>
            <atom:updated>2018-07-30T06:05:47.926Z</atom:updated>
            <content:encoded><![CDATA[<p>In the 90s adding a “.com” to your company name had a positive impact on your share prices. 74% to be precise in the first 10 days of announcement*. Something similar is happening in the decentralised world. This post will help you take a step back and ask yourself certain questions to overcome the confirmation bias of believing that blockchain is the solution to everything!</p><p>By the end of this post you should be able to</p><ul><li>Discover the factors to look at when evaluating if blockchain technology is right for a particular project.</li><li>Decide when to use and when not to use blockchain technology.</li></ul><h4>Recap</h4><p><strong>Blockchain</strong> is a new data structure with an automated way to enforce trust among participants. Consensus algorithms ensure that all participants agree on the data stored within the blockchain. Blockchain opens the door to disrupt any industry that relies on a central authority to confirm authenticity. It also allows independent, and even competing organizations, to share information to gain efficiencies across an industry.</p><p><strong>In permissioned blockchains,</strong> a consortium of organizations are responsible for authenticating and controlling the participants in a blockchain. In public blockchains, no central authority or administration is required to exchange data. Blockchains can drive business innovation through controlled data-sharing networks for industry consortiums.</p><p>The promise of <strong>distributed ledger technologies (DLT)</strong> to simplify and automate key work functions has many industries taking notice. Businesses recognize the efficiency gains from transitioning from closed and proprietary solutions to standard open source capabilities, such as Hyperledger business blockchain technologies. Several common project features of blockchain applications are taking shape as the technology matures.</p><p>Business professionals when they see the word ‘hyperledger’</p><ol><li>They should associate it with <strong><em>open source development practices</em></strong>. They should know that any project that carries the term ‘hyperledger’, ‘hyperledger foobar’, ‘hyperledger rhubarb’, that these are projects that have been collaboratively built<strong>, </strong>that have been vetted by multiple developers working in concert on the technology, that it’s as secure as we can make it, because the code is out there.</li><li>They should realize that they can build their business on top of Hyperledger technologies,<strong> </strong>they can use it all day long, they don’t owe anybody a fee, a license fee, a patent license, <strong><em>nothing</em></strong>.</li></ol><h4>Dot com Mania</h4><blockquote>We document a striking positive stock price reaction to the announcement of corporate name changes to Internet-related dotcom names. This “dotcom” effect <strong>produces cumulative abnormal returns on the order of 74 percent for the 10 days surrounding the announcement day</strong>. The effect does not appear to be transitory; there is no evidence of a postannouncement negative drift. The announcement day effect is also similar across all firms, regardless of the firm’s level of involvement with the Internet. A mere association with the Internet seems enough to provide a firm with a large and permanent value increase. — Michael J. Cooper, Orlin Dimitriv, Raghavendru Rau</blockquote><p>Full Paper below:</p><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//www.andreisimonov.com/NES/BF/Cooper_A_Rosecom.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/046ee510e20ed362fc32738a6359a4b8/href">https://medium.com/media/046ee510e20ed362fc32738a6359a4b8/href</a></iframe><p>&amp; now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MB0Dhs0703mw2u5qkuBMyg.png" /></figure><h4>Blockchain / Bitcoin Mania</h4><p>Similar to the dot com hype, amid the cryptocurrency mania, several companies have launched initiatives to take advantage of the burgeoning assets, from retailer <a href="https://qz.com/1155108/overstock-com-ceo-patrick-byrne-considers-selling-the-business-to-fund-a-blockchain-non-profit/">Overstock.com</a> to photo group <a href="https://qz.com/1176495/kodakcoin-kodak-is-trying-to-stay-relevant-with-a-cryptocurrency-scheme-run-by-paparazzis/">Kodak</a>. Some much smaller firms have rebranded themselves completely, adding “bitcoin” or “blockchain” directly to their name. In some cases, the companies’ share prices soared in the US, Germany, and Hong Kong after this crypto-tweak.</p><p>For example, Bitcoin Services, formerly known as Tulip BioMed, saw its stock increase by as much as <strong>42,500% last year.</strong></p><p><a href="https://www.theatlas.com/charts/rJWric7Ez">Bitcoin Services&#39; stock price in 2017</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*SGI8nbUta0tG08a_XSJuhA.jpeg" /></figure><p>Here is a list of such companies!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VJPW1oZgsq9Q4M-LgQmWw.png" /><figcaption>Sources: OTC Markets, Investing.com</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*d30sLCaUv0077YMkxIJxuA.jpeg" /></figure><blockquote>Anyhow, the point is, it’s easy to just add blockchain / bitcoin to anything and ride the wave but that’s not what we are here to do. So let’s take a step back and ask ourselves certain questions to see if the problem that you are trying to solve really needs blockchain!</blockquote><h4>When to use blockchain?</h4><p>Factors to consider when evaluating blockchain distributed ledger technology for your business.</p><ul><li>How many participants are in your system?</li><li>What is the geographical distribution of the participants?</li><li>What sort of performance requirements do you have?</li></ul><p>Defining the rules, risks, and responsibilities of each party in your blockchain system is useful as you consider transferring a database to a decentralized environment such as one of the Hyperledger frameworks.</p><p>Blockchain is best suited for business applications where one or more of the following conditions apply:</p><ul><li>There is a need for a shared common database</li><li>The parties involved with the process have conflicting incentives, or do not have trust among participants</li><li>There are multiple parties involved or writers to a database</li><li>There are currently trusted third parties involved in the process that facilitate interactions between multiple parties who must trust the third party. This could include escrow services, data feed providers, licensing authorities, background verification companies or a notary public</li><li>Cryptography is currently being used or should be used. Cryptography facilitates data confidentiality, data integrity, authentication, and non-repudiation</li><li>Data for a business process is being entered into many different databases along the lifecycle of the process. It is important that this data is consistent across all entities, and/or digitization of such a process is desired</li><li>There are uniform rules governing participants in the system</li><li>Decision making of the parties is transparent, rather than confidential</li><li>There is a need for an objective, immutable history or log of facts for parties’ reference</li><li>Transaction frequency does not exceed 10,000 transactions per second.</li></ul><h4>When not to use Blockchain?</h4><p>Blockchain technology is a powerful tool, but it is not always the right tool for the job at hand. If you are contemplating using blockchain technology, be sure to evaluate the problem fully.</p><p>The following conditions are not currently well suited to blockchain-based solutions:</p><ul><li>The process involves confidential data</li><li>The process stores a lot of static data, or the data is quite large</li><li>Rules of transactions change frequently</li><li>The use of external services to gather/store data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*DixlupArHRgOStYK1efaRQ.png" /><figcaption>source: Hyperledger</figcaption></figure><p>Let’s use the above parameters to see if a professional network (candidates / professionals + recruiters + educational institutions + regulators) requires blockchain</p><ol><li>Need for a shared common database ? — Yes [so background verification isn’t done multiple times as the records here would be pre-vetted / pre-validated]</li><li>Multiple Parties Involved? — Yes [Candidates, Recruiters, Educational Institutes, Regulators &amp; Outsourced Verification Companies ]</li><li>Parties involved have conflicting incentives and/or not trusted? — Yes [Candidates can add fake certificates..<a href="https://economictimes.indiatimes.com/industry/services/education/sitting-on-a-fake-cv-time-bomb-how-india-inc-is-putting-in-checks-to-identify-discrepancies-in-resumes/articleshow/47750013.cms">Exhibit A</a>]</li><li>Rules governing participants are not uniform ? — Yes</li><li>Need for an objective, immutable log? — Yes [Public, De-centralized log of pre-validated resumes can remove trust establishing parties in the Hiring context]</li><li>Rules of Transactions do not change frequently? — Yes [Engagement terms of candidates and employers may vary but not the process]</li><li>Are transactions public? — Not always — so permissioned blockchain.</li></ol><p>Let’s tentatively name this project “Peoplechain” so in the future posts it’ll be easy to refer.</p><pre>So what did we learn in this post ?</pre><pre>1. Is Blockchain Technology the solution to all business problems ? — No<br>2. When to use Blockchain<br>3. When not to use Blockchain</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9c9ae97669a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 2 | Hyperledger Frameworks & Modules]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-2-hyperledger-frameworks-modules-b478e7aad89?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b478e7aad89</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:04:35 GMT</pubDate>
            <atom:updated>2018-07-30T06:04:35.165Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my learning journal of Hyperledger, the framework to create, deploy and maintain blockchains for businesses. This is gonna be a 10 part series so buckle up!</p><p>In the first chapter we learnt all the foundational concepts related to blockchain &amp; distributed ledger technologies (DLTs). Here we will focus purely on Hyperledger and its frameworks &amp; modules at a high level.</p><p>By the end of this post, you will understand</p><ul><li>The differences between Hyperledger and permissionless blockchain technologies.</li><li>The components of a Hyperledger Framework</li><li>Hyperledger frameworks (Iroha, Sawtooth, Fabric, Indy, and Burrow)</li><li>Hyperledger modules (Cello, Explorer, and Composer).</li></ul><p>You can think of Hyperledger as an operating system for marketplaces, data sharing networks, micro-currencies, and decentralized digital communities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*m5dr6qGMC4opWYFOLdHeuw.png" /></figure><h4>Differences between Hyperledger and permission-less blockchain technologies</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*s0t9QdJB_k_qRb4Wo14Fgg.png" /></figure><p><strong>*</strong>Sawtooth can be configured to be permissionless</p><p><strong>**</strong>Key Hyperledger consensus protocols arePoET in Hyperledger Sawtooth, RBFT in Hyperledger Indy, Tendermint in Hyperledger Burrow, and Yet Another Consensus (YAC) in Hyperledger Iroha. The fabric is built on a pluggable architecture such that developers can configure their deployment with the consensus module that best suits their needs. The initial release package will offer three consensus implementations for users to select from: 1) No-op (consensus ignored); 2) Classic PBFT; and 3) SIEVE (an enhanced version of classic PBFT).</p><h4>Components of Hyperledger Frameworks</h4><p>Hyperledger business blockchain frameworks are used to build enterprise blockchains for a consortium of organizations. They are different than public ledgers like the Bitcoin blockchain and Ethereum. The Hyperledger frameworks include:</p><ul><li>An append-only distributed <strong>ledger</strong></li><li>A <strong>consensus algorithm</strong> for agreeing to changes in the ledger</li><li><strong>Privacy</strong> of transactions through permissioned access</li><li><strong>Smart contracts</strong> to process transaction requests.</li></ul><h4>Hyperledger Framework 1: Iroha</h4><p><a href="https://hyperledger.org/projects/iroha">Hyperledger Iroha</a> is a blockchain framework contributed by Soramitsu, Hitachi, NTT Data, and Colu. Hyperledger Iroha is designed to be simple and easy to incorporate into infrastructure projects requiring distributed ledger technology. Hyperledger Iroha emphasizes mobile application development with client libraries for Android and iOS, making it distinct from other Hyperledger frameworks. Inspired by Hyperledger Fabric, Hyperledger Iroha seeks to complement Hyperledger Fabric and Hyperledger Sawtooth, while providing a development environment for C++ developers to contribute to Hyperledger.</p><p>In conclusion, Hyperledger Iroha features a simple construction, modern, domain-driven C++ design, along with the consensus algorithm <a href="https://www.overleaf.com/read/wzhwjzbjvrzn#/40115559/">YAC</a>.</p><h4>Hyperledger Framework 2: Sawtooth</h4><p><a href="https://www.hyperledger.org/projects/sawtooth">Hyperledger Sawtooth</a>, contributed by Intel, is a blockchain framework that utilizes a modular platform for building, deploying, and running distributed ledgers. Distributed ledger solutions built with Hyperledger Sawtooth can utilize various consensus algorithms based on the size of the network. By default, it uses the Proof of Elapsed Time (PoET) consensus algorithm, which provides the scalability of the Bitcoin blockchain without the high energy consumption. PoET allows for a highly scalable network of validator nodes. Hyperledger Sawtooth is designed for versatility, with support for both permissioned and permissionless deployments.</p><p>Eg: <strong>Sawtooth lake:</strong> Sawtooth Lake blockchain technology can provide an immutable record of the provenance and lineage of various goods, like fish.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-oxOas6cFXE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-oxOas6cFXE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-oxOas6cFXE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e77dcfbe0428d0a02d1bcf68ba25868a/href">https://medium.com/media/e77dcfbe0428d0a02d1bcf68ba25868a/href</a></iframe><p>Unique Characteristics of Sawtooth:</p><ol><li>Sawtooth is designed so that you can grow the size of the network</li><li>You can actually change the consensus mechanism on the fly</li></ol><h4>Hyperledger Framework 3: Fabric</h4><p><a href="https://www.hyperledger.org/projects/fabric">Hyperledger Fabric</a> was the first proposal for a codebase, combining previous work done by Digital Asset Holdings, Blockstream’s libconsensus, and IBM’s OpenBlockchain. Hyperledger Fabric provides a modular architecture, which allows components such as consensus and membership services to be plug-and-play. Hyperledger Fabric is revolutionary in allowing entities to conduct confidential transactions without passing information through a central authority. This is accomplished through different channels that run within the network, as well as the division of labor that characterizes the different nodes within the network. Lastly, it is important to remember that, unlike Bitcoin, which is a public chain, Hyperledger Fabric supports permissioned deployments.</p><blockquote><em>“If you have a large blockchain network and you want to share data with only certain parties, you can create a private channel with just those participants. It is the most distinctive thing about Fabric right now</em>.<em>” — Brian Behlendorf, Executive Director of Hyperledger, The Linux Foundation</em></blockquote><h4>Hyperledger Framework 4: Indy</h4><p><a href="https://www.hyperledger.org/projects">Hyperledger Indy</a> is a distributed ledger purpose-built for decentralized identity. Hyperledger Indy’s goal is to achieve this by developing a set of decentralized identity specs and artifacts that are independent of any particular ledger and will enable <strong>interoperability</strong> across any DLT that supports them.</p><p>Indeed, since 2013, over 9 billion data records were lost or stolen. What is striking is that, out of these, only 4% were encrypted, and hence, rendered useless after being stolen (also called ‘secure breaches’). You can find detailed statistics at</p><p><a href="http://breachlevelindex.com/">Data Breach Statistics by Year, Industry, More - Breach Level Index</a></p><p>One of the key principles of Hyperledger Indy is its ‘<a href="https://en.wikipedia.org/wiki/Privacy_by_design">Privacy by Design</a>’ approach. Given the immutable nature of the DLT, it is all the more important that digital identities be handled with the utmost care, keeping human values front and center.</p><blockquote><em>Hyperledger Indy lets users authenticate identity based on the attributes they are willing to store and share themselves. This can reduce the amount of liability contained within a business because the data can be kept with the user and presented to you again in a way that you can trust and validate that what has been said really was said and is trusted by the other parties you do business with.</em></blockquote><blockquote><em>- Nathan George, Maintainer, Hyperledger Indy</em></blockquote><p>Contributor: <a href="https://sovrin.org/">Sovrin foundation</a></p><h4>Hyperledger Framework 5: Burrow</h4><p>Currently under incubation, Hyperledger Burrow is a permissionable smart contract machine that provides a modular blockchain client with a permissioned smart contract interpreter built- in part to the specification of the Ethereum Virtual Machine (EVM). It is the only available Apache-licensed EVM implementation.</p><p>Following are the major components of Burrow:</p><ul><li>The <strong>Gateway</strong> provides interfaces for systems integration and user interfaces</li><li>The<strong> Smart contract application engine</strong> facilitates integration of complex business logic</li><li>The <strong>Consensus Engine</strong> serves the dual purpose of: <br>a. Maintaining the networking stack between the nodes, and,<br>b. Ordering transactions</li><li>The<strong> Application Blockchain Interface</strong> (ABCI) provides interface specification for the consensus engine and smart contract application engine to connect.</li></ul><p>You can learn more about Hyperledger Burrow at</p><p><a href="https://monax.io/platform/db/">Platform | Blockchain Client</a></p><h4>Recap</h4><pre><strong>Hyperledger Frameworks</strong><br>1. Iroha- A simple and easy to incorporate into infrastructure projects requiring distributed ledger technology<br>2. Sawtooth- A modular blockchain framework that implements the PoET consensus algorithm<br>3. Fabric- Modular Blockchain with private channels<br>4. Indy — De-centralised Identity<br>5. Burrow — Smart Contract Machine</pre><h4>Hyperledger Modules</h4><p>The Hyperledger modules are auxiliary softwares used for things like deploying and maintaining blockchains, examining the data on the ledgers, as well as tools to design, prototype, and extend blockchain networks.</p><p><strong>Hyperledger Module 1: Cello</strong></p><p>For businesses that want to deploy Blockchain-as-a-Service, <a href="https://www.hyperledger.org/projects/cello">Hyperledger Cello</a> provides a toolkit that fulfills this need. As a Hyperledger module, <em>“Cello aims to bring the on-demand ‘as-a-service’ deployment model to the blockchain ecosystem”</em>, thus helping in furthering the development and deployment of Hyperledger’s frameworks. Hyperledger Cello was initially contributed by IBM, with sponsors from Soramitsu, Huawei, and Intel. With Cello, You can build a Blockchain-as-a-Service (BaaS) platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*qWLxrpjOPUeW9tnzFbSVcg.jpeg" /><figcaption>Hyperledger Cello (Source: <a href="https://www.hyperledger.org/blog/2017/01/17/hyperledger-says-hello-to-cello">https://www.hyperledger.org/blog/2017/01/17/hyperledger-says-hello-to-cello</a>)</figcaption></figure><p><strong>Hyperledger Module 2: Hyperledger Explorer</strong></p><p><a href="https://www.hyperledger.org/projects/explorer">Hyperledger Explorer</a> is a tool for visualizing blockchain operations. It is the first ever blockchain explorer for permissioned ledgers, allowing anyone to explore the distributed ledger projects being created by Hyperledger’s members from the inside, without compromising their privacy. The project was contributed by DTCC, Intel, and IBM.</p><p>Designed to create a user-friendly web application, Hyperledger Explorer can view, invoke, deploy, or query:</p><ul><li>Blocks</li><li>Transactions and associated data</li><li>Network information (name, status, list of nodes)</li><li>Smart contracts (chain codes and transaction families)</li><li>Other relevant information stored in the ledger.</li></ul><p>The ability to visualize data is of critical importance, in order to extract business value from it. Hyperledger Explorer provides this much needed functionality. Key components include a web server, a web UI, web sockets, a database, a security repository, and a blockchain implementation.</p><p><strong>Hyperledger Module 3: Hyperledger Composer</strong></p><p><a href="https://www.hyperledger.org/projects/composer">Hyperledger Composer</a> provides a suite of tools for building blockchain business networks. These tools allow you to:</p><ul><li>Model your business blockchain network</li><li>Generate REST APIs for interacting with your blockchain network</li><li>Generate a skeleton Angular application.</li></ul><p>Built in <strong>Javascript </strong>(yaey!), Hyperledger Composer provides an easy-to-use set of components that developers can quickly learn and implement. The project was contributed by Oxchains and IBM.</p><p>The <a href="https://www.hyperledger.org/wp-content/uploads/2017/05/Hyperledger-Composer-Overview.pdf">benefits</a> of Hyperledger Composer are:</p><ul><li><strong>Faster creation of blockchain applications</strong>, eliminating the massive effort required to build blockchain applications from scratch</li><li><strong>Reduced risk</strong> with well-tested, efficient design that aligns understanding across business and technical analysts</li><li><strong>Greater flexibility</strong> as the higher-level abstractions make it far simpler to iterate.</li></ul><h4>Recap</h4><pre>Hyperledger Modules:<br>* Cello - toolkit to build Blockchain as a service revenue stream for a consulting company<br>* Explorer - To create something similar to etherscan or blockchaininfo. A tool to visualise transactions, blocks etc<br>* Composer - suite of tools for building blockchain business networks</pre><p>All right, so what did we learn ?</p><ul><li>The differences between Hyperledger and permmissionless blockchain technologies.</li><li>Overview of Hyperledger frameworks such as Iroha, Sawtooth, Fabric, Indy, and Burrow.</li><li>Overview of Hyperledger modules such as Cello, Explorer, and Composer.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b478e7aad89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger — Chapter 1 | Blockchain Foundation]]></title>
            <link>https://medium.com/@abhinav.garg_90821/hyperledger-chapter-1-blockchain-foundation-73472f6140e3?source=rss-2b2e8cdc0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/73472f6140e3</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Abhinav Garg]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 06:03:14 GMT</pubDate>
            <atom:updated>2018-07-30T06:03:14.628Z</atom:updated>
            <content:encoded><![CDATA[<p>This is my learning journal of Hyperledger, the framework to create, deploy and maintain blockchains for businesses. This is gonna be a 10 part series.</p><p>By the end of this post, you will understand</p><ul><li>Hyperledger (what &amp; who)</li><li>Distributed Ledger Technology</li><li>Blockchain vs. Distributed Ledger Technology</li><li>Blockchain (Transactions, Blocks, Merkle Tree, Cryptography)</li><li>Smart Contracts</li><li>Consensus Algorithms</li><li>Public Blockchains</li><li>Permissioned vs. Permissionless Blockchains</li><li>Other DLTs</li></ul><h4>What is Hyperledger?</h4><p>Hyperledger is the umbrella open source project that the Linux Foundation has created and hosted since 2015. It aims at advancing and promoting cross-industry blockchain technologies to ensure accountability, transparency, and trust among business partners. As a result, Hyperledger makes business network and transactions more efficient.</p><h4>What is the Linux Foundation?</h4><p>Linux<strong> </strong>is the world’s largest and most pervasive open source software project in history. The Linux Foundation is home to Linux creator Linus Torvalds and lead maintainer Greg Kroah-Hartman, and provides a neutral home where Linux kernel development can be protected and accelerated for years to come.</p><p>The Linux Foundation is the umbrella organization for many critical open source projects that power corporations today, spanning all industry sectors:</p><ul><li>Big data and analytics: <a href="https://www.odpi.org/">ODPi</a>, <a href="https://www.r-consortium.org/">R Consortium</a></li><li>Networking: <a href="https://www.opendaylight.org/">OpenDaylight</a>, <a href="https://www.opnfv.org/">OPNFV</a></li><li>Embedded: <a href="https://www.dronecode.org/">Dronecode</a>, <a href="https://www.zephyrproject.org/">Zephyr</a></li><li>Web tools: <a href="https://js.foundation/">JS Foundation</a>, <a href="https://nodejs.org/en/">Node.js</a></li><li>Cloud computing: <a href="https://www.cloudfoundry.org/">Cloud Foundry</a>, <a href="https://cncf.io/">Cloud Native Computing Foundation</a>, <a href="https://www.opencontainers.org/">Open Container Initiative</a></li><li>Automotive: <a href="https://www.automotivelinux.org/">Automotive Grade Linux</a></li><li>Security: <a href="https://www.coreinfrastructure.org/">The Core Infrastructure Initiative</a></li><li>Blockchain: <a href="https://www.hyperledger.org/">Hyperledger</a></li></ul><h4>Context</h4><p>We are witnessing the transition from centralized computing, storage, and processing to decentralized architectures and systems. These systems aim to</p><blockquote><em>“give explicit control of digital assets to end-users and remove the need to trust any third-party servers and infrastructure”</em>. — <a href="https://medium.com/u/8dd3ab013f82">Muneeb Ali</a></blockquote><p>Distributed ledger technology is one of the key innovations making this shift possible.</p><h4>Distributed Ledger Technology (DLT)</h4><p>A <strong>distributed ledger</strong> is a type of data structure which resides across multiple computer devices, generally spread across locations or regions.</p><p><strong>Distributed Ledger Technology</strong> includes blockchain technologies and smart contracts. While distributed ledgers existed prior to Bitcoin, the Bitcoin blockchain marks the convergence of a host of technologies, including time-stamping of transactions, Peer-to-Peer (P2P) networks, cryptography, and shared computational power, along with a new consensus algorithm.</p><p>In summary, distributed ledger technology generally consists of <a href="https://intelledger.github.io/introduction.html">three basic components</a>:</p><ul><li>A <strong>data model</strong> that captures the current state of the ledger ( a time-stamped series of transactions cryptographically secured)</li><li>A <strong>language of transactions</strong> that changes the ledger state [Smart Contracts / Chain code]</li><li>A <strong>protocol</strong> used to build consensus among participants around which transactions will be accepted, and in what order, by the ledger.</li></ul><blockquote>Blockchain is a peer-peer distributed ledger forged by consensus, combined with a system for smart contracts and other assistive technologies. — Robert Schwentker (hyperledger.org)</blockquote><p><strong>Smart contracts</strong> are simply computer programs that execute predefined actions when certain conditions within the system are met.</p><p><strong>Consensus</strong> refers to a system of ensuring that parties agree to a certain state of the system as the true state.</p><h3>Difference between Distributed Ledger &amp; Blockchain</h3><p><strong>Blockchain</strong> is a specific form or <strong>subset of distributed ledger technologies, </strong>which constructs a chronological chain of blocks, hence the name ‘block-chain’.</p><p><strong>Block:</strong></p><p>A <strong>block</strong> refers to a set of <strong>transactions</strong> that are bundled together and added to the chain at the same time. In the Bitcoin blockchain, the miner nodes bundle unconfirmed and valid transactions into a block. Each block contains a given number of transactions. In the Bitcoin network, miners must solve a cryptographic challenge to propose the next block. This process is known as ‘<strong>proof of work’</strong>, and requires significant computing power.</p><p><strong>Transactions</strong> The record of an event, cryptographically secured with a digital signature, that is verified, ordered, and bundled together into blocks, form the <strong>transactions</strong> in the blockchain.</p><p><strong>Cryptography </strong>has a key role to play both in the security, as well as in the immutability of the transactions recorded on blockchains. Cryptography is the study of the techniques used to allow secure communication between different parties and to ensure the authenticity and immutability of the data being communicated. For blockchain technologies, cryptography is used to prove that a transaction was created by the right person. It is also used to link transactions into a block in a tamper-proof way, as well as create the links between blocks, to form a blockchain.</p><p><strong>Timestamping</strong> is another key feature of blockchain technology. Each block is timestamped, with each new block referring to the previous block. Combined with <strong>cryptographic hashes</strong>, this timestamped chain of blocks provides an immutable record of all transactions in the network, from the very first (or genesis) block.</p><p>A block commonly consists of four pieces of metadata:</p><ul><li>The reference to the previous block</li><li>The proof of work, also known as a nonce</li><li>The timestamp</li><li>The Merkle tree root for the transactions included in this block.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*vdIpslqaCqA6ijTJgXXnfQ.png" /><figcaption>source: <a href="https://vi.wikipedia.org/wiki/T%E1%BA%ADp_tin:Bitcoin_Block_Data.png">https://vi.wikipedia.org/wiki/T%E1%BA%ADp_tin:Bitcoin_Block_Data.png</a></figcaption></figure><p><strong>The Merkle tree</strong>, also known as a binary hash tree, is a data structure that is used to store <strong>hashes</strong> of the individual data in large datasets in a way to make the verification of the dataset efficient. It is an anti-tamper mechanism to ensure that the large dataset has not been changed.</p><blockquote>Merkle trees are used to summarize all the transactions in a block, producing an overall digital fingerprint of the entire set of transactions, providing a very efficient process to verify whether a transaction is included in a block.</blockquote><h4>Blockchain</h4><blockquote>Blockchain also allows us to create an <strong>instantaneous single source of truth</strong>. In the past, we’ve always had problems with trying to figure out what really happened over the course of a day. Banks reconcile their books, inventory systems clear sales and deliveries…With blockchains, we’re recording things in real time, and it provides us with sort of an up-to-date accounting of the state of the world.<strong> </strong>— Dave Huseby</blockquote><p>Importance of a single source of truth and it being shared with everyone from two people I admire the most.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNV3sBlRgzTI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNV3sBlRgzTI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FNV3sBlRgzTI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/de3a80f23c635928d6224545d3ec7f90/href">https://medium.com/media/de3a80f23c635928d6224545d3ec7f90/href</a></iframe><blockquote>Boil things down to the fundamental truth — Elon Musk</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FtaQOSs0IXRE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtaQOSs0IXRE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FtaQOSs0IXRE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea2de50f9d657496514b56976627be03/href">https://medium.com/media/ea2de50f9d657496514b56976627be03/href</a></iframe><blockquote>One of the biggest problems with democracy is that we don’t share a common baseline of facts — Barrack Obama to David Letterman [My Next Guest Needs no introduction]</blockquote><blockquote>So we have established that a common base of truth / fact that is shared across the concerned parties will solve a lot of inefficiencies for which we have relied on middle men / institutions for centuries. But, who will oversee / make sure that the facts aren’t tampered with and what goes into the commonly shared ledger and what doesn’t ? Well, your answer is consensus. So a <strong>protocol</strong> is used to build consensus among participants around which transactions will be accepted, and in what order, by the ledger</blockquote><p><strong>Consensus</strong> is a process whereby the computers that are part of the network synchronize the data on the blockchain. <strong>Consensus</strong> in the network refers to the process of achieving agreement among the network participants as to the correct state of data on the system. Consensus leads to all nodes sharing the exact same data. A <strong>consensus algorithm</strong>, hence, does two things: it ensures that the data on the ledger is the same for all the nodes in the network, and, in turn, prevents malicious actors from manipulating the data. The consensus algorithm varies with different blockchain implementations.</p><p>There are a number of consensus mechanisms or algorithms.</p><ul><li>Proof of Work</li><li>Proof of Stake</li><li>Proof of Elapsed Time</li><li>Simplified Byzantine Fault Tolerance</li><li>Practical Byzantine Fault Tolerance (PBFT)</li></ul><p>Bitcoin uses Proof of Work, while Ethereum uses Proof of Work currently, but is moving towards Proof of Stake. The Hyperledger Sawtooth uses Proof of Elapsed Time. Zilica uses PBFT.</p><h4>Different Algorithms for Consensus</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIClyGovPU7PysqrD3mIoA.png" /></figure><h4>Decision Metrics of Consensus Algorithms</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*-nWqHmCyq-sxbecjkvuhFw.png" /></figure><h4>Comparative Analysis of Consensus Algorithms</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*q1p7KseSQ96g4H-qdtL_fg.png" /><figcaption>Parameters used to compare are defined below</figcaption></figure><p><strong>Blockchain type</strong> — Blockchain type indicates the type of blockchain platform — permissioned or permissionless, in which the consensus model can be used.</p><p><strong>Transaction finality</strong> — Transaction finality indicates whether the transaction once added to a block in the blockchain is considered final.</p><p><strong>Transaction rate</strong> — Transaction rate is higher with platforms that can confirm transactions immediately and reach consensus fast.</p><p><strong>Token needed?</strong> — A cryptographic token is inherently required for PoW and PoS models as their design itself is based on existence of the token.</p><p><strong>Cost of participation</strong> — PoW and PoS have an inherent cost associated for participation in consensus. PoW requires expending energy, which is a resource that is external to the consensus protocol, while PoS requires nodes to buy some initial cryptocurrency to generate a security deposit for declaring interest and bonding with the platform.</p><p><strong>Scalability of peer network</strong> — Scalability of the consensus models is its ability to reach consensus when number of peering nodes are constantly increasing. All models summarized above, except BFT and variants, have high scalability.</p><p><strong>Trust model </strong>— Trust model determines if the nodes participating in the consensus have to be known or trusted. In PoW, PoS and PoET, nodes can be untrusted as the mechanism to reach consensus is based on other means such as computational work or security deposits.</p><p><strong>Adversary tolerance</strong> — The fraction of the network that can be compromised without the consensus being affected. Each consensus model has a certain threshold to adversary tolerance.</p><blockquote>Now that we know that consensus algorithms are used to drive distributed consensus with out a centralized authority or human intervention. How do make sure the data isn’t tampered with ? Read along.</blockquote><h4>The Immutability of the Data</h4><p>The immutability of the data which sits on the blockchain is perhaps the most powerful and convincing reason to deploy blockchain-based solutions for a variety of socio-economic processes which are currently recorded on centralized servers.</p><p>This <strong>immutability</strong>, or ‘<strong>unchanging over time</strong>’ feature makes the blockchain useful for accounting, financial transactions, identity management, and asset ownership, management and transfer, just to name a few examples.</p><p>Once a transaction is written onto the blockchain, no one can change it, or, at least, it would be extremely difficult to change it.</p><p>According to <a href="https://www.linkedin.com/pulse/gentle-introduction-immutability-blockchains-antony-lewis/">Antony Lewis</a>, the Director of Research at R3,</p><p><em>“When people say that blockchains are immutable, they don’t mean that the data can’t be changed, they mean it is extremely hard to change without collusion, and if you try, it’s extremely easy to detect the attempt</em>.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*Z8AG33rSlfcSArBap5rirQ.png" /></figure><blockquote>Now that we know blockchain / distributed ledger is the way to store facts and consensus algorithms are used to drive agreements of what goes into the ledger and in what order how do we actually do it? Through smart contracts!</blockquote><h4>Smart Contracts</h4><p>Back in 1996, a man named Nick Szabo coined the term ‘smart contract’. <strong>Smart contracts</strong> are simply computer programs that execute predefined actions when certain conditions within the system are met. Smart contracts provide the <strong>language of transactions</strong> that allow the ledger state to be modified. They can facilitate the exchange and transfer of anything of value (e.g. shares, money, content, property).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*TKuwkRsCsTm05p3zISYjzw.png" /></figure><h3>Quick Recap</h3><pre>* The data model for a DLT (Distributed Ledger Technology) is a version of <strong>Blockchain</strong></pre><pre>. Transactions make a block<br> . Block has the reference to the previous block, The proof of work, also known as a nonce (consensus parameter), The timestamp, The Merkle tree root for the transactions included in this block.<br> . A cryptographically secured chain of blocks is blockchain</pre><pre>* A <strong>protocol</strong> used to build consensus among participants around which transactions will be accepted, and in what order, by the ledger is called <strong>consensus</strong>. Various consensus algorithms are available and you choose what&#39;s best for your solution based on certain parameters defined above.</pre><pre>* Smart contracts - A <strong>language of transactions</strong> that changes the ledger state</pre><blockquote>Now, you might wonder if blockchain is just a database …read on to find the differences</blockquote><h4>Blockchain vs. Databases</h4><p>A blockchain is a <strong>write-only data structure</strong>, where new entries get appended onto the end of the ledger. Every new block gets appended to the block chain by linking to the previous block’s ‘hash’. There are <strong>no administrator permissions</strong> within a blockchain that allow editing or deleting of data.</p><p>In a relational database, data can be easily modified or deleted. Typically, there are database administrators who may make changes to any part of the data and/or its structure. Additionally, blockchains were designed for decentralized applications, whereas relational databases, in general, were originally designed for centralized applications, where a single entity controls the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*7n4LExrO68YMuSBf7DjAvw.png" /></figure><h4>Types of Blockchain</h4><ul><li><strong>Permissionless Blockchain </strong>(like Bitcoin or Ethereum)</li><li><strong>Permissioned</strong> <strong>Blockchain</strong> (like the different Hyperledger blockchain frameworks).</li></ul><p>A Permissionless blockchain is also known as a public blockchain, because anyone can join the network.</p><p>A permissioned blockchain, or private blockchain, requires pre-verification of the participating parties within the network, and these parties are usually known to each other.</p><blockquote>Permissionless blockchain examples</blockquote><h4>1. Bitcoin</h4><p><a href="https://blockchain.info/">Bitcoin Block Explorer - Blockchain</a></p><p>Genesis Block of Bitcoin [50 BTC transferred on Jan 3 2009]</p><p><a href="https://blockexplorer.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f">Bitcoin Block Explorer</a></p><p>Few interesting Bitcoin Transactions:</p><p><a href="https://blockchain.info/tx/f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"><strong>January 12, 2009: It all had to start somewhere</strong></a></p><p>It happened at <a href="https://blockchain.info/block-index/15019/00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee">block height 170</a>, the very first bitcoin transaction ever. This transaction was between the late Hal Finney and Satoshi Nakamoto. <a href="https://en.wikipedia.org/wiki/Hal_Finney_(computer_scientist)">Finney was a computer scientist</a>, inventor of reusable-proof-of-work (RPOW), a bitcoin pioneer, and also the first recipient of bitcoin via this transaction.</p><p><a href="https://blockchain.info/tx/a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"><strong>May 22, 2010: “I’ll pay 10,000 bitcoins for a couple of pizzas…”</strong></a></p><p>In retrospect, this was quite a monumental transaction, and it also resulted in the most expensive pizzas ever. A user of the BitcoinTalk forum <a href="https://bitcointalk.org/index.php?topic=137.msg1195#msg1195">wanted to order two pizzas</a> and was asking if anyone could order it to be delivered to him in exchange for 10,000 bitcoins. The value at the time of the transaction was around $25 USD. Today, that amount in bitcoin is worth over $6.3 million. Every year since that transaction, the bitcoin community remembers this event by celebrating <a href="https://blog.blockchain.com/2014/05/23/how-the-blockchain-team-celebrated-bitcoin-pizza-day/">Bitcoin Pizza Day</a> on May 22nd. Images of the famous pizza <a href="http://eclipse.heliacal.net/~solar/bitcoin/pizza/">here</a></p><p><a href="https://blockchain.info/tx/3a1b9e330d32fef1ee42f8e86420d2be978bbe0dc5862f17da9027cf9e11f8c4"><strong>June 23, 2011: Mt.Gox on the move</strong></a></p><p>When bitcoin exchange Mt.Gox was struggling to stay afloat prior to their infamous collapse, then CEO Mark Karpeles wanted to prove that Mt.Gox was financially sound. To do so, he performed one of the biggest and most risky bitcoin transactions ever. The transaction <a href="http://www.coindesk.com/gox-money-moving-through-block-chain/">was from Mt.Gox to Mt.Gox</a>, but regardless it was sent over the bitcoin network to the tune of 442,000 bitcoins. The value now is in the neighborhood of $282.2 million USD.</p><h4>2. Ethereum</h4><p>-Programmable Blockchain with a Turing complete language, solidity.</p><p><a href="https://etherscan.io/blocks">Ethereum Blocks</a></p><p>Genesis Block of Ethereum [5 ethers transferred on 30-July-2015]</p><p><a href="https://www.etherchain.org/block/1">Block 1 - etherchain.org - The Ethereum Blockchain Explorer</a></p><blockquote>Till now, we have talked about blocks, a chain of blocks, writing on to the blockchains, driving consensus but how does it become a network ?</blockquote><blockquote>Every node / computer that has the distributed ledger is considered a node and a network of such computers / nodes form a network.</blockquote><h4>Architecture [Client-Server vs. Peer — Peer]</h4><p>Historically, most applications utilize a central server (or servers). For one user/client to send a message to another user/client in the network, the request has to be sent to the hub or a central server, which then directs it to the right computer.</p><p><strong>Peer-to-peer</strong> (P2P) networks were first made popular by Napster (and later BitTorrent) and consist of computer systems which are directly connected to each other via the Internet, without a central server. Peers contribute to the computing power and storage that is required for the upkeep of the network. P2P networks are generally considered to be more secure than centralized networks, as they do not have a single <em>point of attack.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*BhPNWD_vUwBC2icRASxfMw.png" /><figcaption>Edx : Hyperledger</figcaption></figure><h3>Advantages of using a Permissioned Blockchain over a Permissionless (Public) Blockchain</h3><p>If you look at permissionless blockchains, like the Bitcoin blockchain or the Ethereum blockchain, anyone can join the network, as well as write and read transactions. The actors in the system are not known, which means there could be some malicious actors within the network.</p><p>Hyperledger reduces these security risks and ensures that only the parties that want to transact are the ones that are part of the transaction and, rather than displaying the record of the transactions to the whole network, they remain visible only to the parties involved. So, Hyperledger provides all the capabilities of the blockchain architecture — data privacy, information sharing, immutability, with a full stack of security protocols — all for the enterprise.</p><h4>Other DLTs.</h4><ol><li><strong>Chain Core,</strong> created by chain.com, has initially been designed for financial service institutions, and for things like securities, bonds, and currencies. Their company has strong ties with Visa, Citigroup, and Nasdaq. “T<em>he operation of the network is governed by a designated set of entities known as a federation</em>”</li><li><strong>The Corda</strong> distributed ledger platform is designed to record, manage, and automate legal agreements between businesses. It was created by the R3 company, which is a consortium of over a hundred global financial institutions. “<em>”Corda achieves consensus between firms at the level of individual deals, not the level of the system”</em></li><li><strong>Quorum</strong> is a permissioned implementation of Ethereum, which supports data privacy. Quorum achieves this data privacy through allowing data visibility on need-to-know basis by a <strong>voting-based consensus algorithm. </strong>Interestingly, Quorum was created and open sourced by JPMorgan. <em>“ The platform is designed to support both transaction-level privacy and network-wide transparency”</em></li><li><strong>IOTA</strong>: <em>“It is the first cryptocurrency that provides the whole ecosystem based on blockless blockchain”</em> to enable machine-to-machine (M2M) transactions. IOTA, however, is more than just a cryptocurrency. Essentially, the platform entails a generalization of the blockchain protocol (the technology called Tangle) that sits at the backend of the IOTA platform. Instead of paying miners to validate the transactions, the architecture of the network involves peer-based validation. Think of a simple analogy, that of a teacher grading students’ homework: the students are the clients/users in the Bitcoin protocol, and the teacher is the miner/validator. Tangle technology asks students (users) to grade each other’s homework, making the need for a teacher (external validator) redundant, and avoiding expenses related to the teacher’s/validator’s work. This allows the platform to be completely free of cost, without facing the scaling challenges that are inherent in the first generation of blockchains. Additionally, the use of the platform with connected devices or the Internet of Things <em>“enables companies to explore new business-to-business models by making every technological resource a potential service to be traded on an open market in real time, with no fees”.</em></li></ol><pre>Now that we have a basic understanding of the foundational concepts we’ll move on to Hyperledger projects in the next chapters.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73472f6140e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>