Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Develop a Blockchain application using Oracle Blockchain Platform
Introduction
Blockchain technology is revolutionizing the way businesses and organizations operate, and it has given rise to a new era of applications that can bring about unprecedented levels of transparency, security, and decentralization.
Oracle Blockchain Platform gives you a pre-assembled platform for building and running smart contracts and maintaining a tamper-proof distributed ledger. With Oracle Blockchain Platform, you complete some simple instance creation steps, and then Oracle takes care of service management, patching, backup and restore, and other service lifecycle tasks.
Objective
To help you get started with developing a Blockchain application using Oracle Blockchain Platform, this tutorial provides a high-level overview of the key concepts and steps involved.
Prerequisites
-
A basic understanding of Blockchain technology and Oracle Cloud.
-
Consider if Blockchain is required:
Study your use-case thoroughly. Will a database or any other technology be able to provide the same solution? Blockchain is much more than a simple database and has the ability to transform businesses. Consider Blockchain when you do not want to rely on a third-party or suffer the delays inherent in an offline reconciliation process. Blockchain can also be used to trace the entire lifecycle of products. Also, it is worth noting that Blockchain needs participation from all parties and points of contact involved. After this step, you should to be able to answer the question ‘Why Blockchain?’. For more information, see Why should I use blockchain
-
Define the use case
The first step is to define the use case for your Blockchain application. This involves identifying the problem you want to solve and how Blockchain technology can be used to address it. It is also important to consider the target audience and their needs when defining the use case.
-
Decide on the Blockchain Platform
Public Blockchain Platforms allow anyone to join, read and write data on the Blockchain network. Most types of cryptocurrencies run on a public blockchain that is governed by rules or consensus algorithms. On the contrary, permissioned blockchain allows organizations to set controls on who can access blockchain data. Only users who are granted permissions can access specific sets of data. Depending on your use case, you need to decide on the type of Blockchain Platform.
Oracle Blockchain Platform is based on the permissioned Hyperledger Fabric project developed by Linux Foundation. Oracle Blockchain Platform includes all the dependencies required to support a blockchain network: compute, storage, containers, identity services, event services, and management services. Oracle Blockchain Platform also includes the blockchain network console to support integrated operations.
Task 1: Create an Oracle Blockchain Platform instance
-
Log in to the OCI Console.
-
Select the compartment where you have appropriate privileges to create an instance.
-
Provide a Display name for your instance, select the Platform Role, version and the required Edition.
-
Click Create.
-
For each member organization participating in your Blockchain network, create an Oracle Blockchain Platform instance. For more information, see Create an OBP instance.
At the end of this step, you will have all the infrastructure ready to run a Blockchain application.
Task 2: Set up your development environment
The Blockchain App Builder supports the full development lifecycle either from a command line interface or as an extension for Visual Studio Code. Blockchain App Builder for Oracle Blockchain Platform is a tool set that assists with rapid development, testing, and deployment of chaincode on Oracle Blockchain Platform. You can download the Visual Studio Code extension for App Builder from the Samples tab in the Oracle Blockchain Platform Console.
For more information, see Install App Builder.
Task 3: Create a Data Model for your Blockchain application
-
Depending on the identified use case, decide the parameters that will be stored on the Blockchain.
-
For the purpose of simplicity, let us consider an example of a Blockchain application for transferring ownership of Marble tiles. In this case, the marble details such as color of the marble, size, owner and Id are be required to write the Blockchain code, known as chaincode.
-
For creating the Data Model, only consider the object metadata. Non-transaction data such as pictures, PDF, and so on. are not required in the Data Model for Blockchain. This is called off-chain data.
-
Determine your on-chain and off-chain data and also decide on the storage for off-chain data.
Task 4. Create a specification file using the Data Model
-
Using the data model created in Task 3, write a simple specification file in either
yaml
orjson
. For more information, see Create a specification file. -
In this specification file, you can specify multiple asset definitions and behavior, validation of arguments and CRUD and non-CRUD method declaration.
-
Sample specification files in both formats (
yaml
andjson
) can be found in the Blockchain App Builder downloaded package.
Task 5. Generate the chaincode file
-
The Oracle Blockchain App Builder takes the input from your specification file and generates a fully-functional scaffolded chaincode project.
-
Generate the chaincode using Oracle Blockchain App Builder in either Typescript or Go Lang and add any required custom functions to it. For more information, see Generate Chaincode.
Now you are ready to deploy the chaincode on Oracle Blockchain Platform.
Task 6. Deploy and test the chaincode
-
Deploying a chaincode consists of approving and committing the chaincode definition.
-
Use the Blockchain App Builder to deploy your chaincode onto the Oracle Blockchain Platform.
-
Add your Oracle Blockchain Platform instance details in the Environment section in the App Builder and then deploy the chaincode. For more information, see Deploy Chaincode.
-
You can also package your chaincode project and manually deploy it to Oracle Blockchain Platform. Deploy Chaincode using VS Code.
-
Once your chaincode is deployed, next step is to test the deployed chaincode. As part of the testing, you can invoke transactions or query the chaincode. Blockchain App Builder can be used for performing both invoking and querying and also for multi-user testing. For more information, see Test your chaincode.
Task 7: Use SDKs and REST APIs to develop the application
- Oracle Blockchain Platform uses Hyperledger Fabric as its foundation.
- Use the Hyperledger Fabric documentation to help you write applications. For more information, see Hyperledger Fabric docs.
- Install and use the Hyperledger Fabric SDKs to develop applications for Oracle Blockchain Platform. For more information, see Use Fabric SDKs.
- The REST APIs provided by Oracle Blockchain Platform have been created with maximum flexibility in mind; you can invoke a transaction, invoke a query, or view the status of a transaction. For more information, see Use REST APIs.
Tip: Read the Key Concepts and Tutorials sections before you write your own application.
Related Links
Acknowledgments
- Authors - Bhupendra Raghuwanshi (Senior Cloud Engineer), Deepika Nayak (Staff Cloud Engineer)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Develop a Blockchain application using Oracle Blockchain Platform
F78393-01
February 2023
Copyright © 2023, Oracle and/or its affiliates.