09 Building Dapps for private blockchain using Quorum

Learn Ethereum by Examples Part 3 Building Dapps for private blockchain using Quorum
31 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
This is a free item
$0.00
د.إ0.00
Kz0.00
ARS$0.00
A$0.00
৳0.00
Лв0.00
Bs0.00
B$0.00
P0.00
CA$0.00
CHF 0.00
CLP$0.00
CN¥0.00
COP$0.00
₡0.00
Kč0.00
DKK kr0.00
RD$0.00
DA0.00
E£0.00
ብር0.00
€0.00
FJ$0.00
£0.00
Q0.00
GY$0.00
HK$0.00
L0.00
Ft0.00
₪0.00
₹0.00
ISK kr0.00
¥0.00
KSh0.00
₩0.00
DH0.00
L0.00
ден0.00
MOP$0.00
MX$0.00
RM0.00
N$0.00
₦0.00
C$0.00
NOK kr0.00
रु0.00
NZ$0.00
S/0.00
K0.00
₱0.00
₨0.00
zł0.00
₲0.00
L0.00
QR0.00
SAR0.00
SEK kr0.00
S$0.00
฿0.00
₺0.00
$U0.00
R0.00
ZK0.00
Already have an account? Log In

Transcript

Hello, everyone, welcome to another session on Ethereum dev kit. So, today we are going to talk about building dap for a private blockchain okay. So, in this we will talk about a private blockchain called as Cora we then we are going to talk about how to set up the Corum environment. Then we are going to connect our truffle environment to utilize the current blockchain instead of using ganache or you know any other aetherium blockchain then we are going to do development and deployment of our project. Then finally, we are going to do the testing and ultimately there will be some takeaways from this session. Okay to get started.

In our previous sessions, we have developed and tested our application on Ethereum blockchain, that Ethereum blockchain was a local blockchain You know, we use local blockchain because we don't want to deploy our application on Main chain because that requires aetherium gas. And also, we don't want to do it on other test networks because, you know, that requires even some efforts from our side. Okay? Because those notes are, you know, test RPC notes. So instead what we did is we did our deployment or on the dash or test RPC, regardless of all these blockchains the the transactions which happened on aetherium blockchain, they are public in nature, meaning that if you have the account details, then you can trace what are the different transactions which happened over that account. And also, you can do transaction between any two accounts.

Okay, so there are no restrictions. As such inbuilt when it comes to aetherium public blockchain which may be desirable in you know most of the application but for some application that might not be desired environment Okay, we we may require some restrictions, some privacy for our transaction. So that's where the private blockchain comm comes into picture wherein that blockchain is deployed across certain nodes, okay. And then within those nodes, we can even put restriction that you know, only node one and five for example, you can communicate or do transaction for a particular account. And other nodes won't be able to view those transactions. And these sorts of privacy requirements are there in financial industries and it may be there in any any sort of application right?

So this private blockchains provide you that environment and one such private blockchain is Cora. So quorum is developed by JP Morgan. It is basically a fork of the Ethereum blockchain itself, with added features to provide enhance privacy on top of the tyrian blockchain, if you want to get more details about quorum, you can go to their GitHub page. And you can get more details about what quorum is and you know, how the whole core is organized. Okay. So they have a very good architecture diagram explaining the whole core project.

And as I mentioned, you know, it is built on top of aetherium. Along with this code, they also provide one example, which is what we are going to capitalize on for our preferred demo in today's session, Okay, so that is about Cora. So in order for us to set up the quorum environment, if you want to do it from scratch, you need to build the quorum code or install it from their executables in your environment. And after having Cora which, which is similar to an Ethereum blockchain, you need to set up multiple nodes because if you want to demonstrate the privacy across multiple accounts, you need to have at least two nodes, okay? In your blockchain, at least three nodes Okay, in your blockchain, so that you can see that the transactions are happening between two nodes only and the third node cannot do that transaction.

