With the dramatic upsurge of COVID-19, also known as Coronavirus, all over the world, the healthcare industry was the first to face its adve...
We will be using Hyperledger Fabric Node and IBM Blockchain Starter Plan to invoke chaincode for error-free results and automatic processing while creating an auction system. In this example, we are creating a network on Blockchain that simulates a car auction network.
Hyperledger Composer and Hyperledger Fabric Node SDK
Hyperledger Composer is an open development toolset and framework which is very extensive and helps make Blockchain application development easier. Its primary purpose is to save time and make the development process more efficient, which allows easy integration of Blockchain applications into existing business systems.
IBM Blockchain Starter Plan
IBM Platform Blockchain Starter Plan is an entry-level offering that allows businesses to simulate Blockchain networks, work with business networks, and enables prompt development of applications. It is a development and testing platform, not ideal for production. The Starter Plan network is built on the Hyperledger Fabric SDK.
This can be used for vehicle auctions in this scenario, but it can be expanded for use in many other types. Bidding, art auctions, vintage pieces, can all be worked upon in this process. This kind of process encourages transparency in a free market, as well as real-time inputs where all bids are verified on the chaincode system itself, which identifies errors on its own, thus ensuring that the correct winner is selected. After this, the Hyperledger is updated with the information automatically, thus ensuring that any bidding process conducted by this framework will take place error-free and seamlessly.
Development and Process Description
In this case, three components are of primary importance to develop the application: members of the auction, the vehicle in question, and an informational listing about the vehicle where the aforementioned members can place bids. Once the Starter Plan cloud service has been created, you can connect your Node app to the certificate authority (CA) of the Starter Plan. Once the credentials are given by the CA, each transaction (also called a chain code invocation) will have its own credentials and will be visible on a peer-to-peer network for easy verification.
Once the chaincode has been installed on peers and instantiated, it populates your auction. In this code, it will populate with three members, one vehicle and one informational listing where bids and offers can be made. The requirement is to make offers and sell the car, which can be done by simply invoking the chaincode, where it will check bids, ensure that they are error-free, and ensure that the correct highest bidder wins. The ledger then updates with this information where the highest bidder wins the auction and hence the car, and the seller gets the winning offer price. All the chaincode invocations are saved as blocks in the IBM Blockchain Starter Plan.
Intro to Certificate Authority
The first step before diving into the car-auction logic is to enroll your application with the Certificate Authority from the IBM Blockchain Starter Plan. To do this, you need to give your application the API endpoints of the CA on the IBM Blockchain Starter plan so your app can interact with the network. The CA will then provide you with certificates that will prove your authenticity to the network, allowing you to transact (invoke chaincode) on the network.
Note: Any calls to the Hyperledger Fabric network will have to be signed with a private key and a properly signed X.509 certificate for verification purposes. Each of the actors within your network (peers, orderers, client apps, admins) will have a digital identity encapsulated in an X.509 certificate. You’ll need certificates for both an admin user and a new user, which you can call user1.
Intro to Chaincode
After you have finished generating keys and certificates, you need to install the chaincode on your peers. After the chaincode is installed, you will instantiate it, which will call the chaincode constructor and create blocks on the ledger. This is seen in the initLedger function from the chaincode/carauction.js file. This will create a vehicle, a few members, and a vehicle listing (or a listing on which members can bid). After that, the members make offers for the car, which is actually invoking chaincode under the hood.
Note: When you invoke chaincode, you are making a transaction on the blockchain network. This is extremely important. Chaincode is how you make transactions on the network. When you make an offer, the chaincode checks for two types of errors:
1. The owner of the car bids on his own car.
2. The bidder doesn’t have enough money in his account to make the bid.
If both checks are passed, an offer is recorded on the ledger. Once the auction closes, you call
the closeBidding transaction as seen in the chaincode/carauction.js file. That gives the car to the highest bidder, transferring funds from the buyer to the seller so the buyer gains ownership of the car.
To ensure that your auction has worked correctly, you can query the ledger at the end to ensure that the car has the correct owner and that the seller has been credited the correct amount in their account.
Finally, you can check the logs of the peers on the IBM Blockchain Starter Plan, and also view the details of the blocks to see how transactions are recorded.
When you have completed this code pattern, you will understand how to:
- Interact with the IBM Blockchain Starter Plan
- Build a blockchain network using Hyperledger Fabric Node SDK
- Inspect and read logs from applications that are connected to the IBM Blockchain Starter Plan
1. User downloads IBM Blockchain Starter Plan connection profile and adds the URL/secret for the CA in the Node app.
2. User enrolls the admin and registers a user with the CA.
3. The user installs, instantiates, and invokes the car auction chaincode on the peer.
4. Ledger is updated, blocks are added to the Starter Plan service, and the response is sent to the Node app.
Find the detailed instructions in the README. These steps show you how to:
1. Clone the repo
2. Enroll the app
3. Register users
4. Invoke the chaincode
5. Run the app
6. Query the ledger
For more information, visit https://ibm.co/2JnhR0l