-
Notifications
You must be signed in to change notification settings - Fork 1
/
07-install-contract.js
27 lines (23 loc) · 1017 Bytes
/
07-install-contract.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
const Client = require('fabric-client');
const fs = require('fs-extra');
const certificate = fs.readFileSync('./local_fabric/certificate', 'utf8');
const privateKey = fs.readFileSync('./local_fabric/privateKey', 'utf8');
(async () => {
try {
const serializedPackage = await fs.readFile('[email protected]');
const client = new Client();
await client.setAdminSigningIdentity(privateKey, certificate, 'Org1MSP');
const peer = client.newPeer('grpc://localhost:17051');
const txId = client.newTransactionID(true);
const [proposalResponses] = await client.installChaincode({ chaincodePackage: serializedPackage, targets: [ peer ], txId });
for (const proposalResponse of proposalResponses) {
if (proposalResponse instanceof Error) {
throw proposalResponse;
}
}
console.log('Installed contract onto peer');
} catch (error) {
console.error(error);
process.exit(1);
}
})();