Calling Ethereum Smart Contracts in Azure Logic Apps

Intro

Microsoft released a preview Logic App Connector to deploy Solidity Smart Contracts, call Functions and execute Transactions.

An example usage scenario would be in case a document is added to the CosmosDB, a Logic App would be triggered to store additional data in the Blockchain.

This article aims to give a step-by-step overview on how to get this working.

Steps

This article describes the following steps in detail:

  • Create an Account and Project on Infura.io
  • Create an Account with Address using MetaMask
  • Define a Smart Contract
  • Deploy this Smart Contract to the Ropsten test network using Remix
  • Create a Logic App in the Azure Portal
  • Add the “Query SmartContract Function (preview)”
  • Add the “Execute SmartContract Function(preview)”
  • Test the Logic App
  • Alternative: create and deploy your own Azure Function to interact with the Ethereum BlockChain

Create an Account and Project on Infura.io

With Infura.io, it’s very easy to interact (as a DApp) with the Ethereum BlockChain network.

First step is to create an account and then create a project.

One you have created the project, make sure to switch to the Ropsten endpoint and remember the complete URL, this will be used later.

Infura.io : Project

Create an Account with Address using MetaMask

Download and install the MetaMask as a Chrome extension.

Create an account on the Ropsten Test Network using this guide. Once the account is correctly created, you can view it:

MetaMask : Account

Make sure to view the details and export the private key, you need this later:

MetaMask: Export Private Key

Note that initially, the balance will be 0 ETH. To get ETH to test SmartContracts, go to https://faucet.ropsten.be/ and request some test ETH:

Faucet : Ropsten ETH

Go to Etherscan.io to view details on your Account Address:

Etherscan.io : Overview

Define a Smart Contract

I’m using a very simple Solidity Smart Contract for this article.

SimpleStorageContract.sol

Deploy this Smart Contract to the Ropsten test network using Remix

Go to http://remix.ethereum.org.

The first time you connect, MetaMask is detected and asks for permission to connect to Remix.

Copy the SmartContract to a new file:

Remix: Add Contract

And deploy the Smart Contract.

Note that it shows information about the contract deployment via the Metamask plugin)

Remix : deploy

See also this link https://medium.com/swlh/deploy-smart-contracts-on-ropsten-testnet-through-ethereum-remix-233cd1494b4b

Once it’s deployed, you can see the status in MetaMask:

MetaMask: Contract Deployment Overview

Make sure to copy the ABI (Application Binary Interface) from the SmartContract, you will need this later.

Remix: Copy ABI to clipboard

Also remember the Contract Address, you will also need this later:

Remix: Copy Address to clipboard

Create a Logic App in the Azure Portal

Now it’s time to go to the Azure Portal and create a new Logic App in the designer which includes the following steps:

  • When a HTTP request is received : This is the start point
  • Initialize variable steps: To define the ABI and the Address
  • Query smart contract: To call a function from the Smart Contract
  • Execute smart contract: To execute a function from the Smart Contract
  • Return response: return (raw) response
Azure Portal : Logic App — Design

Add “Query SmartContract Function (preview)” step

When adding this step, you first need to create a connection:

Logic App Ethereum Blockchain step : Create Connection

The private key is the key you copied from MetaMask.

Once the connection is correctly defined, you can fill in the details for the Query Smart Contract Function.

Logic App Ethereum Blockchain step : Query SmartContract Function ”getString”(request)

In the above example, the ABI and the Smart Contract Address are variables which are defined the the variables step. But it’s also possible to copy-paste the data directly for these field. The function which is called is named getString (without any arguments).

The response is:

Logic App Ethereum Blockchain step : Query SmartContract Function ”getString” (response)

You can also call a function with multiple parameters, see example below.

Logic App Ethereum Blockchain step : Query SmartContract Function ”addNumbers” (request)

The response is:

Logic App Ethereum Blockchain step : Query SmartContract Function ”addNumbers” (response)

Add the “Execute SmartContract Function(preview)”

Add this step and fill in the details for the Execute Smart Contract Function

Logic App Ethereum Blockchain step : Execute SmartContract Function ”setString” (request)

Test the Logic App

If all is setup correctly, you should be able to run the Logic App in Azure Portal.

Azure Portal : Logic App — Run

Create and deploy your own Azure Function to interact with the Ethereum Blockchain

Instead of using the Query and Execute SmartContract Connectors, it’s also possible to write your own Azure Function. This will be described in a new story.

References

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

CHOICE COIN SO FAR

Blockchain Applications (I): A Primer

Introducing MetaTransact

TMRW/CONF Belgrade 2022

SoterOne — The Rise of the Polkadot Ecological Leading Project

Instructions on Radiant Glory’s Strategic Adjustment

OneRare to use Propel DaaS

The Interesting Use Cases of JPM Coin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stef Heyenrath

Stef Heyenrath

More from Medium

MetaMask — RPC Error: Expected 0x-prefixed

What Are Smart Contracts?

Solana Automation CLI is here

How to build a Voting Decentralized Application

Voting Application Example