- Description
- Pre-requisites
- Hyperledger Fabric network
- Deploy the network
- Web Application
- Firefly fabconnect
This project has been developed using Hyperledger Fabric private blockchain. The blockchain has only one organization and the network topology can be seen in the image below. In addition, a REST API developed in Nest.js is available that allows connecting to the blockchain through the Fabric SDK, registering and enrolling a user through the Fabric CA, and making invocations and queries to the blockchain.
Hyperledger Firefly fabconnect can be connected to the blockchain using the configuration file that is available in the project.
Along with the blockchain, an ERC20-token Smart Contract is deployed which implements Hash TimeLock (HTLC) functions, those functions allow transfers to be blocked until the requirements are met, thus achieving atomic swaps.
- Hyperledger Fabric v2.4
- Hyperledger Fabric CA v1.5
- Docker v20.10
- Docker-Compose v2.14.0
- Golang v1.19.4
- NodeJS / TypeScript v16.13.0
- npm v9.2.0
Note: This has been developed using macOS, other OS have not been tested.
The Hyperledger Fabric network consists of:
- One orderer
- orderer.example.com
- One organization
- MSPID: Org1MSP
- Two peers:
- peer0.org1.example.com
- peer1.org1.example.com
- One CouchDB state database deployment for each peer
- Fabric CA
- ca.org1.example.com
- Fabric CLI
-
Install Hyperledger Fabric latest docker images and binaries.
./install-fabric.sh
this will generate a
fabric-samplesfolder inside the project directory.Note: The
fabric-samplesfolder is not needed, as we will only be using the downloaded Docker images to deploy the network -
Generate the network artifacts.
cd network-files ./generate.sh -
Deploy the network.
./start.sh
-
Teardown the network
./teardown.sh
The ERC-20 token chaincode can be tested making use of the CLI Docker container. In order to do so, get a shell inside the container:
docker exec -it cli bashOnce inside, some transactions can be submitted using the peer chaincode command. Note that this chaincode needs to be initialized, therefore the Initialize function must be executed first.
-
Initialize
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile $ORDERER_TLS_CA -C default -n erc20token --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"function":"Initialize","args":["mytoken", "mysymbol", "2"]}' --waitForEvent
-
Mint some tokens
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile $ORDERER_TLS_CA -C default -n erc20token --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"function":"Mint","args":["5000"]}' --waitForEvent
-
Query the account balance
peer chaincode query -C default -n erc20token -c '{"function":"ClientAccountBalance","Args":[]}'
A Web Application is made available using Nest.js
cd webapp/npm installnpm startWhenever the web application is started, the user for the application is registered and enrolled on the Fabric CA making use of the Fabric SDK.
The configuration is specified in webapp/src/blockchain/fabric.ts. That being the user ID, the channel and chainode names to connect to and the path in which the wallet of the user will be generated.
Transactions can be submitted via the web application. The Nest.js webapp supports both invokes and queries to the blockchain.
The application listens on localhost:3000 and has two endpoints:
-
body:
{ "function": "FunctionName", "args": ["list", "of", "arguments"] }
As mentioned before, this chaincode needs to be initialized in order to use it. Therefore, the Initialize function can be called via POSTMAN.

Furthermore, an Invoke can be made via POSTMAN to Mint some tokens

-
body:
{ "function": "FunctionName", "args": ["list", "of", "arguments"] }Similarly, a
Querycan be made via POSTMAN to get the account balance
Firefly fabconnect is a reliable REST and websocket API to interact with a Fabric network and stream events.
See: https://github.com/hyperledger/firefly-fabconnect
Firefly fabconnect can be connected to the network and used to interact with it.
-
Pull the firefly-fabconnect repository
git pull https://github.com/hyperledger/firefly-fabconnect.git
-
Go into the folder and run
makecd firefly-fabconnect make -
Firefly fabconnect needs 2 configuration files:
firefily-fabconnect-config.jsonwith all the Firefly configuration, andconnection-profile.jsonwith the Hyperledger Fabric blockchain network configuration.firefly-fabconnect-config.jsoncan be found inside thefirefly-fabconnect/folder of this repository.connection-profile.jsonis the one used by the Nest.js WebAPP (Fabric SDK) to connect to the blockchain.Launch the connector:
./fabconnect -f ${PWD}/firefly-fabconnect/firefly-fabconnect-config.jsonAdditionally, here is the
firefly-fabconnect-config.jsonfile's content:{ "maxInFlight": 10, "maxTXWaitTime": 60, "sendConcurrency": 25, "receipts": { "maxDocs": 1000, "queryLimit": 100, "retryInitialDelay": 5, "retryTimeout": 30, "leveldb": { "path": "./receipts" } }, "events": { "webhooksAllowPrivateIPs": true, "leveldb": { "path": "./events" } }, "http": { "port": 3000 }, "rpc": { "useGatewayClient": true, "configPath": "../webapp/src/blockchain/utils/connection-profile.json" } }