Okay. So here in our state Development Kit environment I already have the entire setup done the setup required to have done loads okay for Cora. And instead of you for you know putting all the efforts to set up the environment you will get it out of the box, all you need to do is just run one script which will start seven different nodes in our environment. Okay, so here let's get into our development kit. And you know retaining folder. Now you will see in our demos, there is that Corum example folder.

And here the Core M setup is done within this folder or there so you don't need to touch this folder. It will have the current blockchain installed over here and in examples, you have these seven nodes. So this is where the set of records barment for having a seven node core blockchain is is all the scripts and everything are put inside this folder. Okay, so the next thing we need to do is we need to run the script to start the server loads. Okay, so before we start Let me also give you some overview about those seven nodes. So those seven nodes, you will have this curator folder in this curator folder.

If you go inside, you will see these are the seven folder from the the one to DD server where you will have the data for each of the seven nodes. And then there is this log folder where you will see log for each of the node starting from one till server. And the other thing is our notes will be running the same notes. Okay the seven notes we'll be running from Double to triple zero, okay, so that's the starting Port 10 double two double 06 Okay. So these are the ports where our core nodes will be seven different nodes will be running. Okay.

So here I will open a terminal on this terminal, we will get into our current folder. So, do cd dekstop ADM demos or an example not here we'll get into the example folders, seven loads okay. And if we do LS here you will see there are the the this is the script for care of hypertension Got assets, this will start all the seven nodes. Before we start, I will do a net stat. Okay, we will do double to double zero. Okay, so there is nothing running on this port, double two double zero.

Okay, so there's nothing running at this point. Now here we go, I will start. This is going to start that seven nodes okay. And here you will see this message all nodes configured. Okay, if you want to see the logs, here is the log which, which I just showed you for the folder very you can get the logs. Okay, so now that our quorum nodes are up and running next thing we need to do is we need to go to our Coromant sample folder okay which is there on the desktop.

And here we are going to create our truffle project. So here I am going to create one folder. I will call it as my project. So MK dir my project, CD to my project. And then we are going to do a truffle in it or here. So this truffle in it will create the directory structure we need for our project with all the boilerplate, okay with the migration contract the script for migrating that contract and everything.

Okay, the next thing I'm going to do is I'll open this in our Visual Studio, okay. And then we need to point our projects To our code on blockchain instead of pointing it to the default test RPC blockchain, okay. And as I told you, our core, blockchain is consisting of seven different nodes and those nodes are running on double to triple zero from double to triple 02, double two double 06. Right. So we need to go to our truffle.js. And here we need to configure truffle.js to point to our project, our core blockchain.

Okay, now, as always, we have all the configuration and coding files available to us in our example folder. So let's go back to our aetherium. We have the demo solution, for example, and he Here I have this truffle.js it has all the configuration to point to our core blockchain. So, now what we are going to do is we are going to have truffle orange or use three different nodes okay. So, the objective of this project is to create one contract that contract we will deploy on two nodes and then we are going to do the testing to see if the deployed contract is available through the two nodes where it is deployed and it is not available through the third node okay where it is not deployed. So, the node where we are going to do the development, we will call that load as development node.

Okay. It is running on our localhost, but the Double 03 double to triple zero okay so this is the first node the second node where we are not going to deploy the contract and we will test that the contract is not available. So that node will be the fourth node okay. We are going to refer that node as node four okay. It is running on double two double 03 and the second node where we are going to deploy the contract is node seven, it is running on double two double 06 Okay. So, what we are going to do is we are going to copy this configuration, put it in our project.

So, now our project can deploy the contract on any of these three nodes of core. Okay, so I hope this this point is clear. Okay, so we mentioned three different nodes, but we are going to do the deployment or only two nodes, the third node, we have it for the testing purpose. Okay? Right. So now the other thing we need to do is we need to create the contract for the testing purpose.

So here I will go and say new file. And I will name this file as simple storage dot song, solidity file. And again, we have the code already with us. So we go back to our solution folder, go to contracts, open the simple storage file and copy paste it into the file I just created. And again, here, the logic is very simple. We have one public variable, we call it as store data.

