cancel
Showing results for 
Search instead for 
Did you mean: 

Error importing packages on Smart Contract - Hyperledger Fabric

ejd_barrio21
Explorer

Hi,

I've been trying to program a smart contract in GO language for SAP Hyperledger Fabric, but when I try to instantiate it, I've got the following error:

cannot find package "github.com/hyperledger/fabric/core/ledger" 

I'm trying to import the ledger package from GitHub but I'm unable to do it, I've got the same issue when I tried to import other packages as well. Is there any way to do it ? What are the packages supported from SAP and where can I find them ?

Thank you !

Accepted Solutions (1)

Accepted Solutions (1)

chris_fries
Advisor
Advisor

Hi Emilio,

the SAP Hyperledger Fabric Service is running version 1.4 supporting the packages included in this release for chaincode.

With Hyperledger Fabric 2.x some packages were moved to other repositories so there can be some issues with requiring packages with go get.

One way of getting around that is to vendor your dependencies. If you haven’t done already initialize go modules by running

go mod init chaincode

After that you can vendor your dependencies by running

go mod vendor

If you want to use chaincode packages of version 1.4 you have to also init go modules but instead of vendoring you can require the dependencies of a specific release by running for example:

go get github.com/hyperledger/fabric/core/chaincode/shim@v1.4
go get github.com/hyperledger/fabric/protos/peer@v1.4

Since those dependencies are in version 1.4 they are available during instantiation without vendoring.

@Gregory The Hyperledger Fabric service from SAP only supports Go chaincode

Best,

Christopher

ejd_barrio21
Explorer
0 Kudos

Hi Christopher!

Thank you for your answer, I've tried to do everything you told me, but I've still got the error on SAP Hyperledger Fabric Dashboard, I'll post the image so you can see what I mean.

I've tried to import the same packages as HF has in their 1.4v, but I'm still unable to make it run. Can I reach you on e-mail or anywhere so I can ask you some questions please? Or just reply me if I'm doing something wrong, because I'm very lost at this point..

Thank you again !

Former Member
0 Kudos

Hi Christopher,

sorry that i got it backwards. indeed the sample chaincode is the go code, but it seems to be wrapped (shimmed?) into Javascript code. so, both are needed for the application to run on SAP cloud, correct?

thank you for pointing this out.

gm

chris_fries
Advisor
Advisor
0 Kudos

Hi Emilio,

the error should disappear if you vendor the dependencies. Have you run the steps inside the /src folder of the chaincode? Have you tried to build the chaincode on your local machine (go build -tags nopkcs11)?

Also I haven’t seen the package "github.com/hyperledger/fabric/core/ledger" to be used in any chaincode so far. Do you really need that package as an import? You can also check for unused imports with gofmt.

@Gregory I don’t know which sample chaincode you are referring to but the chaincode should be pure go and nothing wrapped with JavaScript code.

Best,

Christopher

ejd_barrio21
Explorer
0 Kudos

Hi christopher.fries ,

I think there might be a problem with my Go installation, because I've done what you told me and still not working.. but here's the point.

I've tried to import these packages because I thought it would be useful to use a function they have. I'm very new in blockchain, as well as in smart contract implementation, so I'm experimenting with it.

My problem is that I need to return the current block number of the blockchain, I'm capable of returning the TxId, Timestamp and other things as well, but I haven't seen any function that can do it. Is there any way I could do this with only the 'peer' and 'shim' packages ?

Sorry for bothering you, I'm very glad you are answering me, thank you so much!

Regards,

Emilio

chris_fries
Advisor
Advisor

Hi Emilio,

you should definetly try to get your Go installation working. It will be much better to develop when having the possibility to already check if the code builds locally.

I think getting the current block number via this package will not work. There's a system chaincode that you can call to get information about blocks & transactions called "qscc" https://godoc.org/github.com/hyperledger/fabric/core/scc/qscc To get the current block just query "getChainInfo" and the you will get the current block height --> https://github.com/hyperledger/fabric-protos-go/blob/master/common/ledger.pb.go#L25

You can call this chaincode from within your chaincode via the shim interface documented here https://godoc.org/github.com/hyperledger/fabric-chaincode-go/shim#ChaincodeStub.InvokeChaincode

Coming back to your question getting the current block I want to clarify that you can't get the block of the current transaction since the transaction will be written to a block after it was executed (endorsed by the peers).

Best,

Christopher

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Christopher,

thank you for clarifying all this and providing the help link. i will be happy to be corrected again, if i get it wrong.

here's my understanding: the sample chaincode is written in GO which is just one file + 2 yaml config files, that communicates with the channel or ledger (via shims), and is inside the zip file that is installed and instantiated to that channel and fabric network. the actual fabric application (and service) that is hosted on the cloud platform is written in Javascript, so in the end there are three tiers to this implementation:

1. fabric in GO

2. chaincode in GO

3. service and application in Javascript of cloud foundry 'flavor'

the actual fabric network is not started and exposed until the fabric services are instantiated. there are certain licensing implications to use and reuse of all that code, but that's beyond the scope of our thread here.

happy to see fabric being discussed here on SAP platform.

thank you and best regards,

gm

Former Member
0 Kudos

Hi Emilio,

i believe Christopher has made an important distinction. i still think that SAP implementation requires Javascript in addition to Go or at least that is what i have seen in the sample application.

Thank you,

gm

chris_fries
Advisor
Advisor

Hi Gregory,

I think I need to clarify some things. There is chaincode in Hyperledger Fabric and Smart Filters in Multichain.

When we talk about chaincode in Hyperledger Fabric, SAP only supports Go chaincode. There's an example chaincode available at the official documentation https://help.sap.com/viewer/cab6d96064454f348689e661d3fe569b/BLOCKCHAIN/en-US/177de60b49df4d11bd9276...

Interaction with the chaincode then happens via the REST API and to write your application you can use any languare that you want which is capable of doing http calls. So if you have seen a sample application it could be that this application was written in JavaScript.

MultiChain uses the so called Smart Filters and those are written in JavaScript.

Hope this helps.

Best,

Christopher

Former Member
0 Kudos

Hi Emilio,

i haven't seen any chaincode implementations by SAP in Go, but only in Javascript. it also seems like SAP are more interested in multichain than in contributing to hyperledger.

i wish i could answer your question better,

thank you, gm

ejd_barrio21
Explorer
0 Kudos

Hi Gregory!,

thank you for your answer, I've only tried implementing chaincodes with GOLANG because I thought that SAP only supports this type of chaincode, but I'll take a look at JS chaincode implementations, as well as reading of MultiChain.

Thanks!