Use blockchain, like a cloud user, using kaleido
Tags: hyperledger, fabric, cloud, kaleido
Published: 2022-04-04 22:43:08


Hyperledger fabric is very great to use. It gives the users the ability to customize their networks and is more performant and private. All great features to have for enterprise applications. 


All of this, however, comes out at the cost of simplicity. Bringing up a simple network can be daunting when considering the number of arguments you have to consider and how you have to handle authentication at each step. 

This is all good when customizing the network with very complex rules and complex authentication certificates, but this might become a headache when building an MVP. 


Here is where Kaleido comes in. This platform can set up your structure with a user-friendly UI and gives you REST APIs that have default options that you can use to quickly set up your network programmatically without handling things like authentications yourself. 

In this tutorial, we will go through the basics of using Kaleido. 

Kaleido can be divided into three main sections: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09q3m16ij3r7namjwz10.png)
 
- Network or consortia: this is the network of organizations that work together or your business network; it might be a little bit confusing with fabric network, which we will see next. But the key takeaway is that this network is your business network and not your fabric network.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6w3gccip066k4d4afyu.png) 
    - Here we can define apps. Apps are used for defining chain codes. Notice that at this point, we are only defining apps so that all organizations in our business network can see them, but they have not yet been deployed to fabric networks.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yqtvv2c0zjrjutyk9bze.png) 
- Environments. This is where the actual fabric networks are defined.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv2rcmnpqnwg3cnmszg2.png)
 
  Here we can define hyperledger networks. So you can deploy channels and promote your chain codes here (which is other words, for sending in your chain code to fabric networks).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu6uy27nobh6r47mjsn5.png) 
    - Before moving forward with anything, you will need to have an orderer node and a peer node. These will allow you to submit things as an organization and make your API calls, respectively. 

- Once your environment is ready, you can make your channel (there is a default one created for you) and promote chain codes to environments.
    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4lmqujo1ydvsx436sc0h.png)
    - You can upload chain code by clicking on the "Create new version", then you need to run `GOOS=linux GOARCH=amd64 go build -o output.bin` and upload the output.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9vvlc8vips8sb2asj2i.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pm323copyetgh44ojdm2.png) 
    - You can then promote your uploaded version to an environment that gives you the ability to deploy your chain code to channels. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0qnslsm24b7g01ji9u9.png) 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmbw22jnpvhqetdhnm6o.png) 
Once all this setup is done, you can access your APIs through the peer node.

# Now we will talk about how to run your chain code from the API

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgxtakkbmz98t5346g3b.png)
 

You should use a post request to /identities to create a new user to make your calls your transaction calls with.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fw72z44oo4jk6wyoyro.png)
 

Then you can use the secret information you have gained alongside a post-call to /identities/{username}/enroll to enroll your client. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4zher2pxot1wo9x20ff.png)
 

Once that is done, you can make your transactions by your chain code using post calls to /transactions. For the signer option, you can use the client's name that you just made. And for arguments, you can pass the string of all the arguments you want to use. Please note that if you want to get the final result of your transaction instead of the link to the receipt, you should set fly-sync to true. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kfjbgf8rqovixp7sua8.png) 
You can use the same values alongside a post-call to /query for querying.

Now, if you are wondering how to do the following automatically, it is straightforward as long as you follow the following two concepts.

- For everything we did outside the peer node, you can find their API at https://api.kaleido.io/platform.html. However, for using these APIs, you will need access to your Bearer authentication, which can be found under your user profile under https://console.kaleido.io/profile under API keys. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0pmt66mvdxmqylhueqy.png) 
- For all the APIs that we used in the peer node, we need to create an application credential that is based on the environment. Please note that once you create the credential, you will be given one-time access to your username and password and links on how to connect to the peer node API while being authenticated. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7y9r3rn6u4oenba6r4d.png)
(Please keep your secrets safe and don't share their screenshots XD ... unless you are deleting them afterward)
 

Using all of this, you should be able to create networks fast, deploy them with ease, and handle most of your logic programmatically. 

# Limits 
Kaleido currently does not support customized policies for validation within the channel. However they are working on that, but for the time being, you should consider that the validation of your transactions is done through the majority vote or more than half of the organizations within your channel. 

# Going decenterlized
Once you are sure of your network and have tested your logic, you can add more organizations to the Kaleido network, allowing them to add their own node or have self-hosted instances; however, that requires you to at least have a business plan with Kaleido.

# Conclusion
Kaleido is a helpful platform for starting out with fabric and testing out new ideas quickly. However, it is a new platform that you need to learn to work with, although there is a good amount of documentation and tutorials for the platform.


I hope this post has been helpful and if you have any more questions checking Kaleido's youtube channel and documents is always very helpful.