【问题标题】:How to install chaincode using fabric sdk (fabric-client)?如何使用fabric sdk(fabric-client)安装链码?
【发布时间】:2019-10-09 08:45:01
【问题描述】:
【问题讨论】:
标签:
hyperledger-fabric
hyperledger-fabric-sdk-js
hyperledger-fabric-sdk-go
【解决方案1】:
chaincodePath 是包含实际链码文件的目录(比如chainCode.go),metadataPath 是可能包含元数据文件的目录,例如如果您的链代码需要,索引文件。
【解决方案2】:
对于fabric-go-sdk,您可以参考chainHeroExample。检查main.go 和setup.go 文件。
下面是main.go文件的sn-p。
func main() {
// Definition of the Fabric SDK properties
fSetup := blockchain.FabricSetup{
// Network parameters
OrdererID: "orderer.firstproject.com",
// Channel parameters
ChannelID: "mychannel",
ChannelConfig: "/c/Projects/Go/src/github.com/hyperledger/firstproject/firstproject-network/artifacts/channel.tx",
// Chaincode parameters
ChainCodeID: "firstproject",
ChaincodeGoPath: "/c/Projects/Go",
ChaincodePath: "github.com/hyperledger/firstproject/chaincode/",
OrgAdmin: "Admin",
OrgName: "org1",
ConfigFile: "config.yaml",
// User parameters
UserName: "User1",
}
// Initialization of the Fabric SDK from the previously set properties
err := fSetup.Initialize()
if err != nil {
fmt.Printf("Unable to initialize the Fabric SDK: %v\n", err)
return
}
// Close SDK
defer fSetup.CloseSDK()
// Install and instantiate the chaincode
err = fSetup.InstallAndInstantiateCC()
if err != nil {
fmt.Printf("Unable to install and instantiate the chaincode: %v\n", err)
return
}
// Query the chaincode
response, err := fSetup.QueryHello()
if err != nil {
fmt.Printf("Unable to query hello on the chaincode: %v\n", err)
} else {
fmt.Printf("Response from the query hello: %s\n", response)
}
【解决方案3】:
要安装链码,您必须使用以下方法:
installCCReq := resmgmt.InstallCCRequest{
Name: ccName,
Path: ccPath,
Version: ccVersion,
Package: ccPkg}
这是完整的example,这是完整的documentation