That when we are going to initialize the contract, we will pass some random value to that and that value will get assigned to this variable okay and then we have that setter and getter method on the variable okay. So, the logic we are going to put is we are going to deploy this contract while deploying the contract we will set some initial value okay and after that we are going to deploy this on our development node and node seven All right, and then we are going to do the testing. So, while doing the testing, we will see that when we invoke the contract from the fourth node, where it is not deployed, we are not going to get any value from stored data because the contract is not you know, accessible Okay, so the contract is accessible only from node node zero, okay, the development node and node server okay So, this is a very simple contract not much of business logic or there.

So just to demonstrate the core concept we have this contract. The next thing we are going to do is we are going to deploy this contract. Okay. So I will go back to the command prompt. And here I will do combined. Okay, so it is compiled, and now I need to do the migration.

But before we do the migration we need to create the migration script. So, here in the migration folder, I create a new file. We're going to call it as to underscore integration In this I need to rename it as a JavaScript file. And here again, you know, I will go to our solution folder or copy, no migration script. And this script is again a straightforward script, it will just take our contract and deploy it on the blockchain. But there is a very important difference between this deployment script and the other scripts we have seen so far.

So in other scripts, all we do is we use the deployed or deploy function and deploy the contract on the blockchain which is configured in our truffle dot j s. Okay, but this time around We are not only deploying the script, we are also passing some initial value, which is going to set the value of the variable. Because in our contract we have one constructor, right that constructor is taking some initial value assigning it to store data. So, this script will initialize the contract with this initial value of 42. And also you see this Okay, this this data we are passing okay while doing the deployment. So here is where quorum differs from aetherium blockchain so quorum has this capability wherein you can provide an extra parameter called private for and in the private for, you can specify the address of the load where you want to make this contract to be private.

Okay? So what it means is when this is getting deployed this contract will be accessible only to the node whose address we have provided over here. So this points to our node seven, okay. So, this is the address this is hard coded over here because in our setup, this is the value which is been provided to load seven server. So this is the distinction between the public aetherium blockchain and the quorum blockchain reading quorum provides you this facility wherein you can make your transaction private, between you know, two or more nodes. Okay.

All right. So we have the migration script with us. The next thing we need to do is we need to run the migration. Okay, so now when we are migrating it, by default it will take the development mode because we haven't specified find any particular nodes it will take the development node, it will deploy that contract on the development node and it will make that contract accessible only to the seventh node because we mentioned that address in that deployment script. Okay. So our deployment is successful contract is deployed.

The next thing we are going to do is we are going to do the testing and the way we are going to do the testing is first we connect to our development environment. Okay and try to get the value of our deployed contract the instance variable value, Okay, next we are going to connect to node four and see the value and finally we will connect to node seven. We are going to see the value okay. So far that we can use truffle contract So, from this will connect to it will open the truffle console and it will have connectivity to one of the nodes okay. And you will see here in the console, it is connected to development why because development is the first entry in our preferred org. So by default if you don't specify which node you want to which network you want to connect to by default it will connect to the first one.

So here it is connected to development. And now we will query our contract variable. Okay, so for that also, I have the test command. You can open this file, test command file, just copy this command into the terminal. just paste it here okay. All it is doing is it is calling the if it is it is taking if the simple storage contract is deployed or not.

If it is deployed, then it will get a call back with the instance ID, and it is going to return the instance job to get Ok, which will then return the value of the variable we have over here in our contract. Okay, so here the get will, this function will return them, store data variable value. And if you remember when we did the deployment through our migration script, we initialize the value of the variable while calling the constructor with 42. So, let's see what happens. As soon as I hit Enter, I get that variable value 42 over here okay. Alright, and also remember one thing when we did the migration, we did not specify which node we want to migrate.

So by default it got deployed on that development node, okay. And in the deployment script, we did mention that this should be private to the this this note which is not safe. Okay. So what I will do is I will do an exit from our development node by dot exit, clear the screen. And now, we will open the truffle console again, but this time around, we are going to connect to node four. Okay, so how are we going to mention that we want to connect to node four, we need to pass this parameter or network and we need to give the name we mentioned in our truffle dot j s which was not for Okay, so truffle query the node.js file, check the configuration for node four and it will connect to that four.

