Rebai Hamida
4 min readJul 25, 2018

--

Azure Blockchain Workbench — Add new application

Table of Contents

- Introduction

- Smart Contract

- Deploy a new Application

- Conclusion

Introduction

Blockchain is an Enabling technology with a big potential.

Azure Blockchain Workbench is created for developer 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 guarantee a quick spin up along the implementation by creating a smart contracts , so, you will not be brought to care 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 explain how we can add a new application by deploying a smart contract.

Once deployed, we will access to 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 smart contract. Once smart contract is instantiated in the workbench, the Administrator can assign users, deploy demo contracts and deploy custom contracts.

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.

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

What is smart contract?

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

I GitHub, we can use any sample:

https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/application-and-smart-contract-samples/

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

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: https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/application-and-smart-contract-samples/simple-marketplace/ethereum

SimpleMarketplace.json define the configuration of the blockchain application.

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

Create or Update Contract

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

function WorkbenchBase(string applicationName, string workflowName) internal {

ApplicationName = applicationName;

WorkflowName = workflowName;

}

After the contracts should inherit from the base class WorkbenchBase

contract SimpleMarketplace is WorkbenchBase(‘SimpleMarketplace’, ‘SimpleMarketplace’)

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

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’);

}

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 contract from the interface:

Add contract

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

--

--

Rebai Hamida

Senior Cloud Application Architect, Microsoft MVP in Developer Technologies, MCT, Technical writer, Speaker