Compare commits

...

3 commits

Author SHA1 Message Date
SurbhiAgarwal
918e4f22ec
Merge d72c60d652 into a2c40e6522 2026-05-24 13:28:54 +08:00
James Taylor
a2c40e6522
test-network-k8s: ghcr.io for Hyperledger images (#1416)
Some checks failed
Test Network BFT Orderer 🍟 / basic (java, cryptogen) (push) Has been cancelled
Test Network BFT Orderer 🍟 / basic (javascript, ca) (push) Has been cancelled
Test Network BFT Orderer 🍟 / basic (javascript, cryptogen) (push) Has been cancelled
Test Network BFT Orderer 🍟 / basic (typescript, ca) (push) Has been cancelled
Test Network BFT Orderer 🍟 / basic (typescript, cryptogen) (push) Has been cancelled
Test Network Events 💡 / events (go, events) (push) Has been cancelled
Test Network Events 💡 / events (java, events) (push) Has been cancelled
Test Network Events 💡 / events (javascript, events) (push) Has been cancelled
Test Network HSM 🍏 / hsm (go) (push) Has been cancelled
Test Network HSM 🍏 / hsm (java) (push) Has been cancelled
Test Network HSM 🍏 / hsm (javascript) (push) Has been cancelled
Test Network HSM 🍏 / hsm (typescript) (push) Has been cancelled
Kubernetes Test Network 🍒 / ccaas-java (push) Has been cancelled
Kubernetes Test Network 🍒 / ccaas-external (push) Has been cancelled
Kubernetes Test Network 🍒 / k8s-builder (push) Has been cancelled
Kubernetes Test Network 🍒 / multi-namespace (push) Has been cancelled
Kubernetes Test Network 🍒 / bft-orderer (push) Has been cancelled
Test Network Ledger 🥑 / basic (go, ledger) (push) Has been cancelled
Test Network Ledger 🥑 / basic (javascript, ledger) (push) Has been cancelled
Test Network Ledger 🥑 / basic (typescript, ledger) (push) Has been cancelled
Test Network Off Chain 🍔 / off-chain (go) (push) Has been cancelled
Test Network Off Chain 🍔 / off-chain (java) (push) Has been cancelled
Test Network Off Chain 🍔 / off-chain (javascript) (push) Has been cancelled
Test Network Off Chain 🍔 / off-chain (typescript) (push) Has been cancelled
Test Network Private 🔒 / private (go, private) (push) Has been cancelled
Test Network Private 🔒 / private (java, private) (push) Has been cancelled
Test Network Private 🔒 / private (typescript, private) (push) Has been cancelled
Test Network SBE 🎵 / SBE (java, sbe) (push) Has been cancelled
Test Network SBE 🎵 / SBE (typescript, sbe) (push) Has been cancelled
Test Network Secured 🔔 / secured (go, secured) (push) Has been cancelled
Default to using ghcr.io for Hyperledger images in the k8s test network

Signed-off-by: James Taylor <jamest@uk.ibm.com>
2026-05-21 11:30:24 +01:00
SurbhiAgarwal1
d72c60d652 docs: highlight GetHistoryForKey in ledger-queries sample
Addresses issue #1233. Adds a new README.md for the sample and updates the root README.md to include asset history and TypeScript support.

Signed-off-by: SurbhiAgarwal1 <agarwalsurbhi1807@gmail.com>
2026-04-13 14:11:19 +05:30
3 changed files with 70 additions and 4 deletions

View file

@ -30,14 +30,14 @@ applications on a development or CI workstation.
The asset transfer series provides a series of sample smart contracts and applications to demonstrate how to store and transfer assets using Hyperledger Fabric. The asset transfer series provides a series of sample smart contracts and applications to demonstrate how to store and transfer assets using Hyperledger Fabric.
Each sample and associated tutorial in the series demonstrates a different core capability in Hyperledger Fabric. The **Basic** sample provides an introduction on how Each sample and associated tutorial in the series demonstrates a different core capability in Hyperledger Fabric. The **Basic** sample provides an introduction on how
to write smart contracts and how to interact with a Fabric network using the Fabric SDKs. The **Ledger queries**, **Private data**, and **State-based endorsement** to write smart contracts and how to interact with a Fabric network using the Fabric SDKs. The **Ledger queries** (including asset history), **Private data**, and **State-based endorsement**
samples demonstrate these additional capabilities. Finally, the **Secured agreement** sample demonstrates how to bring all the capabilities together to securely samples demonstrate these additional capabilities. The **Secured agreement** sample demonstrates how to bring all the capabilities together to securely
transfer an asset in a more realistic transfer scenario. transfer an asset in a more realistic transfer scenario.
| **Smart Contract** | **Description** | **Tutorial** | **Smart contract languages** | **Application languages** | | **Smart Contract** | **Description** | **Tutorial** | **Smart contract languages** | **Application languages** |
| -----------|------------------------------|----------|---------|---------| | -----------|------------------------------|----------|---------|---------|
| [Basic](asset-transfer-basic) | The Basic sample smart contract that allows you to create and transfer an asset by putting data on the ledger and retrieving it. This sample is recommended for new Fabric users. | [Writing your first application](https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html) | Go, JavaScript, TypeScript, Java | Go, TypeScript, Java | | [Basic](asset-transfer-basic) | The Basic sample smart contract that allows you to create and transfer an asset by putting data on the ledger and retrieving it. This sample is recommended for new Fabric users. | [Writing your first application](https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html) | Go, JavaScript, TypeScript, Java | Go, TypeScript, Java |
| [Ledger queries](asset-transfer-ledger-queries) | The ledger queries sample demonstrates range queries and transaction updates using range queries (applicable for both LevelDB and CouchDB state databases), and how to deploy an index with your chaincode to support JSON queries (applicable for CouchDB state database only). | [Using CouchDB](https://hyperledger-fabric.readthedocs.io/en/latest/couchdb_tutorial.html) | Go, JavaScript | Java, JavaScript | | [Ledger queries](asset-transfer-ledger-queries) | The ledger queries sample demonstrates range queries, transaction updates using range queries (applicable for both LevelDB and CouchDB state databases), retrieving asset history using GetHistoryForKey, and deploying an index with your chaincode to support JSON queries (applicable for CouchDB state database only). | [Using CouchDB](https://hyperledger-fabric.readthedocs.io/en/latest/couchdb_tutorial.html) | Go, JavaScript, TypeScript | Java, JavaScript |
| [Private data](asset-transfer-private-data) | This sample demonstrates the use of private data collections, how to manage private data collections with the chaincode lifecycle, and how the private data hash can be used to verify private data on the ledger. It also demonstrates how to control asset updates and transfers using client-based ownership and access control. | [Using Private Data](https://hyperledger-fabric.readthedocs.io/en/latest/private_data_tutorial.html) | Go, TypeScript, Java | TypeScript | | [Private data](asset-transfer-private-data) | This sample demonstrates the use of private data collections, how to manage private data collections with the chaincode lifecycle, and how the private data hash can be used to verify private data on the ledger. It also demonstrates how to control asset updates and transfers using client-based ownership and access control. | [Using Private Data](https://hyperledger-fabric.readthedocs.io/en/latest/private_data_tutorial.html) | Go, TypeScript, Java | TypeScript |
| [State-Based Endorsement](asset-transfer-sbe) | This sample demonstrates how to override the chaincode-level endorsement policy to set endorsement policies at the key-level (data/asset level). | [Using State-based endorsement](https://github.com/hyperledger/fabric-samples/tree/main/asset-transfer-sbe) | Java, TypeScript | JavaScript | | [State-Based Endorsement](asset-transfer-sbe) | This sample demonstrates how to override the chaincode-level endorsement policy to set endorsement policies at the key-level (data/asset level). | [Using State-based endorsement](https://github.com/hyperledger/fabric-samples/tree/main/asset-transfer-sbe) | Java, TypeScript | JavaScript |
| [Secured agreement](asset-transfer-secured-agreement) | Smart contract that uses implicit private data collections, state-based endorsement, and organization-based ownership and access control to keep data private and securely transfer an asset with the consent of both the current owner and buyer. | [Secured asset transfer](https://hyperledger-fabric.readthedocs.io/en/latest/secured_asset_transfer/secured_private_asset_transfer_tutorial.html) | Go | TypeScript | | [Secured agreement](asset-transfer-secured-agreement) | Smart contract that uses implicit private data collections, state-based endorsement, and organization-based ownership and access control to keep data private and securely transfer an asset with the consent of both the current owner and buyer. | [Secured asset transfer](https://hyperledger-fabric.readthedocs.io/en/latest/secured_asset_transfer/secured_private_asset_transfer_tutorial.html) | Go | TypeScript |

View file

@ -0,0 +1,66 @@
# Asset transfer ledger queries sample
The asset transfer ledger queries sample demonstrates the ledger query capabilities of Hyperledger Fabric, including range queries, rich queries (when using CouchDB), and retrieving asset history.
## About the sample
This sample includes smart contract and application code in multiple languages. It demonstrates several key features:
- **Range Queries**: Retrieve a range of assets from the ledger.
- **Transaction Updates with Range Queries**: Safely update assets based on the results of a range query.
- **History Queries**: Use `GetHistoryForKey` to retrieve the entire history of an asset, including all previous owners and deletions.
- **Rich Queries**: Use the state database (CouchDB) to perform complex JSON queries.
- **CouchDB Indexes**: Package indexes with your chaincode to support efficient rich queries and sorting.
- **Pagination**: Handle large result sets using bookmarks and page sizes for both range and rich queries.
For a detailed walk-through of this sample, refer to the [Using CouchDB as your state database](https://hyperledger-fabric.readthedocs.io/en/latest/couchdb_tutorial.html) tutorial in the Hyperledger Fabric documentation.
### GetAssetHistory
The `GetAssetHistory` function in the smart contract uses the `GetHistoryForKey` API to return every change made to an asset since it was first created on the ledger, providing full auditability for asset transfers.
## Running the sample
The Fabric test network is used to deploy and run this sample. Follow these steps in order:
1. Create the test network and a channel (from the `test-network` folder). Use the `-s couchdb` flag to enable rich query support.
```shell
./network.sh up createChannel -c mychannel -ca -s couchdb
```
2. Deploy one of the smart contract implementations (from the `test-network` folder).
- To deploy the **Go** chaincode implementation:
```shell
./network.sh deployCC -ccn ledger -ccp ../asset-transfer-ledger-queries/chaincode-go/ -ccl go
```
- To deploy the **JavaScript** chaincode implementation:
```shell
./network.sh deployCC -ccn ledger -ccp ../asset-transfer-ledger-queries/chaincode-javascript/ -ccl javascript
```
- To deploy the **TypeScript** chaincode implementation:
```shell
./network.sh deployCC -ccn ledger -ccp ../asset-transfer-ledger-queries/chaincode-typescript/ -ccl typescript
```
3. Run the application (from the `asset-transfer-ledger-queries/application-javascript` folder).
```shell
cd application-javascript
npm install
node app.js
```
## Clean up
When you are finished, you can bring down the test network (from the `test-network` folder). The command will remove all the nodes of the test network, and delete any ledger data that you created.
```shell
./network.sh down
```

View file

@ -35,7 +35,7 @@ context CLUSTER_RUNTIME kind # or k3s for Rancher
context CONTAINER_CLI docker # or nerdctl for containerd context CONTAINER_CLI docker # or nerdctl for containerd
context CONTAINER_NAMESPACE "" # or "--namespace k8s.io" for containerd / nerdctl context CONTAINER_NAMESPACE "" # or "--namespace k8s.io" for containerd / nerdctl
context FABRIC_CONTAINER_REGISTRY hyperledger context FABRIC_CONTAINER_REGISTRY ghcr.io/hyperledger
context FABRIC_PEER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-peer:${FABRIC_VERSION} context FABRIC_PEER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-peer:${FABRIC_VERSION}
context COUCHDB_VERSION 3.4.2 context COUCHDB_VERSION 3.4.2
context NETWORK_NAME test-network context NETWORK_NAME test-network