This post continues to explore Blockchain integration into Microsoft Dynamics 365 for Finance and Operations (AX). I’ve seen examples where developers did integration using the MetaMask Chrome extension, however I want something that looks and feels like pure AX.
For this post I will be using Xalentis Fusion which provides seamless Blockchain integration, whereby Blockchain I refer to Ethereum. I don’t see much use for Bitcoin, and apart from hundreds of other altcoins available, I see more enterprise-level movement towards Ethereum or its variants, including JP Morgans’ Quorum or Microsoft “Project Bletchley”.
Xalentis Fusion works by detecting new transactions in an Ethereum Blockchain and allows filtering to take place across those. Once a filter detects your specific requirements, it can fire off any number of associated rules, written in simple script. Fusion also includes a growing API allowing REST-based integration with the outside world, which is what we will be using.
Fusion provides a Transact API method allowing transactions to be made via a REST call. We can do this ourselves easily as well, but since we’ll be using Fusion for more than transacting (later on in this post) I figured I’ll just stick with it.
We’ll keep it very basic, and create a simple form accepting a number of parameters that we will use to perform a transaction. Our form design is shown below.
We’ve added fields for Node, Sender, Recipient, Sender’s account Password, and the amount of Wei to send. Depending on the Ethereum network you are connecting to, adjust the Node value accordingly, or simply hardcode it and remove the field. We are using the Fusion Test Net so that is shown. I’ve created two addresses in the Test Net, also shown in the form design, and loaded the first with some Ether. Perhaps customers want to trade in Dollars, so you can add code to convert Dollars entered into Wei or whatever token is in use. We’ll stick with Wei for now.
Let’s submit this transaction.
As you can see, the transaction has been submitted to the Blockchain and an Infolog displayed showing success. The X++ code is shown below, including the form class and a utility class that performs our REST calls to Fusion. I’ve added a TransactionRequest class as the POST action we are performing requires JSON being passed, and wrapped the class members with the DataContract attributes to enable easy serialization. This particular POST call accepts the full JSON as part of the POST URL, wrapped as Base64, and that is done in the utility class. The body is required, so we set the content-length to 0.
That works pretty well, but users don’t understand Blockchain addresses, and it would be painful to maintain that somewhere in notepad or Excel to copy and paste each time a transaction is made. Luckily Fusion provides an Account Mapping facility, which is a customer-specific key/value table mapping Blockchain addresses to friendly names, or account numbers the rest of us can readily understand.
So instead of entering address for Sender and Recipient, let’s modify our form as shown below. We can use drop-downs to pull up a list of known accounts, or use an API call to Fusion to return a full list of mapped accounts which we can then allow users to select. I’ll keep it simple with a text field. Here we’ve entered two known friendly account names we can read and verify. These could come from your chart of accounts as well, whatever works best in your scenario. As long as the display text maps to an address in Fusion, it can be resolved.
I’ve modified our form class and utility class to add two additional API calls to Fusion to resolve the friendly names to Ethereum addresses as shown in the code below. We simply make a GET call to Fusion passing across the friendly name, and Fusion will perform the lookup, returning the proper Ethereum address we need to use when performing the transaction. The updated code is shown below.
We’ll submit this transaction, and as shown we’ve got success.
I hope this was helpful. One final item to note is using Wei, which is a BigInteger. I’ve used strings to remove the need for dealing with BigInteger types in X++.