Deploy A New Application In Azure Blockchain Workbench

Table of Contents

  • Introduction
  • Smart Contract
  • Deploy a new Application
  • Conclusion

Introduction

The blockchain is an Enabling technology with big potential.

Azure Blockchain Workbench is created for developers as a helpful easy framework. To implement a blockchain ledger, you will focus only in the application and the workflow associated, test different scenarios between them in a flexible way that guarantees a quick spin up along the implementation. By creating smart contracts you will not need to worry about the infrastructure and configuration because you will use Azures services to ensure the optimization of the transactions verifications and the dismiss of the resource and the performance overhead costs of mining.

In the previous article, we described Azure Blockchain Workbench deployment, we configured Azure AD and we added Azure AD users in Azure Blockchain Workbench and in this article, we will discuss how we can add a new application by deploying a smart contract.

Once deployed, we will access the first URL, it is the Backend part where you will see an Azure AD login experience where you will enter your work or your personal Microsoft account credentials to access to the application.

We are going to focus on creating a smart contract. Once a smart contract is instantiated in the workbench, the Administrator can assign users, deploy demo contracts and deploy custom contracts.

Blockchain

Once the Azure Blockchain Workbench is deployed, we will access by navigating to its URL. You’ll see an Azure AD-backed login experience where you can enter your work or personal Microsoft account credentials to access the application.

The second URL is the Azure Blockchain Workbench REST API offers consumable services to facilitate the application integration by developers or Blockchain users.

Blockchain

Let’s start with smart contracts, that contain business logic conducting the different scenario flows.

What is a smart contract?

They are written in the specific language, for example, Solidity for Ethereum and deployed to all nodes on the blockchain. (https://www.ethereum.org)

From GitHub, we can use any sample,

To be able to open these simple, we need to install the Visual Studio Code and Solidity plugin.

Blockchain

If we open any sample, we find that it includes two files: JSON file and Sol file.

We will use in this article this sample SimpleMarketplace.

SimpleMarketplace.json define the configuration of the Blockchain Application.

Blockchain

SimpleMarketplace.sol written in Solidity language used in Ethereum, it allows the developer to create and update the contract and this is realized by these methods: ContractCreated() and ContractUpdated()

Blockchain

We have like a constructor in object-oriented language the WorkbenchBase that receives as a parameter the ApplicationName and the WorkflowName.

  1. function WorkbenchBase(string applicationName, string workflowName) internal {  
  2.         ApplicationName = applicationName;  
  3.         WorkflowName = workflowName;  
  4.     }  

After that the contracts should inherit from the base class WorkbenchBase

  1. contract SimpleMarketplace is WorkbenchBase('SimpleMarketplace''SimpleMarketplace')  

We have Set of States that are used after in the Functions:

  1. enum StateType {   
  2.       ItemAvailable,  
  3.       OfferPlaced,  
  4.       Accepted  
  5.     }  
  6.   
  7. function MakeOffer(int offerPrice) public  
  8.     {  
  9.         if (offerPrice == 0)  
  10.         {  
  11.             revert();  
  12.         }  
  13.   
  14.         if (State != StateType.ItemAvailable)  
  15.         {  
  16.             revert();  
  17.         }  
  18.           
  19.         if (InstanceOwner == msg.sender)  
  20.         {  
  21.             revert();  
  22.         }  
  23.   
  24.         InstanceBuyer = msg.sender;  
  25.         OfferPrice = offerPrice;  
  26.         State = StateType.OfferPlaced;  
  27.         ContractUpdated('MakeOffer');  
  28.     }  

This application can be deployed in our workbench in this way,

  • Connect as Administrator in Azure Blockchain Workbench.
  • Select Applications > New. The New Application pane appears.
  • Select Upload the contract configuration after Browse to load the configuration file SimpleMarketplace.json.
  • Select Upload the contract code after Browse to load the SimpleMarketplace.sol file.
  • Select Deploy to create our application.
  • Wait a few minutes and the new application appears in Applications.

We can create more contract from the interface,

Blockchain

The same interface allows the Administrator to create more users or deploy custom contracts.

Azure Blockchain Workbench let you integrate other services like Azure Logic, Apps, Web APIs, Notification Hubs…

Conclusion

In this article, we describe using an existent sample the way of deploying a new application in Azure Blockchain Workbench.

Azure Blockchain Workbench uses a shared view of a business process but is an insecure and distributed ledger and it stands  up to the scaffolding around the blockchain application.


Similar Articles