你fabric-go-sdk
可以参考chainHeroExample 。检查main.go
和setup.go
文件。
下面是main.go
文件的片段。
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)
}