================================== Install chaincode programmatically ================================== To install chaincode inside our application, we need to reach out to system chaincode called ``_lifecycle``. Following piece of code can be taken as a reference: .. code-block:: go :linenos: func InstallChaincode(network *client.Network, arguments *lifecycle.InstallChaincodeArgs) (*lifecycle.InstallChaincodeResult, error) { lifecycleChaincode := network.GetContract("_lifecycle") argumentsBytes, err := proto.Marshal(arguments) if err != nil { return nil, err } chaincodesBytes, err := lifecycleChaincode.EvaluateTransaction("InstallChaincode", string(argumentsBytes)) if err != nil { return nil, err } installedChaincode := new(lifecycle.InstallChaincodeResult) err = proto.Unmarshal(chaincodesBytes, installedChaincode) if err != nil { return nil, err } return installedChaincode, nil } Where: - ``lifecycle.InstallChaincodeArgs`` - protobuf struct that the ``InstallChaincode`` chaincode function expects while installing the chaincode (``lifecycle`` package is imported from ``"github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle"``) - ``lifecycle.InstallChaincodeResult`` - the return type of ``InstallChaincode`` chaincode function ``lifecycle.InstallChaincodeArgs`` has ``ChaincodeInstallPackage`` field that we fill with the target chaincode. Take a look at this function usage: .. code-block:: go :linenos: // ... arguments := lifecycle.InstallChaincodeArgs{ChaincodeInstallPackage: myChaincodeBytes} result, err := InstallChaincode(network, &arguments) fmt.Printf("Label: %v, Package id: %v", result.Label, result.PackageId)