Trying to use example code to use ibm-blockchain-js.
my sample code:
// Starting out by requiring all dependancies
var Ibc = require ('ibm-blockchain-js');
var ibc = new Ibc();
// Then define new instances that will be needed
var chaincode = {};
// configure ibc-js sdk by defining options
var options = {
network:{
peers: [{
"api_host": "864acfab0a734673a4f99844a8b02129-vp0.us.blockchain.ibm.com",
"api_port": 444,
"api_port_tls": 444,
"id": "864acfab0a734673a4f99844a8b02129-vp0",
"api_url": "http://864acfab0a734673a4f99844a8b02129-vp0.us.blockchain.ibm.com:444"
}],
users: [{
"username": "user_type1_1",
"secret": "2b19ed2755",
"enrollId": "user_type1_1",
"enrollSecret": "2b19ed2755"
}],
options:{
quiet: false,
timeout: 60000
}
},
chaincode:{
zip_url: 'https://github.com/ibm-blockchain/marbles/archive/v1.0.zip',
unzip_dir: 'marbles-1.0/chaincode/part1',
git_url: 'http://gopkg.in/ibm-blockchain/marbles.v1/chaincode/part1',
deployed_name: null
}
};
// Load the Marbles1 chaincode, with defined options, and return call-back-when-ready function.
ibc.load(options, cb_ready);
// Define the call-back-when-ready function returned above
// call-back-when-ready function has err
function cb_ready(err, cc){
//response has chaincode functions
//app1.setup(ibc, cc);
//app2.setup(ibc, cc);
// if the deployed name is blank, then chaincode has not been deployed
chaincode = cc;
if(cc.details.deployed_name === null){
cc.deploy('init', ['99'], null, cb_deployed);
}
else{
console.log('chaincode summary file indicates chaincode has been previously deployed');
cb_deployed();
}
}
// Step 5 ==================================
function cb_deployed(err){
console.log('sdk has deployed code and waited');
//chaincode.query.read(['a']);
chaincode.invoke.init_marble("marble1", "blue", "35", "mdonthi", cb_invoked);
}
function cb_invoked(e, a){
console.log('response: ', e, a);
}
logs looks like:
ibc-js] Peer: 864acfab0a734673a4f99844a8b02129-vp0-864acfab0a73...:444
[ibc-js] Registering 864acfab0a734673a4f99844a8b02129-vp0-864acfab0a73...:444 w/enrollId - user_type1_1
[https POST - b] /registrar
body: {"enrollId":"user_type1_1","enrollSecret":"2b19ed2755"}
[https POST - b] Status code: 200
[ibc-js] Registration success x1 : user_type1_1
[ibc-js] removing temp dir
[ibc-js] Downloading zip
redirect... https://codeload.github.com/IBM-Blockchain/marbles/zip/v1.0
[ibc-js] Downloading zip
[ibc-js] Unzipping zip
[ibc-js] Unzip done
[ibc-js] Scanning files [ 'part1_chaincode.go' ]
[ibc-js] Parsing file for shim version
[ibc-js] Found shim version: github.com/hyperledger/fabric/core/chaincode/shim
[ibc-js] Parsing file for invoke functions - part1_chaincode.go
[ibc-js] Found cc invoke function: init
[ibc-js] Found cc invoke function: delete
[ibc-js] Found cc invoke function: write
[ibc-js] Found cc invoke function: init_marble
[ibc-js] Found cc invoke function: set_user
[ibc-js] Parsing file for query functions - part1_chaincode.go
[ibc-js] Found cc query function: read
[ibc-js] load_chaincode() finished
[ibc-js] Deploy Chaincode - Starting
[ibc-js] function: init , arg: [ '99' ]
[https POST - m] /chaincode
body: {"jsonrpc":"2.0","method":"deploy","params":{"type":1,"chaincodeID":{"path":"http://gopkg.in/ibm-blockchain/marbles.v1/chaincode/part1"},"ctorMsg":{"function":"init","args":["99"]},"secureContext":"user_type1_1"},"id":1478646962678}
[https POST - m] Status code: 200
deploy success [waiting another 45 seconds]
5836a766abb5f6585af53aebeba3be92153f991b7406456c98cf03313e0f27325d59bacaaf3ad2b76a05e6b80789ed6bb570fd17ef16e9ac6487f268f6f25b26
[ibc-js] Deploy Chaincode - Complete
sdk has deployed code and waited
[https POST - e] /chaincode
body: {"jsonrpc":"2.0","method":"invoke","params":{"type":1,"chaincodeID":{"name":"5836a766abb5f6585af53aebeba3be92153f991b7406456c98cf03313e0f27325d59bacaaf3ad2b76a05e6b80789ed6bb570fd17ef16e9ac6487f268f6f25b26"},"ctorMsg":{"function":"init_marble","args":"marble1"},"secureContext":"blue"},"id":1478647016573}
[https POST - e] Status code: 400
[https POST - e] Error - status code: 400 {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Error unmarshalling chaincode request payload: json: cannot unmarshal string into Go value of type []string"},"id":null}
[ibc-js] init_marble - failure: 400 { jsonrpc: '2.0',
error:
{ code: -32700,
message: 'Parse error',
data: 'Error unmarshalling chaincode request payload: json: cannot unmarshal string into Go value of type []string' },
id: null }
/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/index.js:914
if(cb) cb(helper.eFmt('invoke() error', statusCode, e), null);
^
TypeError: cb is not a function
at Object.options.failure (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/index.js:914:12)
at failure (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/lib/rest.js:119:30)
at IncomingMessage. (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/lib/rest.js:209:5)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)