Main function

Last but not least, we will add the main function: the initial point of a Go program. When an instance of the chaincode is deployed on a peer, the main function is executed to start the chaincode.

In line 2 of the following snippet, the chaincode is instantiated. The function shim.Start starts the chaincode in line 4 and registers it with the peer, as follows:

func main() { 
   twc := new(TradeWorkflowChaincode) 
   twc.testMode = false 
   err := shim.Start(twc) 
   if err != nil { 
         fmt.Printf("Error starting Trade Workflow chaincode: %s", err) 
   } 
} 

Get Blockchain Development with Hyperledger now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.