{"id":37156577,"url":"https://github.com/block-foundation/hyperledger-template","last_synced_at":"2026-01-14T18:34:36.492Z","repository":{"id":184728408,"uuid":"671564917","full_name":"block-foundation/hyperledger-template","owner":"block-foundation","description":"Hyperledger Fabric Smart-Contract Template","archived":false,"fork":false,"pushed_at":"2024-08-25T06:29:05.000Z","size":48,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-04T20:41:28.677Z","etag":null,"topics":["block-foundation","blockchain","blockfoundation","hyperledger","hyperledger-fabric","smart-contracts","template"],"latest_commit_sha":null,"homepage":"https://www.blockfoundation.io","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc-by-sa-4.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/block-foundation.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":".github/SUPPORT.md","governance":".github/GOVERNANCE.md","roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"block-foundation","open_collective":"block"}},"created_at":"2023-07-27T15:55:05.000Z","updated_at":"2024-08-25T06:28:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"a922bc58-7a1c-4499-b94f-59f7725668a4","html_url":"https://github.com/block-foundation/hyperledger-template","commit_stats":null,"previous_names":["block-foundation/hyperledger-template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/block-foundation/hyperledger-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-foundation%2Fhyperledger-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-foundation%2Fhyperledger-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-foundation%2Fhyperledger-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-foundation%2Fhyperledger-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/block-foundation","download_url":"https://codeload.github.com/block-foundation/hyperledger-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-foundation%2Fhyperledger-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28430852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["block-foundation","blockchain","blockfoundation","hyperledger","hyperledger-fabric","smart-contracts","template"],"created_at":"2026-01-14T18:34:35.687Z","updated_at":"2026-01-14T18:34:36.488Z","avatar_url":"https://github.com/block-foundation.png","language":"Go","funding_links":["https://github.com/sponsors/block-foundation","https://opencollective.com/block"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"right\"\u003e\n\n[![GitHub License](https://img.shields.io/github/license/block-foundation/blocktxt?style=flat-square\u0026logo=readthedocs\u0026logoColor=FFFFFF\u0026label=\u0026labelColor=%23041B26\u0026color=%23041B26\u0026link=LICENSE)](https://github.com/block-foundation/hyperledger-template/blob/main/LICENSE)\n[![devContainer](https://img.shields.io/badge/Container-Remote?style=flat-square\u0026logo=visualstudiocode\u0026logoColor=%23FFFFFF\u0026label=Remote\u0026labelColor=%23041B26\u0026color=%23041B26)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/block-foundation/hyperledger-template)\n\n\u003c/div\u003e\n\n---\n\n\u003cdiv\u003e\n    \u003cimg align=\"right\" src=\"https://raw.githubusercontent.com/block-foundation/brand/master/src/logo/logo_gray.png\" width=\"96\" alt=\"Block Foundation Logo\"\u003e\n    \u003ch1 align=\"left\"\u003eHyperledger Template\u003c/h1\u003e\n    \u003ch3 align=\"left\"\u003eBlock Foundation\u003c/h3\u003e\n\u003c/div\u003e\n\n---\n\n\u003cimg align=\"right\" width=\"75%\" src=\"https://raw.githubusercontent.com/block-foundation/brand/master/src/image/repository_cover/block_foundation-structure-03-accent.jpg\"  alt=\"Block Foundation Brand\"\u003e\n\n### Contents\n\n- [Introduction](#introduction)\n- [Colophon](#colophon)\n\n\u003cbr clear=\"both\"/\u003e\n\n---\n\n\u003cdiv align=\"right\"\u003e\n\n[![Report a Bug](https://img.shields.io/badge/Report%20a%20Bug-GitHub?style=flat-square\u0026\u0026logoColor=%23FFFFFF\u0026color=%23E1E4E5)](https://github.com/block-foundation/hyperledger-template/issues/new?assignees=\u0026labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected\u0026projects=\u0026template=bug_report.yml)\n[![Request a Feature](https://img.shields.io/badge/Request%20a%20Feature-GitHub?style=flat-square\u0026\u0026logoColor=%23FFFFFF\u0026color=%23E1E4E5)](https://github.com/block-foundation/hyperledger-template/issues/new?assignees=\u0026labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected\u0026projects=\u0026template=feature_request.yml)\n[![Ask a Question](https://img.shields.io/badge/Ask%20a%20Question-GitHub?style=flat-square\u0026\u0026logoColor=%23FFFFFF\u0026color=%23E1E4E5)](https://github.com/block-foundation/hyperledger-template/issues/new?assignees=\u0026labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected\u0026projects=\u0026template=question.yml)\n[![Make a Suggestion](https://img.shields.io/badge/Make%20a%20Suggestion-GitHub?style=flat-square\u0026\u0026logoColor=%23FFFFFF\u0026color=%23E1E4E5)](https://github.com/block-foundation/hyperledger-template/issues/new?assignees=\u0026labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected\u0026projects=\u0026template=suggestion.yml)\n[![Start a Discussion](https://img.shields.io/badge/Start%20a%20Discussion-GitHub?style=flat-square\u0026\u0026logoColor=%23FFFFFF\u0026color=%23E1E4E5)](https://github.com/block-foundation/hyperledger-template/issues/new?assignees=\u0026labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected\u0026projects=\u0026template=discussion.yml)\n\n\u003c/div\u003e\n\n## Introduction\n\nBelow is a basic example of a chaincode (smart contract) in Hyperledger Fabric. This is written in Go, which is one of the languages you can use to create chaincode in Hyperledger Fabric. This simple example chaincode models assets (items) that can be created, read, updated, deleted, and listed.\n\n``` go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/hyperledger/fabric-contract-api-go/contractapi\"\n)\n\ntype SmartContract struct {\n    contractapi.Contract\n}\n\ntype Item struct {\n    ID    string `json:\"id\"`\n    Name  string `json:\"name\"`\n    Price int    `json:\"price\"`\n}\n\nfunc (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface) error {\n    items := []Item{\n        {ID: \"item1\", Name: \"Item 1\", Price: 100},\n        {ID: \"item2\", Name: \"Item 2\", Price: 200},\n        {ID: \"item3\", Name: \"Item 3\", Price: 300},\n    }\n\n    for _, item := range items {\n        itemJSON, err := json.Marshal(item)\n        if err != nil {\n            return err\n        }\n\n        err = ctx.GetStub().PutState(item.ID, itemJSON)\n        if err != nil {\n            return fmt.Errorf(\"failed to put to world state. %v\", err)\n        }\n    }\n\n    return nil\n}\n\nfunc (s *SmartContract) CreateItem(ctx contractapi.TransactionContextInterface, id string, name string, price int) error {\n    item := Item{\n        ID:    id,\n        Name:  name,\n        Price: price,\n    }\n\n    itemJSON, err := json.Marshal(item)\n    if err != nil {\n        return err\n    }\n\n    return ctx.GetStub().PutState(id, itemJSON)\n}\n\nfunc (s *SmartContract) ReadItem(ctx contractapi.TransactionContextInterface, id string) (*Item, error) {\n    itemJSON, err := ctx.GetStub().GetState(id)\n    if err != nil {\n        return nil, fmt.Errorf(\"failed to read from world state. %v\", err)\n    }\n\n    if itemJSON == nil {\n        return nil, fmt.Errorf(\"the asset %s does not exist\", id)\n    }\n\n    var item Item\n    err = json.Unmarshal(itemJSON, \u0026item)\n    if err != nil {\n        return nil, err\n    }\n\n    return \u0026item, nil\n}\n\nfunc (s *SmartContract) UpdateItem(ctx contractapi.TransactionContextInterface, id string, name string, price int) error {\n    item, err := s.ReadItem(ctx, id)\n    if err != nil {\n        return err\n    }\n\n    item.Name = name\n    item.Price = price\n\n    itemJSON, err := json.Marshal(item)\n    if err != nil {\n        return err\n    }\n\n    return ctx.GetStub().PutState(id, itemJSON)\n}\n\nfunc (s *SmartContract) DeleteItem(ctx contractapi.TransactionContextInterface, id string) error {\n    exists, err := s.ItemExists(ctx, id)\n    if err != nil {\n        return err\n    }\n    if !exists {\n        return fmt.Errorf(\"the asset %s does not exist\", id)\n    }\n\n    return ctx.GetStub().DelState(id)\n}\n\nfunc (s *SmartContract) ItemExists(ctx contractapi.TransactionContextInterface, id string) (bool, error) {\n    itemJSON, err := ctx.GetStub().GetState(id)\n    if err != nil {\n        return false, fmt.Errorf(\"failed to read from world state. %v\", err)\n    }\n\n    return itemJSON != nil, nil\n}\n\nfunc (s *SmartContract) GetAllItems(ctx contractapi.TransactionContextInterface) ([]*Item, error) {\n    resultsIterator, err := ctx.GetStub().GetStateByRange(\"\", \"\")\n    if err != nil {\n        return nil, err\n    }\n    defer resultsIterator.Close()\n\n    var items []*Item\n    for resultsIterator.HasNext() {\n        queryResponse, err := resultsIterator.Next()\n        if err != nil {\n            return nil, err\n        }\n\n        var item Item\n        err = json.Unmarshal(queryResponse.Value, \u0026item)\n        if err != nil {\n            return nil, err\n        }\n        items = append(items, \u0026item)\n    }\n\n    return items, nil\n}\n\nfunc main() {\n    chaincode, err := contractapi.NewChaincode(new(SmartContract))\n    if err != nil {\n        fmt.Printf(\"Error create example chaincode: %s\", err.Error())\n        return\n    }\n\n    if err := chaincode.Start(); err != nil {\n        fmt.Printf(\"Error starting example chaincode: %s\", err.Error())\n    }\n}\n```\n\nThis chaincode allows for the following operations:\n\n1. Initialize the ledger with some items (`InitLedger` function).\n2. Create an item (`CreateItem` function).\n3. Read an item (`ReadItem` function).\n4. Check if an item exists (`ItemExists` function).\n5. Update an item (`UpdateItem` function).\n6. Delete an item (`DeleteItem` function).\n7. Get all items (`GetAllItems` function).\n\nEach item has an ID, a name, and a price. Remember to use the correct import paths for the `fmt`, `json`, and `github.com/hyperledger/fabric-contract-api-go/contractapi` packages.\n\n\n\n## Directory structure\n\nThe directory structure for a Hyperledger Fabric Chaincode (smart contract):\n\n``` sh\n- fabric-item-contract\n    - chaincode\n        - item-contract\n            - item-contract.go // The chaincode file\n    - test\n        - item-contract_test.go // Unit tests for your smart contract\n    - scripts\n        - startFabric.sh // Scripts for setting up and running the network\n        - testAPI.sh     // Scripts for testing the API\n    - doc\n        - item-contract.md // Documentation for your chaincode\n    - network\n        - // Contains the configuration for your network\n    - client\n        - // Optional, for client side code if needed\n    - README.md // Main project readme\n    - .gitignore // For excluding files from version control\n```\n\nThis is a fairly standard structure for a Fabric chaincode project.\n\n- Your actual chaincode would live inside the `chaincode` directory.\n- The `test` directory contains the tests for your chaincode.\n- The `scripts` directory contains shell scripts for setting up your environment and running your application.\n- The `doc` directory contains the documentation for your chaincode.\n- The `network` directory would contain the configurations for your network.\n- The `client` directory is optional and would contain the client side code for invoking the chaincode, if any.\n\nThese directories and their contents will help keep your project organized and will make it easier for others to understand your work.\n\n\n\n\n\n\n---\n\n## Colophon\n\n### Authors\n\nThis is an open-source project by the **[Block Foundation](https://www.blockfoundation.io \"Block Foundation website\")**.\n\nThe Block Foundation mission is enabling architects to take back initiative and contribute in solving the mismatch in housing through blockchain technology. Therefore the Block Foundation seeks to unschackle the traditional constraints and construct middle ground between rent and the rigidity of traditional mortgages.\n\nwebsite: [www.blockfoundation.io](https://www.blockfoundation.io \"Block Foundation website\")\n\n### Development Resources\n\n#### Contributing\n\nWe'd love for you to contribute and to make this project even better than it is today!\nPlease refer to the [contribution guidelines](.github/CONTRIBUTING.md) for information.\n\n### Legal Information\n\n#### Copyright\n\nCopyright \u0026copy; 2023 [Stichting Block Foundation](https://www.blockfoundation.io/ \"Block Foundation website\"). All Rights Reserved.\n\n#### License\n\nExcept as otherwise noted, the content in this repository is licensed under the\n[Creative Commons Attribution 4.0 International (CC BY 4.0) License](https://creativecommons.org/licenses/by/4.0/), and\ncode samples are licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\n\nAlso see [LICENSE](https://github.com/block-foundation/community/blob/master/src/LICENSE) and [LICENSE-CODE](https://github.com/block-foundation/community/blob/master/src/LICENSE-CODE).\n\n#### Disclaimer\n\n**THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock-foundation%2Fhyperledger-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblock-foundation%2Fhyperledger-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock-foundation%2Fhyperledger-template/lists"}