HyperledgerFabric SampleChaincode does not implement shim Chaincode error

0 votes

I am trying to run this code:

func main() {

lld, _ := shim.LogLevel("DEBUG")
err := shim.Start(new(SampleChaincode))
if err != nil {
    logger.Error("Could not start SampleChaincode")
} else {
    logger.Info("SampleChaincode successfully started")


I am getting the following error:

>  cannot use new(SampleChaincode) (type *SampleChaincode) as type
> shim.Chaincode in argument to shim.Start:
>         *SampleChaincode does not implement shim.Chaincode (wrong type for Init method)
>                 have Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)
>                 want Init(shim.ChaincodeStubInterface) peer.Response
Oct 29, 2018 in Blockchain by digger
• 26,720 points

1 answer to this question.

0 votes

The reason you are getting this error is because the signature of the function in interface is changed to:

// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
    // Init is called during Instantiate transaction after the chaincode container
    // has been established for the first time, allowing the chaincode to
    // initialize its internal data
    Init(stub ChaincodeStubInterface) pb.Response

    // Invoke is called to update or query the ledger in a proposal transaction.
    // Updated state variables are not committed to the ledger until the
    // transaction is committed.
    Invoke(stub ChaincodeStubInterface) pb.Response

Writing a code in the right signature would solve this.

answered Oct 29, 2018 by Omkar
• 69,170 points

Related Questions In Blockchain

0 votes
1 answer

Coinbase spot price SSL Error: does not support SSL at Request

Add 'strictSSL': false to the new client: var btcClient = ...READ MORE

answered Sep 6, 2018 in Blockchain by digger
• 26,720 points
0 votes
1 answer

Network issue while testing Chaincode.

You can do the following things: You can ...READ MORE

answered Jul 3, 2018 in Blockchain by Omkar
• 69,170 points
0 votes
1 answer

Hyperledger Composer rest server NPM versions

The Hyperledger Composer pre-requisites can be installed ...READ MORE

answered Jul 13, 2018 in Blockchain by Christine
• 15,830 points
0 votes
1 answer
0 votes
1 answer

"[RuntimeException] The "-t" option does not exist" error in Hyperledger composer.

This command runs on composer-cli. Have you ...READ MORE

answered Nov 21, 2018 in Blockchain by Omkar
• 69,170 points