首页 > 解决方案 > 使用节点 sdk 在超级账本结构上升级链码

问题描述

我正在尝试使用来自 hyperledger 结构的 node-sdk 安装和升级链代码。但是我似乎遗漏了一些东西。

我能够在对等方上正确安装链代码,但是我无法升级它。我缺少某种 transactionId

基本上,我想使用 sdk 能够执行以下操作:

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"]}'

使用 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: ??????? <----------------------------------
});

我错过了什么?

标签: node.jshyperledger-fabrichyperledger

解决方案


为了将来参考,我失踪了client.newTransactionID()

完整示例

// 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);

推荐阅读