Published: June 19, 2019

Tags:

Blockchain continues to be one of those mysterious technologies that are marred in controversy. There are several different camps with their own perspectives. We have those who feel it is truly a transformational technology due to its trust-building characteristics and its ability to embed transparency in every single transaction. We have some people, like Warren Buffett, in the middle of this spectrum who feels blockchain technology is important, but that cryptocurrency has no value at all. In addition, we have sceptics that claim blockchain is too slow to have any material impact on the industry. For example, credit cards and other traditional transaction processing systems can handle tens of thousands of transactions per second vs 3-7 transactions per second on the Bitcoin blockchain and about 15 transactions per second on the Ethereum blockchain. Lastly, we have the speculative nature of cryptocurrencies, which have projects that are based-upon blockchain variant implementations.

Regardless of which camp you fall into, I firmly believe that understanding the opportunities that exist with emerging technologies is important. Some technologies fall flat on their face, whereas some technologies will have a pervasive impact on society. I also believe that we need to keep an eye on “where the puck is going”. Just because technology, in its current form, may not be ready for primetime, doesn’t mean that it can’t be, in the not so distant future. I like to relate this situation to a Gary Vaynerchukquote:

Don’t try to find all the answers. It’s okay to not know everything and still take that leap of faith. That’s how you learned how to ride a bicycle, how to drive a car, and that’s how you learn how to succeed.

While a lot of blockchain skepticism is warranted, I am still optimistic that a future iteration of today’s blockchain will emerge as a useful tool for commerce. Until that day arrives, I am currently monitoring and learning about technology whenever time permits.

Microsoft, Amazon, and IBM are some of the technology majors that have been making significant investments in blockchain technology. In this post, we are going to discuss a popular, open-source blockchain implementation called Ethereum and the offerings that Microsoft is building around it inside of Azure. Since this blog post is primarily focused on integration technologies, we are going to focus on the new Azure Logic Apps (and Microsoft Flow) Ethereum connector that we can use to publish and subscribe to Ethereum blockchain events.

Announcement on Azure Blockchain Service

At the recent Build conference in Seattle, Microsoft announced a new blockchain offering called Azure Blockchain Service.

Here is what Scott Guthrie had to say about the service:

“Blockchain is showing potential across many industries to manage complex workflows and logistics. Last year we announced Azure Blockchain Workbench, which gave developers a simple UI to model blockchain applications on a preconfigured Azure-supported network. Today we are doubling down on our investments to empower blockchain developers by announcing Azure Blockchain Service, which simplifies the formation, management, and governance of consortium blockchain networks, allowing businesses to focus on workflow logic and app development. Azure Blockchain Service deploys a fully managed consortium network and offers built-in governance for common management tasks, such as adding new members, setting permissions and authenticating user applications.”

Now within the announcement, notice that Scott mentioned the term “consortium blockchain networks”. Therefore, some of the content in the introduction paragraph is important. With this implementation, we are not talking about cryptocurrency, but rather generating transactions across business partners within a closed network. There are no mining rewards, no price volatility, just a secure platform for commerce to take place.

Provisioning an Azure Blockchain Service Instance

Before we can start talking about Azure Logic Apps connectivity, we need to provision an Azure Blockchain Service instance on Azure. The steps required to provision an Azure Blockchain Service have been captured in the Azure product documentation.

Something to be mindful of when provisioning your instance is the validator nodes that are required. By default, Standard instances are provisioned which have a significant cost. For the purpose of this post, we can use the Basic version which is around 1/7th of the cost.

Once your deployment is complete, you will find an Azure Blockchain Service instance within your specified Resource Group.

An area that you need to become familiar with your Transaction node endpoint configuration which you can access from the Transaction nodes left navigation and then select your node.

Next, click on Connection strings and note your Access keys. You will need this information later when connecting from MetaMask Azure Logic Apps.

Also, note that the section below called Sample Code. We will also need this information when we need to create an account to send transactions from Azure Logic Apps.

At this point, we have our Azure Blockchain Service instance provisioned and the access required to start interacting with our blockchain.

Creating Smart Contract

