var http = require('http');
var pb = require("protobufjs");

var builder = pb.loadProtoFile("./appinit.proto"),
    app = builder.build("appinit");

function Deploy(id, params) {

    var post_data = JSON.stringify({
        'jsonrpc': '2.0',
        'method': 'deploy',
        'params': {
            'type': 1,
            'chaincodeID': id,
            'ctorMsg': {
                'function':'init',
                'args':[new app.Init(params).toBase64()]
            }
        },
        "id": 1
    });
    console.log(post_data);
    post(post_data, '/chaincode',function(body) {
        var resp = JSON.parse(body);
        console.log(resp.result.message);
    });
}

function post(pdata, path) {
    var post_options = {
        host: 'localhost',
        port: '3000',
        path: path,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    };

    var post_req = http.request(post_options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('Response: ' + chunk);
        });
    });

    // post the data
    post_req.write(pdata);
    post_req.end();

}

Deploy(
    {
        'name': 'mycc'
    },
    {
        'partyA': {
            'entity': 'foo',
            'value': 100
        },
        'partyB': {
            'entity': 'bar',
            'value': 100
        }
    }
);

@@ -75,109 +75,1177 @@
  pb.
-loadProtoFile(%22./appinit.proto%22),%0A    app = builder.build(%22appinit%22);%0A%0Afunction Deploy(id, params) %7B%0A
+newBuilder(%7B convertFieldsToCamelCase: true %7D);%0A%0Apb.loadProtoFile(%22./appinit.proto%22, builder);%0Avar init = builder.build(%22appinit%22);%0A%0Apb.loadProtoFile(%22./org.hyperledger.chaincode.example02.proto%22, builder);%0Avar app = builder.build(%22org.hyperledger.chaincode.example02%22);%0A%0Afunction Deploy(id, params) %7B%0A%0A    invoke('deploy', id, 'init', new init.Init(params), function(res) %7B%0A        res.setEncoding('utf8');%0A        res.on('data', function (chunk) %7B%0A            var resp = JSON.parse(chunk);%0A            console.log('Response: ' + chunk);%0A        %7D);%0A%0A    %7D);%0A%7D%0A%0Afunction CheckBalance(id, params) %7B%0A%0A    invoke('query', id, 'org.hyperledger.chaincode.example02/query/1', new app.Entity(params), function(res) %7B%0A        res.setEncoding('utf8');%0A        res.on('data', function (chunk) %7B%0A            var resp = JSON.parse(chunk);%0A            if (resp.result.status == %22OK%22) %7B%0A                var result = app.BalanceResult.decode64(resp.result.message);%0A                console.log(%22BalanceResult: %22 + result.balance);%0A            %7D else %7B%0A                console.log('ERROR: ' + chunk);%0A            %7D%0A        %7D);%0A%0A    %7D);%0A%7D%0A%0Afunction invoke(method, id, func, args, cb) %7B
 %0A   
@@ -1322,24 +1322,22 @@
 ethod': 
-'deploy'
+method
 ,%0A      
@@ -1370,17 +1370,17 @@
 'type': 
-1
+3
 ,%0A      
@@ -1456,22 +1456,21 @@
 nction':
-'init'
+ func
 ,%0A      
@@ -1491,28 +1491,12 @@
 s':%5B
-new app.Init(params)
+args
 .toB
@@ -1618,109 +1618,11 @@
 de',
-function(body) %7B%0A        var resp = JSON.parse(body);%0A        console.log(resp.result.message);%0A    %7D
+ cb
 );%0A%7D
@@ -1648,16 +1648,20 @@
 ta, path
+, cb
 ) %7B%0A    
@@ -1908,163 +1908,10 @@
 ns, 
-function(res) %7B%0A        res.setEncoding('utf8');%0A        res.on('data', function (chunk) %7B%0A            console.log('Response: ' + chunk);%0A        %7D);%0A    %7D
+cb
 );%0A%0A
@@ -2210,8 +2210,94 @@
    %7D%0A);%0A
+%0ACheckBalance(%0A    %7B%0A        'name': 'mycc'%0A    %7D,%0A    %7B%0A        %22id%22: %22foo%22%0A    %7D%0A);%0A

Develop the client further