How to Set Up and Deploy a FabCar Blockchain Sample Using Hyperledger Fabric on IBM Blockchain Platform

Jan 20, 2022 | Blockchain

In this article, we will guide you step-by-step on how to set up a blockchain network on the IBM Blockchain Platform using the FabCar sample. Whether you’re a seasoned developer or a curious beginner, this guide will help you through the process of deploying a smart contract and interacting with it through a web application.

Prerequisites

Setting Up the FabCar Blockchain

1. Clone the Repo

Clone this FabCar repository to your desired folder:

git clone https://github.com/IBM/fabcar-blockchain-sample.git
cd fabcar-blockchain-sample

2. Package the Smart Contract

Open Visual Studio Code and load the contract folder from your cloned repository.

Use the IBM Blockchain Platform extension to package the smart contract:

  • Press F1 to see commands and select IBM Blockchain Platform: Package Open Project.
  • Right-click on the packaged contract, select Export Package, and save it as a .cds file for later use.

3. Create IBM Cloud Services

4. Build a Network

Follow the IBM Blockchain Platform documentation to complete these tasks:

  • Create a channel with a single peer organization.
  • Set up the necessary identities for deploying peers and operating nodes.

Understanding the FabCar Blockchain Setup with an Analogy

Imagine you’re setting up an amusement park – the IBM Blockchain Platform serves as the park itself, where you can build various attractions (the Hyperledger Fabric network) for visitors (users). Each ride is like a smart contract that delivers a unique experience, and your Node.js application functions as the ticket booth, facilitating access to those rides. Meanwhile, the Angular client acts as a fun map, guiding users around the park to ensure they find the attractions they desire.

Deploying the FabCar Smart Contract and Running the Application

5. Deploy FabCar Smart Contract on the Network

  • Install the smart contract via the IBM Blockchain Platform console.
  • Instantiate the smart contract on the channel you created.

6. Connect Application to the Network

Download the connection profile from your organization and ensure the Node.js application has the right settings to connect to the network.

7. Run the Application

Enroll the admin and register the user:

cd web-appserver
npm install
node enrollAdmin.js
node registerUser.js

Start the application server as well as the web client to interact with the FabCar smart contract:

npm start
cd web-appclient
npm install
npm start

Your web application should now be running; navigate to http://localhost:4200 to view it in action.

Troubleshooting

  • If you encounter an error stating “access denied,” ensure that gatewayDiscovery in your config.json file is correctly set up:
  • gatewayDiscovery: {
      enabled: true,
      asLocalhost: false
    }
  • Facing a TypeError regarding options.ca? Edit your connection profile to ensure the pem value isn’t an array.
  • If you see a self-signed certificate error during registration, add httpOptions: verify: false to the certification authorities section of your connection profile.
  • To deregister a user, ensure that the application admin has the hf.Revoker attribute set to true.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

Congratulations! You’ve successfully set up a FabCar blockchain sample on the IBM Blockchain Platform. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Useful Links

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox