Guest User

Untitled

a guest
Jan 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. const Client = require('fabric-client');
  2. const myClient = require('./index.js');
  3. var await = require('await')
  4. const fs = require('fs');
  5. const path = require('path');
  6.  
  7. const org1 = 'org1';
  8. const org2 = 'org2';
  9. const org3 = 'org3';
  10.  
  11. const ORG1_ADMIN_MSP = './crypto-config/peerOrganizations/org1.ksachdeva-exp.com/users/Admin@org1.ksachdeva-exp.com/msp';
  12. const ORG2_ADMIN_MSP = './crypto-config/peerOrganizations/org2.ksachdeva-exp.com/users/Admin@org2.ksachdeva-exp.com/msp';
  13. const ORG3_ADMIN_MSP = './crypto-config/peerOrganizations/org3.ksachdeva-exp.com/users/Admin@org3.ksachdeva-exp.com/msp';
  14.  
  15. const ORG1_MSP_ID = 'Org1MSP'
  16. const ORG2_MSP_ID = 'Org2MSP'
  17. const ORG3_MSP_ID = 'Org3MSP'
  18.  
  19. const CHANNEL_NAME = 'ksachdeva-exp-channel-1'
  20. const CHAIN_CODE_ID = 'ksachdeva-exp-cc'
  21.  
  22. async function instantiateChaincodeOnPeers(orgn, adminmsp, mspid) {
  23.  
  24. const client = await myClient.getClient(orgn, adminmsp, mspid);
  25. const orderer = await myClient.getOrderer(client);
  26.  
  27. console.log('Creating a Channel object ..');
  28. const channel = client.newChannel(CHANNEL_NAME);
  29.  
  30. console.log('Specifying the orderer to connect to ..');
  31. channel.addOrderer(orderer);
  32.  
  33. console.log('Getting the peers ..');
  34. const peers = await myClient.getPeers(client, orgn);
  35.  
  36. peers.map(p => channel.addPeer(p));
  37.  
  38. console.log('Initializing the channel ..');
  39. await channel.initialize();
  40.  
  41. console.log('Sending the Instantiate Proposal ..');
  42. const proposalResponse = await channel.sendInstantiateProposal({
  43. chaincodeId: CHAIN_CODE_ID,
  44. chaincodeVersion: 'v0',
  45. fcn: 'init',
  46. args: ["a", "100", "b", "200"],
  47. txId: client.newTransactionID()
  48. });
  49.  
  50. console.log(proposalResponse);
  51.  
  52.  
  53. // console.log('Sending the Transaction ..');
  54. // const transactionResponse = await channel.sendTransaction({
  55. // proposalResponses: proposalResponse[0],
  56. // proposal: proposalResponse[1]
  57. // });
  58.  
  59. }
  60.  
  61. async function main() {
  62. await instantiateChaincodeOnPeers(org1,ORG1_ADMIN_MSP,ORG1_MSP_ID);
  63. }
  64.  
  65. main();
Add Comment
Please, Sign In to add comment