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
- IBM Cloud account
- Node.js v10.x and npm v6.x or greater
- VSCode version 1.38.0 or greater
- IBM Blockchain Platform Extension for VS Code
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
- Create the IBM Cloud Kubernetes Service (use the Free cluster for this code pattern).
- Create the IBM Blockchain Platform service on IBM Cloud.
- Wait for the services to be deployed fully—in some cases, this could take about 20 minutes.
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
}
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.