Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

Deploy a New Application in Azure Blockchain Workbench

5.00/5 (1 vote)
26 Jul 2018CPOL3 min read 8.4K  
In this article, we will describe how we can deploy a new application in Azure Blockchain Workbench.

Introduction

Azure Blockchain Workbench is created for developers as a helper 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 a smart contract, so, you will not be brought to care about the infrastructure and configuration because you will use Azure's 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 explain 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 the application.

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

Image 1Jump 

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.

Image 3

Smart Contracts

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

What is Smart Contract?

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

In GitHub, we can use any sample:

To be able to open these samples, we need to install Visual Studio Code (https://code.visualstudio.com/ Jump ) and Solidity plugin (https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity Jump ).

Image 7Jump

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 defines the configuration of the blockchain application.

Image 11Jump

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

Image 13Jump

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

JavaScript
function WorkbenchBase(string applicationName, string workflowName) internal {
        ApplicationName = applicationName;
        WorkflowName = workflowName;
    }

After the contracts should inherit from the base class WorkbenchBase:

JavaScript
contract SimpleMarketplace is WorkbenchBase('SimpleMarketplace', 'SimpleMarketplace')

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

JavaScript
enum StateType {
      ItemAvailable,
      OfferPlaced,
      Accepted
    }
function MakeOffer(int offerPrice) public
    {
        if (offerPrice == 0)
        {
            revert();
        }
        if (State != StateType.ItemAvailable)
        {
            revert();
        }
       
        if (InstanceOwner == msg.sender)
        {
            revert();
        }
        InstanceBuyer = msg.sender;
        OfferPrice = offerPrice;
        State = StateType.OfferPlaced;
        ContractUpdated('MakeOffer');
    }

Deploy Smart Contracts

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

  1. Connect as Administrator in Azure Blockchain Workbench.
  2. Select Applications > New.  The New Application pane appears.
  3. Select Upload the contract configuration after Browse to load the configuration file SimpleMarketplace.json.
  4. Select Upload the contract code after Browse to load the SimpleMarketplace.sol file.
  5. Select Deploy to create our application.
  6. Few minutes and the new application appears in Applications.

We can create more contracts from the interface:

Image 15 Jump

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

Azure Blockchain Workbench lets 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 in secure and distributed ledger and it is stand up the scaffolding around the blockchain application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)