Running a Hyperledger Fabric Gateway application proves that a client identity can connect to a peer gateway, call deployed chaincode, submit ledger updates, and read the committed result. Use it after the local test network and the sample basic chaincode are ready, or before adapting the Gateway client code for another application.
The TypeScript sample uses the Fabric Gateway client API for Node.js. It reads the Org1 user certificate, private key, and peer TLS certificate from the test network, connects to peer0.org1.example.com, and calls the basic chaincode on mychannel.
The sample run initializes assets, queries the ledger, creates a new asset, transfers it asynchronously while waiting for commit status, reads the changed asset, and catches an expected missing-asset error. Keep production identities, hostnames, MSP IDs, channel names, and TLS material out of shared transcripts when replacing the sample values.
$ cd fabric-samples/\ test-network
$ ./network.sh up createChannel \ -c mychannel \ -ca
The Gateway sample expects CA-generated Org1 user material. The -ca option creates those identities for the default sample network.
Related: How to run the Hyperledger Fabric test network
$ ./network.sh deployCC \ -ccn basic \ -ccp ../asset-transfer-basic/\ chaincode-typescript/ \ -ccl typescript Version: 1.0, Sequence: 1 Chaincode initialization is not required
The application can use TypeScript, Go, or Java chaincode, but the TypeScript chaincode keeps the sample paths aligned with the TypeScript Gateway application.
Related: How to deploy Hyperledger Fabric chaincode
$ cd ../asset-transfer-basic
$ cd application-gateway-typescript
$ npm install npm run build tsc added 128 packages audited 129 packages in 11s
The sample package requires Node.js 20 or later and uses npm start to run node dist/app.js.
$ npm start channelName: mychannel chaincodeName: basic mspId: Org1MSP peerEndpoint: localhost:7051 Submit Transaction: InitLedger *** Transaction committed successfully Evaluate Transaction: GetAllAssets *** Result: [ { ID: 'asset1', Owner: 'Tomoko', AppraisedValue: 300 }, ##### snipped ##### ]
The displayed parameters should match the channel, chaincode, MSP, peer endpoint, and peer TLS host alias for the network being tested.
Async Submit Transaction: TransferAsset *** Submitted transfer *** Owner changed from Tom to Saptha *** Waiting for transaction commit *** Transaction committed successfully
submitAsync() returns the smart-contract response first, then getStatus() waits for the transaction commit result.
Evaluate Transaction: ReadAsset *** Result: { AppraisedValue: 1300, Color: 'yellow', ID: 'asset123', Owner: 'Saptha', Size: 5 }
The asset ID includes a timestamp in the sample application, so the exact asset<number> value changes on each run.
Related: How to query Hyperledger Fabric chaincode
Submit Transaction: UpdateAsset asset70 *** Successfully caught the error: EndorseError: 10 ABORTED ##### snipped ##### message: asset70 does not exist
A caught asset70 endorsement error is part of the sample program. A connection error, certificate error, or commit failure means the Gateway endpoint, TLS host alias, identity material, channel, or chaincode name does not match the network.
$ cd ../../test-network
$ ./network.sh down
This removes the test-network containers, generated organizations, channel artifacts, Docker volumes, and generated chaincode images for the sample network.