Okay, so now I'm connected to node four, I will run the same query again. Not sure if I close the front yet we have a fight here. And now you will see that if I run this on what for, I don't get an evaluator. Okay, so it says zero over here. Okay, so the value returned is zero. That means you know, you don't have this accessible from node four.

And now I will exit from here. So and now we are going to connect to the Load saver and I will run the same command and now you will see that on node saver on note seven we will have some value for our contract the same value. Okay, so here you will see again, it says 42 okay, right. So this is the demonstration of how we can utilize the private chain code to deploy our contract and have privacy in the transaction. Okay, now, I will exit from here and we'll do one more test in this test. What I am going to do is I'm going to create another contract.

That contract is going to update the value from 42 to some other value. And then again, we are going to do the same test from our development mode. Note four and note seven. And you will see that the change in value is reflected only when we run or query the contract from the development node and node server. Okay, so let's go back and I will create a file. Okay at the top of the project right here.

Click New File. Storage test.js. Okay, sorry, by the way, this is not a contract. This is just a JavaScript file. And that file has logic for creating our contract and updating the value of the field. Okay, so here again Have that file sample TX copy this file and what I'll do is for the purpose of having consistency I will rename this value to the SIR TX dot start yes okay the same name as we have it in the solution and I will copy this okay.

So this is just a JavaScript function which all it does is it takes simple storage is deployed or not if it is deployed then it gets a callback with the instance of the contract and on that instance we are calling the set function providing the value okay. And again the private for a parameter, okay which will make it private between node one node one which is development node and node server. Okay and then it will be print some log, okay, so we can run this. So now this is just a simple JavaScript file with some some code which invokes the contract, okay. Now how can we do the testing of this? So for that we have drop truffle efcc Okay, execute.

So I can use truffle, etc. Okay this come up and we are going to give the name of the file. Let's run this, it is going to them run the transaction on the deployed contract. And it will say transaction is finished setting value to 65. Okay, and this is that transaction hash. Okay, now we can go back to our truffle console, and run those commands to check the value again.

So I will say truffle console. If I don't provide the net value, it will connect to the development node. I will copy the command again from the test command dot txt, paste it here and now you should see the value 65 because our sample tx.js has updated the value and it is reflected on the development node. I will exit for here we'll connect to node four. I will run the same command again to copy it again. Now here it says zero, okay because it's not accessible or not Before we go to node seven let me copy the URL and insert it here and you see 65 Okay.

So now the value is updated for the contract variable and it is accessible, it is reflected only on load one and flow server. Alright. So this is the session. This concludes the session. So, the takeaways from this session is that it TDM is a blockchain but, you know, the transaction on that blockchain are publicly available in case you want to have privacy in your transaction, you can use core blockchain developed by JP Morgan. So, this is one takeaway.

The second takeaway is aetherium is not the only blockchain where you can deploy your contracts any other blockchain, which is a fork of aetherium. Your contracts can be deployed on that blockchain as well, as long as those blockchain are compatible with aetherium. And when you deploy it on those blockchain, which are called private blockchain, you will get all the features of Ethereum blockchain. On top of that, the private blockchain will have their own specific features, which then you can capitalize on. In our case, we use Cora and Cora was having the privacy feature on top of it, so we were able to use that. So this private blockchains are also you know, very rapidly growing each and every field, you know, verticals.

The developing their own private blockchains based on aetherium, you might have heard of the enterprise aetherium. Consortium, which is called an enterprise aetherium. Alliance, where you have a lot of companies on boarded on that Alliance. And those companies are collaborating together to develop private blockchains for a specific industry, for example, you know, healthcare or finance and whatnot. And they're the contracts will be deployed and executed with the additional features of that particular blockchain. So I hope this session is useful for you to understand, you know, what are private blockchains and how we can use such blockchains in, in in this session.

So, that concludes the session for today. Have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.