Build and deploy a Blockchain web-app with Hyperledger Fabric & Hyperledger Composer - Horea Porutiu
Again. This main, thing I want you to understand, is that fabric. Is always. Necessary. But composure, just, accesses. Fabric in a easy-to-use, manner so, composure. Is optional, but, I think, it's a really good way to get started developing. And. Under, the hood, composers. Really just calling. The fabric api's and. It's it's it's. It's really just building, on top of fabric. So. Some of the key. Concepts. That we will learn, about is. Participants. Transactions. And assets so. These are the key words that I'll mostly be focusing, on today and that's, the key words that composer uses. Okay. So. Here's, the link for actually, downloading, the fabric. Environment, for your local computer. Of, course I don't recommend doing this now because it will take some time to, actually download but, I'm after, if you want to go home and try this out I leave this link here for you. So. Once. You actually download the. Fabric on your local computer you'll have some scripts, that you'll need to run or. The first one is download fabric so I've already done that on my computer and, that was just taking. The actual fabric and putting it on your computer the. Start fabric, script, is what I will show you later today in. My demo and that's, gonna create some containers, and. The, four containers that will create one will be a database, I want to be order one, will be appear and, one will be a certificate, authority so. I'll kind of go a little bit more about. That when I actually run the script and. The, last thing we have to do is actually create these, pure, admin card this. Is the credentials, that will give us these. Are the credentials that is basically. Admin, access to the network so we have to prove with. Our public/private, key pair that we are the admins of the network and, that's what this script. Is doing is creating these credentials. For us. So. I. Talked. A little bit about this, modeling. Language so. This is. Composer uses, this unique modeling, language and, their. File, is called, this model file so that's just really the data schema of your, actual, application. So. The four things, we really have to worry about is. The, namespace, the. Participants, the. Assets. And the transactions, so. We have to define these four core features, the, events are optional I will not show that for the sake of time but know that there is events, as well. So. This. Is basically what you will need to define and I think this is really the. Most. Critical part of building your application, is this, model file so, if, if. You spend most of your time actually coming, up with a very good model I think that, is really the key to a successful blockchain. Application, so. Really, take the time I think really to understand, who are your participants, in your blockchain, network and. What. Transactions, and assets, do you have but, really the participants, is at the core right. We, want to ensure that. You. Know we, are we, we have some value being traded on the blockchain so. Again. This this first part of defining the model is is I think the key and the most important part. So. Here, I have a very, simple, kind. Of like a hello world model. File so this, model. File I will show you. Deploying. This with composer and as part of the demo, so. First. Thing we have our namespace at the top in. That after, that everything. We, want to reference in the blockchain will be coming from this main space and. So. Once. We have defined, our main namespace. We can define our asset, so. We see here we just have a very generic asset.
See Yeah perfect. Okay. So we start the network we can actually ping the network to see if it's working I'll, not do that right now so the next, thing we can do is actually, create. Our API. So. Let's go ahead and run this compose a rest server. So. This will ask. Okay. Clear. So. This will ask us for, our actual. Business, network, card so, that will be the, admin. Card we have made, earlier, so. Admin at my, network, and here. Asks for namespaces, if you say yes, it will have the org Acme, dot commodity. I'm, gonna say no for, making, it look a little nicer so we'll just say commodity, instead, of or acne dot my network duh commodity so, I'll say never and. I'm. Not gonna secure it for now just for the sake of time. So. Ask do you want to enable authentication. And. Okay. So I'm just gonna say. No for now. So. It's. Going to go. Into the types of our, network, and now we've generated, our REST API if. We click this we. Should see our REST. API here, so. Again, we have the commodity, if. We we. Don't have any commodities, created yet because, our, constructor, didn't create any and but if we this, is where we can go ahead and do like a get call and then we would see all the commodities in our network, as. This, system is like the entire. History of the blockchain so for the system now we should just see something like a, install. We. See the network is instantiated and, I, believe, just the the, basically just the first installation. So let's check that right now. Yes. You see here we have the start, of the network, and. Then we have added the actual admin here. So. What. I can do I can actually add a couple. Traders. Here I'm. Not going to go through the full a. Flow. For time but, I can add a couple traders and all of this JSON, that we need is in the repo. So, here is the data schema for the trader I'll just create once quickly. Post. It here and. If we try it it should give us hopefully. 200. Awesome. So, we see here the date. And if we go into our system, we should have this as well. Ok. Perfect so we have this add participant, we say we see that we add min invoked it. So. That's. What. We have with the system record so. This. Is how you, get. Your first hello world application, running, once, you have this API. Running you can go ahead and connect to your front end and. Then you can have this whole, history of transactions, you, can have more, complex queries, I haven't shown that but I'll show this in the next demo, so. You have more complex queries but, this is kind of the basics, of getting started just, getting to this point, so. Now I want to switch gears a little bit so. You, can kind of see this shirt I'm wearing is this, blockchain. IBM. Blockchain in collaboration, with Brooklyn roasting, so, this is a proof-of-concept I've, worked on using the blockchain. Cloud service, so, I want to kind of demo, and show you that now, so, I want to show this hello. World and then go into a little bit more complex, architecture. And schema.
Now. Okay. So close this up from now okay. Okay. So this is the main page for the. For. The activation. So. Really. The goal of this project. Was to show this transparency. For, all the key, suppliers, in the supply chain so, if the goal of Brooklyn, roasting company so this is the partner we worked with their. Goal is to show this, ethically. And. Sustainably, produced coffee, so, part of that mission. Is showing, this, fair. Fair. Price. That is paid for the coffee so. What, we should what we have here in this project is we have their actual, industry. Compliant. Documentation, that shows, that they gave a, fair, wage, to the coffee, growers that they paid and we. Have shipping, details such as like a packing list, we, have import, details, and. Then we have actual. Roast. Details so, before. The the coffee is actually brewed, and created, into a cup of coffee the. Brooklyn. Roasting company goes ahead and taste tests it critiques, it says oh it's maybe, not so good or it's really, good, so. Those. Are the main kind of components, so again I think what's. Important, to understand, with block chain is that, really. 99%, of the work and investment, comes as you're. Creating the network once, the network is deployed and out there there's not really much to be done right but, it's a huge massive, investment, to actually get it started I you, have to get all the different. Parties all the different suppliers agreed, on the same exact, terms you, have to actually you know build, the network like we have done it here you. It, takes a lot of time and investment right once, you actually. Launch. And deploy it's not not. That much work so, I think that's the key part is do, we need a bot chain and then, actually, taking the time to work with all the participants, and suppliers. Involved, and say hey are you ok with these, exact rules that we have. Gone by in this smart contract and at. The end of the day someone, needs to approve all these transactions. Right so there has to be someone either an external, organization or, someone that you give permission. To actually approve these transactions, so there's something called, like an endorsement policy, which, you can set up in your hyper ledger and saying, which member, is actually going to approve the transaction how do we know it's actually you.
Know A correct, or incorrect. Transaction. Okay. So. For. The next, ten. Ten, eleven, minutes I, want. To focus on the different participants. In different parties involved. So. The first party, I'll talk about is the actual grower, so. The grower is this Ethiopia. Co-op. And, we, see here, on. July 21st, 2017. We, buy a hundred, fifty bags of this coffee. So. At. This point a brooklyn roasting, has a. Document. That says look when we bought these bags of coffee we. Have given, this tax. To actually, invest in the local community, and this, is their way of proving this Fairtrade. Premium. So. If I click on view the blockchain and, it, should actually query my blockchain, and it, will show me exactly, what. Has. Been invested. So. We see that they have invested in road infrastructure, let me a little. Bit, we. See they've invested in road infrastructure. They've. Invested, in school classrooms, and, food. Security. Also, you can see that the total premium. They have invested, is 182,000, so. You may be thinking right now like okay this is just random data, where are you getting. This data from right it's like you're. Just showing these data, so. Now we can click on the view original, document, so. Brooklyn, roasting, was nice enough to actually. Let us publicize. These documents, so. What. You can see here is this a premium, invested. 182,000. Exactly, what I've shown you earlier, you, have the, school. Classroom, edition the funds invested. 30,000. You have the road infrastructure, and the food security, so. These, are some, of the fields we thought were important, and Brooklyn. Roasting thought were important to show to the, all. The customers. The different suppliers so, this is the war way of showing this fair trade and ethically. Produced. And, sustainable. Coffee. So. We have talked about the first part of our journey which, is the grower so, next we will have to actually ship this big, very. Huge batch of coffee I'm not, sure it may be a thousand. Kilos or a very big amount we ship this from Ethiopia, to the United States so. Now we need some sort of proof from the shipper that you, know we, have packaged all your coffee on this date shipped, it in this container. You'll. It'll, arrive on this date we have we have to have some documents, here so, that's the next part of the story here so, we. Can go back and. And. Just, to show you kind of my actual, API. That's running. So. This is the API that I have available for this this. Coffee bean demo so this is the same HelloWorld. API. But, just with a little bit more complex data schema so. Instead, of only one participant, I have four. Four, or five participants, so we have the grower, we have the shipper, we have the retailer right so. It's really that same pretty, much that same thing just added, a little more complexity, to the schema. So. If, I actually, go. In to, submit. Fairtrade. Data so. You, can think of this as we. Have a different, interface for this grower we, have they have their own application they. Sign in they authenticate, and they, have access to this rest. Endpoint, and they're. Able to submit or. Brooklyn, it will actually submit this, Fairtrade data through this endpoint and only, they can submit this data. So. We get we we, actually do a get here to see what's, actually has. Been submitted already. So. Again. It's that same. That data, that, was showing. In the front end right it's, really just doing a simple get call to this. So. You can see again the road infrastructure, here the food security. Classroom. Addition we have the some. More data that was not shown in the UI like the actual batch ID so. You can imagine if there's 100. Or 200 different, huge, batches of coffee we each one will have this unique ID so. You can actually, see, the process for. Each bag. Ok. So. Yeah when you click on this view the blockchain it's just making a call to my API, that's running in the cloud right now so. Second. Step here, is we have to show these packing, details so again I should I tell you you know we have to have some data for actually shipping so, this is the next step here. So. We click on view the blockchain and now. We should, see some more details, about the packing list so.
You. Can see the voyage number, the. Invoice number. Something. Interesting is that this has a reference to the grower so. You're. Saying who actually gave, these beams to be shipped you're saying grower 0, 2 0 1 so. You're saying okay who's grower, 0 2 0 1 if. We actually go into our, our. REST. API if we go into grower, do. A get, we. Should see our growers 0 2 0 wand ok, and, you. See here that's just simply the, Ethiopian. Co-op right, so. We see here that's who. Is actually submitting, these beans and. You. See here that who's. Actually going to. Receive. The beans so, this is this traitor oops. There's, trader zero seven nine one so. Ok. If, we go into trader we'll see who the who's actually picking up the beans. Do. It get. And. We'll. See that here. Ok. So I was already loaded so, you see Royal coffee who's actually receiving these Dean's okay. Again. We see the ship, name northern, Magnum Magnum, and we see the build landing, number 961. So. We can view the original document. Same. Same. Thing this is all coming from the. The. Coffee co-op so this is their proof. That we have actually shipped this, data or this this batch on this day so. We see the date is 2017. This. Royal coffee. Bill. Of landing number again you see that nine six one number and. You see the container number is is a, block. Down that's, just part of our agreement with Brooklyn roasting they didn't want to show, that to detail, just. For security, purposes but everything else they have lettuce, demin. So publicly. So. You see here that container. Number is redacted just for security purposes. Okay. So we. Shipped the coffee next. Thing about, how, long does this journey take two. Weeks two, and a half weeks. Two. And a half weeks later we actually receive, the container so now we have, to go into the container and see like did, we actually get the amount of coffee that was shipped or is, there damage is there, did. It spoil over the ocean. Is there insects. You. Know we have to confirm that we, got a good shipment. So. We can view the blockchain here. Again. It's just calling, my REST API and. Here. So. We see you know are there holes in container no was. There any condom stations how many bags do we expect it. Was the insect activity and. That. Again. That document. Is just coming straight from, this importer, and, they're the one that is actually receiving the shipment and you can imagine this big, importer, of coffee has you know thousands. Of shipler i don't know in. A, normal month maybe they have hundreds of these shipments right so they have to have good. Organization. To keep track of all of these. Again. You see on this documentation, the bags expected. You. Know condensation. Holes in container we, have people, that I've actually signed off on this saying look this is what happened on this date, we. Verified it and. That's. Just coming again straight from this. Submit. Inbound. Wait tally here. Okay. Yeah. So same exact info. Here that, you see on the front end. Okay. So the last step which i think is really the coolest. Part is this. Cupping. So once, they the. Retailer, buys this coffee, from this big warehouse, they. Go ahead and critique so you can imagine like I don't know ten, of these coffee. Connoisseurs. Sitting around drink, sipping a little bit Oh aftertaste. Is not so good or oh it's too acidic, Oh the taste is it's good but it's maybe. Not perfect, so, they have their own internal. Critiquing. System, so. This is what you'll see with this part of the blockchain you'll. See who actually. This. Brian. Actually critiqued, it what was his final score and you see above that you know aroma, nine you know this is all out of ten nine out of ten acidity, eight out of ten flavor eight out of ten same, thing we have this original, document, to show this here. Okay. Again. Same. Same, thing you see Brian the, realm of the flavor we, have some more descriptors, like it tastes like blueberry, a little bit lime honey. Okay. So. The last part, that I want to show you is. This. Of this, actual. Your. Cup of coffee so. What we did at this it was this big food festival so, what happened is every cup had this barcode, on and basically. One use when, you buy it or buy a cup or you know go up to get a cup of coffee the. Barista, or the retailer. Will scan this cup and when, they scan the cup there just simply calling my rest day and they're posting to, the blockchain so they're saying look at, this exact time and date I've sold, this cup of coffee to this person and we, say you know I have, you. Know Brian, was, the one that sold it the. Drink was iced, coffee. Served. At this time we, have all this information and maybe. This, is not maybe, necessary, in a real war scenario but we thought this would be a good way to show some of additional, functionality, so. Now let, me show you the cloud service, running, so. This. Is the IBM blockchain, starter, plan so if, right now if you sign up you should get a month free to develop, so. Right now you'll see my channel. Right now I only have one channel if I wanted to create, different, channels, I can do that and basically.
I'll Have private. Transactions, within each channel so. It's almost like a blockchain within a block chain kind of this is what fabric, offers, so. Again we, have our blocks, here we, see the last, time is 50 minutes ago so I'll post a new cup and. In. A. Couple, seconds here you should see it posted to the block I so does. Anyone have a random. Number. Three. Digit number. What's. Six. Six okay I'll try that maybe. Not the best thing to do but I'll, put that in so. We. Should see this. New block being added so it should be 721. We, should see that 666. ID into, the blockchain now, and. Once I do this I get once it's successfully in, the blockchain I can query and I can show this relevant, details. So. Again you see this you. Know 15 seconds to the last transaction to 721 blocks in a second, here we should see the details, of this block. And. We. Should see that. 666. Number right here. So. Yeah you, can see it so now we can query the blockchain for, that specific. Number. So. You can imagine I have just gone got, my cup of coffee and say I go home and I say okay I want to see the history of where this cup of coffee came from so. Here I put in my cup, of coffee and a couple seconds we'll get all that detail, so, we'll get the, exact time so, it's today 1208, you, know this is the type of drink this. Is your cup ID and, the. Type of beams you have in the roaster and then. You have the full timeline after that like okay, this is where the cup came from but where did those beams actually, come from right and you have this timeline and. That's, exactly what I showed you previously is this history of exactly where the beam came from so. I'm. Running, out of time here but maybe. I'll show you one, more minutes of the code and. Then. I will be out, of here so. The last thing I'll show you is this, blockchain. Beam code so this is online I will give you the repo name at, the end so, I'll show you the code here. So. Again I think the most important. Part is the model, file so this is what we have here, we. Have are all of our different participants, I showed you we have the we, didn't talk about regulator, but we have grower trader, shipper retailer we. Have our cup of coffee this, is what I show you earlier we have the cup ID we have the drink type barista, this, is the schema for it and. Then you have this big batch of coffee where you have multiples, cups, of coffee coming from so. This is where you actually put the data. For. The, Fairtrade. Premium the packing, list the. Weight. Tally, this. Is where the conditions, come in and then the my favorite part is tasting, the cupping details how good, it tastes all right so. This is the coffee. Asset, the big batch and then. And what, I showed you earlier is this poor cup this transaction poor cup it just takes in a cup ID and it generates this time stamp for us right, and. That's. More or less it and that's, the schema and then the actual logic. Is is. Here. I. Can, show you a simple, one so. Basically all we do is we get, our actual. Coffee from the blockchain so we get this asset. Registry, as I showed you before is this composer, API and then, we just set all the fields, of the coffee so we set the invoice, number we, set the bill of landing number we, set the loader vessel and then after we create an event I didn't show that but at, the end we just update. And. That's pretty. Much it okay. So, I will. Leave you with that so here are all the all the, things I have just shown you the github are all here. If, you want my actual, if you have any questions here, is my contact. Info. And. Basically. What I showed you today is, how, to get, started with this hyper ledger fabric. So there's this local, open, source you. Can install on your computer test, locally but. You will not get this nice UI to, actually inspect, all these you can still do this inspection, but, you know we have this nice UI you can create, different. Channels, so. I've. Shown you the open source version I showed you a little taste of the cloud, version as well so, hopefully you understand, now this, data. Schema is really that, most. Important, part of creating this this network and then.
Basically Implementing, a few transactions, there on the network, so. I've shown you that I've shown you this a proof of concept we are built with Brooklyn roasting which, is taking some of their supply, chain data and for. The purpose of showing. All. Of their suppliers more, efficient, and streamlined process. To, show ok I this. Second I've received this document. We. Have shown exactly what, time we received it we've signed off on it so increasing, this transparency, for both the customers, and the suppliers and, then. Just for fun every, time we actually gave a cup of coffee we added on watching too so. Hopefully, you have learned at least something about typer ledger and thank, you so much for your time.