What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.

How To Develop Blockchain ‘Dapps’ with Blockhead

The following is part of a series of posts from The Cloud Foundry Foundation on digital transformation, in preparation for the upcoming Cloud Foundry Summit in Basel, Switzerland.
Oct 2nd, 2018 9:30am by
Featued image for: How To Develop Blockchain ‘Dapps’ with Blockhead
Feature image via Pixabay.

The following is part of a series of posts from The Cloud Foundry Foundation on digital transformation, in preparation for the upcoming Cloud Foundry Summit in Basel, Switzerland.

During the past few years, the emergence of new Blockchain technologies has prompted a rush by app makers — known as decentralized application (dapp) developers — to offer new ways for users take advantage of the much-hyped distributed ledger.

However, dapp development requires in-depth knowledge about smart contracts and blockchain networks. Dapps are decentralized in nature, as each instance of the application can communicate with a different node of the network. Consequently, dapp developers must have a solid grounding in a number of technologies. They must be able to:

  1. Choose a network
  2. Create a node and connect it to the network
  3. Create a smart contract
  4. Deploy the smart contract
  5. Develop a dapp to interact with the smart contract.

But what if we could reduce the difficulty and allow regular developers to create dapps? Here is where Project Blockhead comes in, which offers help for developers to simplify the first four steps of the above and to allow them to focus on their dapp.

So what is Blockhead? It is an implementation of the Open Service Broker API (OSB API) that offers on-demand provisioning of nodes as well as the deployment of smart contracts. The idea is that dapp developers should focus on building their application and let the Blockhead broker worry about node and smart contract management.

This project grew out of a hackathon I participated in at Cloud Foundry Summit North America in 2018 and has since been accepted as a CF-Extension project. Team Blockhead consisted of Nima Kaviani (Senior Cloud Engineer, IBM), Jonathan Berkhahn (Open Source Contributor, IBM), Morgan Bauer (Open Source Contributor, IBM) and me. Since the hackathon, the team has been rewriting the broker in Golang and we are excited to present it at the upcoming Cloud Foundry Summit.

Blockhead and Open Service Broker API

Swetha Repakula
Swetha is a software engineer working in IBM’s Open Technologies division. Since late 2017, she has been working on Hyperledger Fabric, an open source blockchain platform on its EVM integration. Previously she was a full-time open source contributor for Cloud Foundry. Swetha holds a BS in electrical engineering and computer science from UC Berkeley.

The OSB API, originally from Cloud Foundry, defines a common set of APIs for applications to easily create and connect with cloud services such as relational databases. The spec helps decouple applications from the services they depend on, allowing the management of both to be separated. Blockhead implements the five endpoints that application developers can expect when working with an OSB API broker through which it manages the lifecycle of blockchain nodes deployed to a Platform as a Service (PaaS) platform.

This is how standard OSB API endpoints translate into managing a blockchain node:

  1. Catalog: GET /v2/catalog
    The blockhead broker returns information about the available services. Currently, it only supports one service, an ethereum node that has been started in development mode.
  2. Provision: PUT /v2/service_instances/:instance_id
    At this stage, the broker starts a Docker container, which has the ethereum node built into it. Through creation of the docker container, the blockchain node is started and a new blockchain user account is created for it.
  3. Binding: PUT /v2/service_instances/:instance_id/service_bindings/:binding_id
    When binding, users must provide the solidity smart contract they would like deployed. The broker, in turn, will download the contract, compile it and deploy it to the blockchain, through the node. After the smart contract is deployed, the broker returns the user account address that had been created, the contract address, as well as the IP address and port of the blockchain node so applications can connect to it. At this stage, applications that use libraries such as web3.js can easily communicate with the development ethereum network that has been created. Depending on the PaaS being used to host the dapp, this information is available as environment variables.
  4. Unbind: DELETE /v2/service_instances/:instance_id/service_bindings/:binding_id
    Currently, the blockhead broker does not do anything with the ethereum node. However most PaaS will remove the connection information from the application’s environment.
  5. Deprovision: DELETE /v2/service_instances/:instance_id
    The broker will stop and remove the docker container that has been running the ethereum node.

Deploying and Registering the Broker

The recommended method to deploy the Blockhead broker is through Bosh or building the Dockerfile.

The following tutorial is for the Bosh broker (instruction on how to deploy the broker without Bosh can be found here: Readme):

  1. Create a manifest. Included in the release is a manifest that works with a bosh-lite and with the “cf-deployment” bosh-lite cloud config.
  2. Deploy the broker. In the root of the repository run the following. The Bosh cli should already be targeting the right BOSH director: bosh -d blockhead deploy blockhead.yml –vars-store creds.yml
    The “creds.yml” will be created and will have the password necessary for authentication.
  3. Register the broker with a PaaS. (This tutorial is for the Cloud Foundry’s PaaS.) After logging in as an admin user, run the following. You will need the password that can be found in the “creds.yml” file, which was created in the previous step:
    cf register-broker blockhead admin <password>
  4. Enable service access to the desired plans. Currently, the broker only supports “geth” in dev mode:
    cf enable-service eth dev
  5. Verify the plans are available in the marketplace: cf marketplace. You should see the “eth” service available.

Using the Blockhead Service

Dapp developers, using a PaaS that has the Blockhead broker registered, can use the service to simplify their development process. The following tutorial is aimed for Cloud Foundry users, but the parallel steps can be done using other PaaS such as Kubernetes that have adopted  OSBAPI. Before running through these steps make sure you are logged into the platform using the “cf” cli.

  1. Download the demo application: git clone 
  2. cd blockhead-broker-demo
  3. Push up your dapp, without starting so you can connect your service: cf push myApp –no-start
  4. Create the service:
    cf create-service eth dev myEth
  5. Bind the application:
    cf bind-service myApp myEth -c ‘{“contract_url”: “”} 
  6. Your app’s environment should reveal all the information you need to connect it to the geth node: cf env myApp
  7. Start your app. Make sure that your application is designed so it reads from the environment variable: “VCAP_SERVICES”
    cf start myApp

Future Plans

We plan to focus on a range of things, from deployment methods to the services that are supported on the broker. One area of future development is to give operators the option to deploy the broker on top of Kubernetes. For developers, the team is looking into adding support for integration of Hyperledger Fabric with applications deployed onto supported PaaS platforms.

The team will present the new Go version of the Blockhead broker at the Cloud Foundry Summit EU in Basel, Switzerland. The tutorial above will be shown as a keynote demo by Nima and this writer followed by a deep dive into the broker in a breakout session run by Nima and Morgan.

Join us in Basel and learn more about the Blockhead broker!

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Enable, Pragma, Docker.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.