Skip to content

feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376)#1391

Open
nXtCyberNet wants to merge 4 commits into
hyperledger:mainfrom
nXtCyberNet:issue/asset-transfer-go
Open

feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376)#1391
nXtCyberNet wants to merge 4 commits into
hyperledger:mainfrom
nXtCyberNet:issue/asset-transfer-go

Conversation

@nXtCyberNet
Copy link
Copy Markdown

@nXtCyberNet nXtCyberNet commented Mar 11, 2026

Title: feat: add Go smart contract for full-stack-asset-transfer-guide

Closes: #1376

Summary
This PR adds a Go implementation of the full-stack-asset-transfer-guide smart contract, equivalent to the existing TypeScript contract in asset-transfer-typescript. It allows developers who prefer Go to follow the guide without switching languages.

Changes
Added a new directory asset-transfer-go containing the Go chaincode implementation.

Implemented asset lifecycle operations:

  • CreateAsset
  • ReadAsset
  • UpdateAsset
  • DeleteAsset
  • AssetExists
  • TransferAsset
  • GetAllAssets

Additional components:

  • main.go entry point to bootstrap the chaincode
  • go.mod / go.sum with required Fabric dependencies
  • Dockerfile and docker-entrypoint.sh for Chaincode-as-a-Service (CaaS) deployment
  • asset-transfer-chaincode-vars.yml for compatibility with workshop automation

Testing
Tested locally in WSL Ubuntu against a live Microfab network.

  • Deployed chaincode in CaaS mode using weft chaincode package caas and the Fabric lifecycle (install → approve → commit)
  • Executed asset operations through the trader-go client on mychannel (org1MSP)
  • Verified chaincode events (CreateAsset, UpdateAsset, TransferAsset)

All 7 client commands (getAllAssets, transact, create, read, delete, transfer, listen) executed successfully.

Notes
Uses standard Fabric Go chaincode patterns via github.com/hyperledger/fabric-contract-api-go.
The asset data model mirrors the TypeScript implementation with minor adjustments for Go conventions.

@nXtCyberNet nXtCyberNet requested a review from a team as a code owner March 11, 2026 06:12
@nXtCyberNet nXtCyberNet force-pushed the issue/asset-transfer-go branch from 60894c9 to 2d376f1 Compare March 11, 2026 06:16
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
…-transfer-go

Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
@nXtCyberNet nXtCyberNet force-pushed the issue/asset-transfer-go branch from f4133c1 to b17085b Compare March 11, 2026 16:35
Copy link
Copy Markdown
Member

@bestbeforetoday bestbeforetoday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work you have put into this and apologies for not reviewing sooner.

The vars YAML and Docker related files are for the cloud deployment portions. The Go version of the contract is not (yet) hooked into them so they are not necessary. However, I don't object to them being there as reference.

See inline comments where things need to be changed.

The biggest gap in this change is that it is not integrated into the workshop workflow or documentation at all. At a minimum it needs to be included in the automated test of the appdev flow. See the test-appdev target in the justfile and the tests/10-appdev-e2e.sh that it calls.

I would probably rename tests/10-appdev-e2e.sh to something like tests/10-appdev-typescript-e2e.sh and add a similar tests/10-appdev-go-e2e.sh. The justfile could have test-appdev-typescript and test-appdev-go targets. These can then be invoked by the automated build defined in .github/workflows/test-fsat.yaml.

contractapi.Contract
}

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, owner string, appraisedValue int) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the wrong number of parameters. It needs to match the TypeScript implementation, which takes a single parameter (in addition to the context) of type Asset.


// UpdateAsset updates color, size, and appraised value of an existing asset.
// The asset owner cannot be changed here; use TransferAsset instead.
func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, appraisedValue int) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the wrong number of parameters. It needs to match the TypeScript implementation, which takes a single parameter (in addition to the context) of type Asset.

log.Panicf("Error creating asset-transfer chaincode: %v", err)
}

if err := assetChaincode.Start(); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workshop uses chaincode as an external service to allow the smart contract to be started/stopped and modified without redeployment to Fabric. What you have here should work without modification but certain environment variables need to be set correctly:

  • CORE_CHAINCODE_ID_NAME set to the value of the CHAINCODE_ID environment variable that is defined by the org env context scripts.
  • CORE_CHAINCODE_SERVER_ADDRESS set to the value of the CHAINCODE_SERVER_ADDRESS environment that is defined by the org env context scripts.

Essentially the chaincode containing the asset transfer smart contract is run from the asset-transfer-go directory as:

CORE_CHAINCODE_ID_NAME=${CHAINCODE_ID} \
CORE_CHAINCODE_SERVER_ADDRESS=${CHAINCODE_SERVER_ADDRESS} \
go run ./src

This needs to be documented somewhere.

Comment on lines +60 to +61
"typescript-eslint": "^8.56.1",
"vitest": "^4.0.18"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not have been changed. Vitest is not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go implementation of full-stack-asset-transfer-guide smart contract

2 participants