One of the value propositions of using Ethereum over some other blockchain projects is the ability to create a smart contract. You can think of a smart contract much like an agreement that outlines the terms of a relationship. It may impose different responsibilities on a service requestor or service provider.

The scope of this post is not to go into a deep dive of creating smart contracts as there are many resources already available on the web.

To build a smart contract, we will use a web-based IDE called Remix. To create a new smart contract we will click on the + sign and then provide a name for our smart contract called myPostBox.sol.

We can now copy and paste the following code which represents our smart contract. Our smart contract is quite simple, we have 3 methods that allow us to post a message, get the message posted – kinda like a typical “echo” demo and lastly determine how many times our smart contract has been called.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

pragma solidity^0.4.22;

contractmyPostBox{

stringmessage;

int64 count;

event Posted(stringmessage);

functionpostMsg(stringtext)public{

emit Posted(text);

count++;

message=text;

}

functiongetMsg()publicview returns(string){

returnmessage;

}

functiongetCount()publicview returns(int64){

returncount;

}

}

A couple of things to note:

On the first line, we will see the following statement: pragma solidity ^0.4.22; What this means is that this contract requires version 4.22 of the solidity compiler or higher. When it comes to choosing your compiler version, keep this in mind.

To address this, I have chosen the compiler version: V0.4.22+commit.4cb486ee.Emscripten.clang which will provide for a successful compilation.

At this point, we have a compiled version of our smart contract, but we haven’t deployed it anywhere. We now want to deploy it to our Azure Blockchain Services instance. We can perform this deployment from Remix, but we need to establish a connection to Azure first. We can do that using a chrome extension called MetaMask. Once we have it installed, we can click on it from the top right-hand corner of our Chrome browser.

By default, MetaMask can connect to a variety of Ethereum networks including Main Ethereum Network and test networks. Since we have a private network, we will select Custom RPC.

Recall earlier in the post when we discussed Azure Blockchain Service Connection strings? This is where we need to use one of our HTTP Access Keys as our New RPC URL. In addition, we need to provide a Network Name.

With your Remix tab still active in Chrome, click on the MetaMask icon again and then click on the Connect button.

We can now deploy our smart contract by clicking on the Run tab inside of Remix. For Environment, we need to select Injected Web3 which represents the network we just created in MetaMask. We can now click on the Deploy button to deploy our smart contract.

At the bottom of the Remix IDE, you see a message that looks like the following that confirms your contract has been deployed.

Let’s now go ahead and test our smart contract. We can do so by clicking on our deployed smart contract instance.

We can then call any of the 3 methods that are exposed. To start with, let’s provide a string text message and then click on postMsg button.

We can now go ahead and click on getMsg button which should now return this value from our smart contract.

We can also click on the getCount button to see how many times we have posted a message.

Subscribing to Ethereum Events using Azure Logic Apps

Within our smart contract, a declaration exists for an event called Posted that takes a string. We subsequently call this event within our postMsg.

Using Azure Logic Apps we can subscribe to these events. Why would we want to do this? Blockchains are primarily good a tracking transactions in a permission-less, distributed manner. It is not a great tool to integrate with other systems like ERPs, CRMs or even reporting platforms. But, Azure Logic Apps is really good as a connectivity platform that can connect with all of these systems. By using Azure Logic Apps we can subscribe to blockchain events and then integrate with other systems.

Let’s now connect Azure Logic Apps to our Ethereum blockchain instance. To do so we need to perform the following steps:

We need to search for the Ethereum Blockchain connector and then select the When a smart contract event occurs trigger.

We now need to establish a connection by providing a Connection Name and Ethereum RPC Endpoint. The connection name is naturally arbitrary, but for our Ethereum RPC Endpoint, we need to provide one of our HTTPS Action Keys that we discussed earlier in this post when connecting from MetaMask.

Note:Since we are only using this connection to read events off of the blockchain, we do not need a Private Key. However, when we submit events to the blockchain later in this post, we will require a private key.

With our connection established, we now need to configure some additional details, including Contract ABI, Smart Contract Address and Event Name.

