Tara
Tara

Reputation: 549

How to install chaincode using fabric sdk (fabric-client)?

Based on the package definition listed here https://fabric-sdk-node.github.io/master/tutorial-chaincode-lifecycle.html

const package_request = {
     chaincodeType: 'golang',
     goPath: '/gopath',
     chaincodePath: '/path/to/code',
     metadataPath: '/path/to/metadata'
}

Where do I put the byte array of my chaincode go (golang) codes which is sitting in my laptop? Also not sure what chaincodePath and metadataPath are for? Are they path in the fabric system?

Basically, I don't know how to load my golang source codes (chaincode) to the request to install the chaincode.

Upvotes: 0

Views: 824

Answers (3)

Mtng
Mtng

Reputation: 61

To install the chaincode you have to use the following method:

installCCReq := resmgmt.InstallCCRequest{
                Name: ccName,
                Path: ccPath, 
                Version: ccVersion,
                Package: ccPkg}

Here is the complete example and here is the complete documentation

Upvotes: 1

metadata
metadata

Reputation: 1189

For fabric-go-sdk you can refer to chainHeroExample. check main.go and setup.go files.

Below is the snippet of main.go file.

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)
    }

Upvotes: 2

adnan.c
adnan.c

Reputation: 721

The chaincodePath is the directory containing the actual chaincode file (say chainCode.go) and the metadataPath is the directory that may contain metadata files, e.g. index files if needed by your chaincode.

Upvotes: 2

Related Questions