Using kaleido to spin your private Ethereum Blockchain

Using kaleido to spin your private Ethereum Blockchain

If you are a developer looking to build same cool Dapps on Blockchain then you can use Ganache (TestRPC) to create & test smart contracts from your local machine. But, if you want to take it to next level and want to test you contracts on a private ethereum blockchain then Kaleido is the best option. Most of the public cloud providers provide templates for spinning private ethereum blockchain instances but they are costly. I will try to guide you through creating your own blockchain consortium and environment through this article.

homepage
Move to next step by clicking on "GET STARTED" or "Try the Beta"

registration
Complete your registration

createconso
Create consortium after filling the name and the objective.

addmenu
Create environment for the consortium. For now, create a 'Development' environment.

devdtls
You will reach this screen once you select the active environment, 'Development' in this case. Select number of nodes you want, I would suggest just one for now. Create APP Credentials. Make sure you keep the ID & Password in a safe place. You will need these credentials to connect to blockchain from the app.

By clicking on the menu at the "Ether Pool" under SERVICES, you can select "Fund Account" to reach the below screen.

fundacct
You can start transferring ethers to the accounts that you have created through this option. You can create accounts by using the NodeJS Code below.

const express = require('express');
const app = express();
const Web3 = require('web3');
const http = require('http');
let web3 = new Web3();

web3.setProvider(new web3.providers.HttpProvider(<your RPC will go here>,0,<ID from App credentials>,<Key from App Credentials>));

let nodeVersion = web3.version.node;

app.use(function(req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
	next();
  });
app.get('/getbalance', (req1, res1) => {
	web3.eth.getBalance(req1.query.acctid, function(error, result) {
		if (!error) {
			res1.send(web3.fromWei(result,'ether'));
		} else {
			console.log('error');
		}
	
	});
});


app.get('/accts', (req1, res1) => {
	web3.eth.getAccounts(function(error,result){
		//console.log(result);
		res1.send(result);
	})
});

app.get('/cacct', (req1, res1) => {
	web3.personal.newAccount('test', function(error,result){
		console.log(result);
	})
});


app.listen(3201, () => console.log('Example app listening on port 3201!'))

Simple NodeJS Code above interacts with the blockchain you created. Remember to replace the credentials in the line 6.

Kaleido is relatively new service and is in Beta. I don't think it is a good idea to push any production ready code / smart contract yet on to Kaleido.