In this blog “Publish Logic Apps data to SQL Database in Azure Blockchain Service” you will learn how to use Ethereum Blockchain connector with Azure Logic Apps to perform smart contract actions and respond to smart contract events and store data into sql database, you will create HelloBlockchain smart contract and deploy on Azure Blockchain as Service.
Step-1 -Create Azure Blockchain as Service
Step-2 Fill details of node and consortium name ,Password .For development you may choose basic plan with 1 validator and 1 transaction node. Data is managed through transaction node which can be added later.
Step-3 After filling all details ,Click on review+create button then create. Now go resource group and click on created group you will be able to see consortium member.
Step-4 When you click on member name below details will be shown . Member account name will be helpful while integrating Logic app (Member account and node password which we entered will be use) .
Step-5 Click on transaction node and click on member name . Choose connection string Access Key1 and Access Key 2 is ethereum blockhain end point . We need to enter RPC end point when we are connecting logic app to ethereum blockchain connection.
Step-6 Let’s start installing extension for smart contract development and connectivity with Azure Blockchain Service to deploy.
Step-7 – After installing all prerequisite and Azure Blockchain Development Kit for Ethereum Extension . Let’s create HelloBlockchain smart contract.
Step-8 – After creating HelloBlockchain sample project ,structure will look like below.
Step-9 Let’s connect to Azure Blockchain as Service by choosing Azure Sign in from command palette or below project structure Azure Blockchain connector option.
Step-10 -Use the Build Contracts command to compile all the smart contracts in your project.
Azure Blockchain Development Kit uses Truffle to compile the smart contracts.After building smart contract build folder will be created you can see HelloBlockchain.json file (contract ABI) . It contains all information related to contract.
Azure Blockchain Development Kit uses Truffle to execute the migration script to deploy the contracts to the blockchain. After deploying contract on blockchain you will get contract address and account name which we deployed contract as given below.
Step-12 – In next step we will generate logic app workflows by choosing Generate Data Publishing workflows for smart contract .
Step-13 – It will generate Logic App folder in project .
Step-14 – Let’s create Blank Logic app from Azure portal.
Step-15 Fill all details ,Make sure resource group region is same as Azure Blockchain Service resource group region.
Step-16– After creating logic app go to resource and choose code view.
Go to VS Code generatedLogicApp folder and copy code from function.SendRequest.logicapp.json and paste into code view of logic app portal and save . Then move to logic app designer .
Step- 17 Now we need to update Connection string to make logic app connection with ethereum blockchain.
Step-18 – After click on connection , It will give two option existing connection or new connection . Existing connection will show as below.
If you don’t have any connection choose Add New option and create new connection. In step- 4 see account address and step -5 check RPC end point and copy below.
Private Key or Account address,Password you need enter only one .
To generate private key follow below step
Private key will be copied on clipboard ,now copy into Private key column in connection . Make sure if you are copying private key then no need for account address and password.
Step- 19 – Now we are ready to perform smart contract actions and respond to smart contract events. Download postman to test . Open logic app designer view and copy HTTP POST URL.
Step-20 First we will trigger sendrequest logic app by passing request string to execute contract and in return it will return block hash address as response. That hash address response we will insert into database.
Note to make sure response data is inserting into database , we need enable interaction from database firewall settings otherwise it will not be allowed.
Step-21 Now we will trigger sendrequest function logic app , It will return state generated by sendrequest function by executing smart contract and return response.That response message we will insert into database.
Refer source code on github .
In this blog Publish Logic Apps data to SQL Database in Azure Blockchain Service you have learnt how to use Ethereum Blockchain connector with Azure Logic Apps to perform smart contract actions and respond to smart contract events and store data into sql databaseIn, If you have any question related to Azure Blockchain service feel free to contact us