Chaincode as external service
Steps to write a chaincode compatible for running as an external service
Golang:
Import the shim package and create the ChaincodeServer struct from the shim package.
The ChaincodeServer struct takes the following values:
CC: It takes contractapi.ContractInterface which was created using contractapi.NewChaincode() function.
CCID: It takes the chaincode package id. This can be accessed from the CORE_CHAINCODE_ID environment variable.
Address: Chaincode server address to expose the chaincode. This can be accessed from the CORE_CHAINCODE_ADDRESS environment variable.
TLSProps: It accepts the struct value of shim.TLSProperties
Then call the start function from the created ChaincodeServer struct value (server.Start())
Eg: https://github.com/spydra-tech/external-chaincode-reference/blob/main/go/main.go
Javascript:
If chaincode is written using contract api:
In package.json, modify the value of scripts.start section to ”fabric-chaincode-node server”
If chaincode is written using fabric-shim:
In the file where the chaincode is initialised / started, create the shim.server by passing ccid and address which are taken from the runtime environment variables CORE_CHAINCODE_ID and CHAINCODE_SERVER_ADDRESS
Then call the start function from the created shim.server object (server.start())
Last updated