Reputation: 2137
I am trying to install & upgrade a chaincode using the node-sdk from hyperledger fabric. However I seem to be missing something.
I am able to install the chaincode correctly on the peers, however I am unable to upgrade it. I am missing a transactionId of some kind
Basicly, I'd like to use the sdk to be able to do the following:
peer chaincode install -n mychaincode -p /path/to/chaincode -l node -v 0.0.2
peer chaincode upgrade -C mychannel -n mychaincode -l node -v 0.0.2 -c '{"Args": ["instantiate", "test"]}'
Using the sdk:
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: 'xxxx' });
const client = gateway.getClient();
const peers = client.getPeersForOrg('PeerMSP');
let installResponse = await client.installChaincode({
targets: peers,
chaincodePath: '/path/to/chaincode',
chaincodeId: 'mychaincode',
chaincodeVersion: '0.0.2',
chaincodeType: 'node',
channelNames: ['mychannel']
});
let channel = client.getChannel('mychannel');
let upgradeResponnse = await channel.sendUpgradeProposal({
targets: peers,
chaincodeType: 'node',
chaincodeId: 'mychaincode',
chaincodeVersion: '0.0.2',
args: ['instantiate', 'test'],
txId: ??????? <----------------------------------
});
What am I missing ?
Upvotes: 0
Views: 898
Reputation: 2137
For future reference, i was missing client.newTransactionID()
.
Full example
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: 'xxxx' });
const client = gateway.getClient();
const peers = client.getPeersForOrg('PeerMSP');
let installResponse = await client.installChaincode({
targets: peers,
chaincodePath: '/path/to/chaincode',
chaincodeId: 'chaincode',
chaincodeVersion: '0.0.2',
chaincodeType: 'node',
channelNames: ['mychannel']
});
let channel = client.getChannel('mychannel');
let proposalResponse = await channel.sendUpgradeProposal({
targets: peers,
chaincodeType: 'node',
chaincodeId: 'chaincode',
chaincodeVersion: '0.0.2',
args: ['test'],
fcn: 'instantiate',
txId: client.newTransactionID()
});
console.log(proposalResponse);
console.log('Sending the Transaction ..');
const transactionResponse = await channel.sendTransaction({
proposalResponses: proposalResponse[0],
proposal: proposalResponse[1]
});
console.log(transactionResponse);
Upvotes: 4
Reputation: 895
Whenever you upgrade a chaincode you need to change its version. I see you are using the same version 0.0.2
for both the commands. Plz change that and check.
peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 0.0.3 -c '{"Args":["init","a","100","b","200","c","300"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
Upvotes: -2