This directory contains example implementations of Hyperledger Fabric Python chaincodes. All examples are CCAAS (Chaincode-as-a-Service) — the chaincode runs as a long-lived gRPC server that the Fabric peer connects to.
examples/
├── README.md # This file
├── STRUCTURE.md # Explanation of the layout & conventions
└── ccaas/ # All CCAAS examples
├── README.md # CCAAS overview
├── fabric-shim/ # Low-level fabric_shim API examples
│ ├── README.md
│ ├── asset-transfer-basic/ # Asset CRUD (manual dispatch)
│ └── asset-transfer-sbe/ # SBE-style transfer (manual dispatch)
└── fabric-contract-api/ # High-level fabric_contract_api examples
├── README.md
├── asset-transfer-basic/ # Asset CRUD (auto-dispatch + metadata)
└── asset-transfer-sbe/ # SBE-style transfer (auto-dispatch + metadata)
| Layer | Use when you want … | Package |
|---|---|---|
ccaas/fabric-shim/ |
Fine-grained control, manual dispatch, zero reflection | src.fabric_shim |
ccaas/fabric-contract-api/ |
Auto-dispatch, type-annotated args, auto-generated metadata | src.fabric_contract_api |
Both layers expose the same scenarios (asset-transfer-basic and asset-transfer-sbe) so you can compare implementations side-by-side.
| Scenario | What it shows |
|---|---|
asset-transfer-basic/ |
Asset CRUD: InitLedger, CreateAsset, ReadAsset, UpdateAsset, DeleteAsset, GetAllAssets |
asset-transfer-sbe/ |
SBE-style: the above plus TransferAsset and AssetExists |
- Choose: pick one of
ccaas/fabric-shim/<scenario>/orccaas/fabric-contract-api/<scenario>/. - Read: each example has its own
README.mdwith the full packaging / install / approve / commit / run / invoke / query sequence. - Run: from the repository root — create/activate a virtualenv and install dependencies, then start the example:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export CHAINCODE_ID="<package_id>"
export CHAINCODE_SERVER_ADDRESS="127.0.0.1:9999"
./.venv/bin/python examples/ccaas/<layer>/<scenario>/main.pyChaincode-as-a-Service (CCAAS) is a deployment model for Hyperledger Fabric chaincodes where:
- The chaincode runs as an independent service/process.
- The peer connects to it via gRPC.
- You have full control over the runtime environment.
- Perfect for integrating with external systems, databases, or microservices.
See the official Fabric docs for more details on the CCAAS architecture.
- Python 3.10+
- Hyperledger Fabric network (test network or production)
- Peer CLI for lifecycle management
- Docker (optional, for containerized deployment)
fabric_shimpackage — low-level chaincode shim.fabric_contract_apipackage — high-level contract API (Python port offabric-contract-api-go).- Hyperledger Fabric Official Docs
- CCAAS Architecture
If you create a new example, follow the same structure:
- Create a new folder under
ccaas/<layer>/<scenario>/. - Include at least
main.py,README.md,connection.json,metadata.json,requirements.txt,Dockerfile. - Update
ccaas/<layer>/README.mdto reference the new example. - Add a row to the tables in this README and in
STRUCTURE.md.