forked from IBM-Blockchain-Archive/marbles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instantiate_chaincode.js
43 lines (39 loc) · 1.71 KB
/
instantiate_chaincode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var winston = require('winston'); //logginer module
var path = require('path');
// --- Set Our Things --- //
var logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.Console)({ colorize: true }),
]
});
var helper = require(path.join(__dirname, '../utils/helper.js'))('marbles1.json', logger); //set the config file name here
var fcw = require(path.join(__dirname, '../utils/fc_wrangler/index.js'))({ block_delay: helper.getBlockDelay() }, logger);
console.log('---------------------------------------');
logger.info('Lets instantiate some chaincode -', helper.getChaincodeId(), helper.getChaincodeVersion());
console.log('---------------------------------------');
logger.warn('Note: the chaincode should have been installed before running this script');
logger.info('First we enroll');
fcw.enroll(helper.makeEnrollmentOptions(0), function (enrollErr, enrollResp) {
if (enrollErr != null) {
logger.error('error enrolling', enrollErr, enrollResp);
} else {
console.log('---------------------------------------');
logger.info('Now we instantiate');
console.log('---------------------------------------');
var opts = {
peer_urls: [helper.getPeersUrl(0)],
path_2_chaincode: 'marbles', //same path used to install it
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId(),
chaincode_version: helper.getChaincodeVersion(),
cc_args: ['12345'],
peer_tls_opts: helper.getPeerTLScertOpts(0)
};
fcw.instantiate_chaincode(enrollResp, opts, function (err, resp) {
console.log('---------------------------------------');
logger.info('Instantiate done. Errors:', err);
console.log('---------------------------------------');
});
}
});