Our Contract ABI can be retrieved from our Remix session. Within Remix, we can click on the Compile tab and then click on the ABI label which will copy this definition for us. You can think of an ABI, kinda like Swagger for an API. It defines the messaging contract between two parties. Once we have our ABI definition, we can paste it into Azure Logic Apps.

Our Smart Contract Address can also be retrieved from Remix. From the Run tab, we can click on the clipboard beside our deployed smart contract. We can now paste this value into our Logic App trigger.

With both our ABI and Smart Contract Address populated, we can now select our Event Name which is called Posted.

Since the Ethereum trigger is a polling trigger, we can change this value as appropriate.

To keep things simple, we will just publish these events to a Request Bin instance to demonstrate that we can take these blockchain events and publish them elsewhere. As you would expect from a Logic Apps trigger, we have access to Dynamic content which we can use to populate our HTTP Body message.

We can now go ahead and test our logic app by adding by calling our postMsg function in our smart contract.

In our next Azure Logic Apps polling interval, we will discover that it has picked up this event and published it to Request Bin

Publishing Transactions to Azure Blockchain Service from Azure Logic Apps

The process for publishing is very similar to subscribing with one major difference. We need to have a private key to sign our message before it is added to the blockchain. Private keys are critical in security blockchain applications which you can read more about here.

Perhaps I have missed something, but when provisioning an Azure Blockchain Service instance, nowhere has a private key been provided to me and the credentials that are found within our HTTP Access keys are not private keys.

However, we can use the information found in our endpoint configurations to create an account and subsequently a private key. A walkthrough does exist in the Azure documentation that outlines the process of connecting to our blockchain instance using command line tools. The most significant tool that we need is called Truffle. But, Truffle has some dependencies. I struggled to get all of this working, but after installing:

js

Python

Configured Windows Python PATH variable

C++ (by creating a Visual Studio C++ project)

Truffle

Web3

I was able to get this all working, but getting all of the pre-requisites took some determination and perseverance. Bottom line, if you can’t get Web3 to be installed cleanly, you won’t be able to create an account/private key on your blockchain instance.

With our prerequisites installed from the walkthrough, we need to connect to our blockchain instance using truffle. From a Node.js command prompt (as Administrator) issue the following commands:

Now create a new account with the following statement: web3.eth.accounts.create(); The result will be a new account is created which includes the address of the account and the private key which is exactly what we need to send transactions from Azure Logic Apps.

We will now use this information to create a new connection in Azure Logic Apps that includes a private key so that we can sign our transactions. It also needs to include our Ethereum RPC Endpoint which we can once again use one of our HTTP Access Keys that we covered in the MetaMask section.

With our connection established, we need to choose our Action which in this case will be Execute smart contract function (incurring gas cost)

Much like our subscribe example, we need to provide our ABI and Smart Contract Address. We also need to provide our Smart Contract Function Name which is postMsg and then provide our Text input.

Since we are just using a Recurrence trigger, we can just go ahead and Run our logic app.

If we now go back to our logic app that is subscribing to blockchain events, we will discover that it has picked up the event related to the transaction that we just created from Azure Logic Apps.

Conclusion

In this blog post, we introduced a new offering from Microsoft called Azure Blockchain Service. Using this service, we can establish a consortium blockchain based upon Ethereum. We also created a simple, smart contract which we deployed to our Azure blockchain instance. We then used the new Ethereum connector to both subscribe to blockchain events and to create new transactions. Azure Logic Apps provides a simple way to connect to your blockchain instance which you can subsequently integrate with many lines of business or SaaS applications. For additional Azure Blockchain Services use cases, please refer to their devkit which is hosted on GitHub.

Related Posts

Author: Kent Weare

Kent Weare is a Microsoft Azure MVP, he has worked on projects for the Canadian Federal Government, a multi-national bank in New York City and integrated Health Care projects throughout Canada. His role as a Senior Enterprise Architect and Integration allows him to get involved in a variety of technology projects for a large Energy company. Since 2004, Kent has been very active in the Integration space having worked with every version of BizTalk from 2004 onwards. He has also spent time using competitor tools including Intersystems, IBM and MuleSoft. He is very passionate about Architecture especially if it involves integrating different systems.
View all posts by Kent Weare