![](/img/trans.png)
[英]How to install chaincode using fabric sdk (fabric-client)?
[英]How to assign identity to fabric-client instance?
我無法使用fabric-node-sdk安裝節點chaincode。
我收到以下錯誤:
installChaincode錯誤沒有將此客戶端分配任何標識
我正在使用以下腳本
const Client = require("fabric-client");
const path = require("path");
const os = require("os");
const client = new Client();
const deploy = async () => {
const connectionOpts = {
name: "peer1",
"request-timeout": 7000,
pem: path.resolve(
os.homedir,
"/fabric-samples/chaincode-docker-devmode/msp/signcerts/peer.pem"
),
"ssl-target-name-override": "peer"
};
const peer = client.newPeer("grpc://172.18.0.3:7052", connectionOpts);
const request = {
targets: peer,
chaincodePath: path.resolve(
os.homedir + "/fabric-samples/chaincode/chaincode_example02/node"
),
chaincodeId: "myc",
chaincodeVersion: "v0",
chaincodeType: "node"
};
const result = await client.installChaincode(request, 6000);
console.log(await result);
};
deploy();
如何為客戶分配身份?
在文檔中,沒有演示需要什么參數以及如何分配標識。
對等節點想知道誰在進行交易。 在安裝chincode事務之前嘗試使用此方法:
client.setAdminSigningIdentity(private_key, certificate, mspid)
哪里:
private_key :私鑰PEM字符串
certificate :PEM編碼的證書字符串
mspid :本地簽名身份的成員服務提供者ID(即“ Org1MSP”)
在chaincode安裝請求中,您需要txId:
client.setAdminSigningIdentity(private_key, certificate, mspid)
const request = {
targets: peer,
chaincodePath: path.resolve(
os.homedir + "/fabric-samples/chaincode/chaincode_example02/node"
),
chaincodeId: "myc",
chaincodeVersion: "v0",
chaincodeType: "node",
txId: client.newTransactionID(true)
};
const result = await client.installChaincode(request, 6000);
console.log(await result);
我也遇到了同樣的問題,在添加以下行(即通道初始化)后,它就解決了。
等待channel.initialize({discover:true});
來源: https : //fabric-sdk-node.github.io/master/tutorial-discovery.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.