Search code examples
hyperledger-fabrichyperledgerhyperledger-chaincodechaincode

What is the difference between fabric-chaincode-go and fabric-contract-api-go?


I am currently trying to learn Hyperledger Fabric , I managed to understand how to setup the network (Orderers, Peers, etc.) but now comes the part of the chaincode.

But, I found two different git repos for (what I understand) can be used to create chaincodes.

The first One being the fabric-contract-api-go, I followed their tutorials a while ago.

And the second one being the fabric-chaincode-go.

So my question is, what is the difference between these two packages, and which one should I use for writing chaincodes? Do you have resources or good examples? (other than the ones in the fabric-samples git)

I followed the fabric-contract-api tutorial and wrote a chaincode a while ago, but now I see people using the fabric-chaincode-go package, and I am a bit lost.

I am sorry, this question might sound stupid, but I don't have a Developer background. I have a SysAdmin background, and not used to GOLANG (but I am a fast learner, given to good resources).


Solution

  • You can think of fabric-contract-api-go as a high-level api that builds on/requires the low-level api fabric-chaincode-go. It's possible to write golang chaincode using only the low-level api - in fact, this was the only option before Fabric 2.0, when the contract api was also added for golang. Previously, it only existed for node and java chaincode. If you have the option to use the contract api, doing so will e.g. save you some boiler plate code.

    To see the difference, you can e.g. compare the fabcar example: in the 1.4 branch, it used the low-level api (shim). In the master branch however it uses the new contract-api.