-1

How a chaincode consist with multiple smart contracts in go lang? for the go only has one main function.

Kęstutis
  • 48
  • 5
touchingsoil
  • 173
  • 1
  • 1
  • 8

1 Answers1

0

When it comes to Go chaincode, there can be any number of smart contracts. There are 3 main functions:

  • Init: called on instantiation or upgrade of the chaincode. It is usually used to initialise data.
  • Invoke: called on every transaction. In this function, you can define which functions are called when some particular arguments are passed, thus, making it possible to have multiple smart contracts in one go file.
  • main: It starts the chaincode in a container on instantiating it.

Here is a detailed tutorial explaining how to write Go smart contracts: https://hyperledger-fabric.readthedocs.io/en/release-2.0/chaincode4ade.html#vendoring

Kęstutis
  • 48
  • 5
  • so chaincode in go lang would support multi smart contracts?@Kestutis – touchingsoil Jan 13 '21 at 01:35
  • @touchingsoil, yes. You define functions/ smart contracts in a Go file, package it, and then instantiate it in your network. Once instantiated, you can execute the smart contracts defined In the file by calling particular functions/ smart contracts in the file (there can be multiple smart contracts within one file). – Kęstutis Jan 13 '21 at 09:41