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.
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.
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/ ) 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
:
SimpleMarketplace.json defines the configuration of the blockchain application.
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()
.
We have like a constructor in object-oriented language the WorkbenchBase
that receives the ApplicationName
and the WorkflowName
as parameters.
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');
}
Deploy Smart Contracts
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.
- Few minutes and the new application appears in Applications.
We can create more contracts from the interface:
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.