Page 40 - MSDN Magazine, July 2018
P. 40

Figure 4 Resource Template File for Ethereum Consortium Multi-Node Ledger
either automatically by the platform or manually by providing my own JSON file.
Step 4: Before I deploy the resources in the Ethereum Consor- tium ledger, I’m presented with a summary of the configuration settings I entered. From here, I can download a JSON template file to automate deployment of a similar resource set with Azure Resource Manager. Figure 4 anticipates the Azure resources to be deployed in the provisioning of the Ethereum ledger, along with a snippet of the template file.
This template file can be used to automate deployment of similar resources in the future, using a combination of .NET or PowerShell scripts.
Figure 5 The DeploymentHelper Class
The C# code in Figure 5 describes the DeploymentHelper class generated by the template for automating the deployment of the identified Azure resources. You need to reference the following packages to run the code:
• Microsoft.Azure.Management.Authorization
• Microsoft.Azure.Management.ResourceManager
• Microsoft.Rest.ClientRuntime.Azure.Authentication
Similarly, the PowerShell script signs into an Azure subscrip- tion, registers the necessary resource providers and then starts the deployment of the resources identified in the template file, as shown in Figure 6.
The entire solution, consisting of template and script files, is available for download from my GitHub repository at bit.ly/2INgNEP. Once that’s done, review the terms of use and licensing con- ditions, and click Create to deploy the resources. In less than 20 minutes, you have a fully functional blockchain ledger up and running. Just don’t forget to save important information needed
for developing dApps, including:
• RPC-Endpoint: You need this address to establish com-
munication between a dApp development environment,
such as Ethereum Remix and the consortium blockchain. • SSH Info: You need credentials to sign into the blockchain environments and configure parameters, like most typically for unlocking the Coinbase account and start mining new blocks. Coinbase is my digital wallet, which contains my signature keys used to hash a block, and my Ether, the cryptocurrency of Ethereum, earned as part of the mining process. When deploying a new Ethe- reum Consortium ledger in Azure, this account is initially locked, so I need to unlock it before I can publish smart contracts. With the help of SSH, I connect to a transaction node of the Ethereum
Consortium network and unlock the Coinbase account, like so:
geth attach -- opens the Geth console personal.unlockAccount(eth.coinbase)
When prompted for a passphrase, I enter the gethadmin pass- word that I specified in Step 1 of the configuration wizard (not the Ethereum private key passphrase). By default, this action unlocks the Coinbase account for 5 minutes. You can change the dura- tion using a different signature of the unlockAccount method, as shown here:
class DeploymentHelper {
string subscriptionId = "your-subscription-id";
string clientId = "your-service-principal-clientId";
string clientSecret = "your-service-principal-client-secret"; string resourceGroupName = "resource-group-name";
string deploymentName = "deployment-name";
string resourceGroupLocation = "resource-group-location";
// Must be specified for creating a new resource group
string pathToTemplateFile = "path-to-template.json-on-disk"; string pathToParameterFile = "path-to-parameters.json-on-disk"; string tenantId = "tenant-id";
public async void Run() {
// Try to obtain the service credentials
var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(
tenantId, clientId, clientSecret);
// Read the template and parameter file contents JObject templateFileContents =
GetJsonFileContents(pathToTemplateFile); JObject parameterFileContents =
GetJsonFileContents(pathToParameterFile);
// Create the resource manager client var resourceManagementClient =
new ResourceManagementClient(serviceCreds); resourceManagementClient.SubscriptionId = subscriptionId;
// Create or check that resource group exists EnsureResourceGroupExists(resourceManagementClient, resourceGroupName,
resourceGroupLocation);
// Start a deployment
DeployTemplate(resourceManagementClient, resourceGroupName, deploymentName,
templateFileContents, parameterFileContents); }
34 msdn magazine
Microsoft Azure


































































































   38   39   40   41   42