How to implement Blockchain using IBM Services
By: Kiran Patil
Tags: Backend, Bitcoin, Google App Engine, IBM, Blockchain

In this post, I will walk you through the implementations of simple amount transfer between users on Blockchain Network using IBM’s Blockchain service. If you had gone through my previous post you would now be knowing basic things about Blockchain. After going through this post which is kind of tutorial, you will be knowing how to set up your own Blockchain network, and build up decentralized applications like bitcoin etc. Before building up the applications let us understand IBM’s Blockchain key concepts and important terms.

Important concepts of Blockchain

Blockchain is a business network consisting of nodes (“members”) who exchange the items of value through a shared ledger and posses content which are always sync with others.

A business network

Blockchain network consist of decentralised nodes (market participants) connected peer-to-peer. Each node follows the protocol to validate and commit transaction in order to reach a common agreement.

Shared Ledger

It acts a source of truth for business applications which stores transaction on blockchain. It records all the transactions and it can be accessed by all the nodes. It is replicated so each participant has their own copy.

Consensus

Data in the ledger are synchronized between all the ledgers in the network. Consensus ensures that these shared ledgers are exact copies, and lowers the risk of fraudulent transactions since tampering would have to occur across many places at the exact same time.

Smart Contracts

Apart from just token system, some business application needs to perform some operations (execution of code related to some functionality). Smart Contracts are verified,signed and encoded in programming language. For example, Ethereum is an open source blockchain project built to realize the possibility of implementing a turing-complete programming language capability to implement the smart contracts.

Key terms involved in IBM’s BlockChain

The following terms are instrumental in gaining a holistic understanding of blockchain concept :

Transactor : It’s a network candidate connected to the blockchain network through a node, who is responsible for submitting the transactions from a client using API or SDK.

Transaction : Transactor makes a request to execute some function on the blockchain network. Different type of transaction are deploy, invoke, and query, which are implemented through the chaincode functions set forth in the fabric’s (explained later) API contract.

Chaincode : Embedded logic that encodes the rules for specific types of network transactions. Developers write chaincode applications and deploy them to the network. End users then invoke chaincode through a client-side application that interfaces with a network peer, or node. Chaincode runs network transactions, which if validated, are appended to the shared ledger and modify world state.

Ledger : It can be said as a system of cryptographically-linked blocks, containing transactions and the current world state. In contains data related to every transaction along with data for currently-running chaincode applications.

World state : Key-value database used by chaincodes to store their state when executed by a transaction.

Validating peer : A network node that runs the consensus protocol for the network to validate transactions and maintain the ledger. Validated transactions are appended to the ledger, in blocks. If a transaction fails consensus, it is purged from the block and therefore, not written to the ledger. A validating peer (VP) has authority to deploy, invoke and query chaincode.

Non-validating peer : A network node that functions as a proxy, connecting transactors to validating peers. A non-validating peer (NVP) forwards invocation requests to its connected validating peer (VP). It also hosts the event stream server and the REST service.

Permissioned network : A blockchain network where each node is required to maintain a member identity on the network, and each node has access to only the transactions that its permissions allow.

Fabric : The Hyperledger Fabric is an implementation of blockchain technology, leveraging familiar and proven technologies. It is a modular architecture allowing pluggable implementations of various function.

IBM’s Blockchain Service

For Blockchain developers IBM provides service on Bluemix with a choice between two four-node development and test blockchain networks, at the click of a button. Developers don’t need to start from scratch. They can directly start writing applications and deploying chaincode. IBM provides a peer-to-peer permissioned blockchain network, built on top of Hyperledger Fabric v0.6.1 code from the Linux Foundation’s Hyperledger Project. Blockchain networks are used to securely and efficiently exchange and track digital assets, and to permanently record all transactions on the shared ledger. You can go through the IBM’s Network and Application architecture to understand the IBM’s blockchain network and basic data flow of the blockchain apps.

You can go through chaincode tutorial to learn and build up chaincode which will be deployed on the network peer. After successfully deploying the chaincode, Client App/User with the help of SDK/API Interaction can make read/write calls to the chaincode shared ledger. IBM supports golang to write chaincode.

If you followed the chaincode tutorial you might be now knowing the following things :

What is chaincode? How do I implement chaincode? What dependencies exist? What are the major functions? How do I pass different values to my arguments? How do I securely enroll a user on my network? How do I compile my chaincode? How do I interact with my chaincode through the REST API?

Amount Transfer Demo

Now Let’s understand how we explored the IBM’s blockchain service to build up a wallet system and allow users to send money. Since we can interact to any of the network nodes on the blockchain network through REST API , we can build up our own server in any languages which supports REST services. We used Google app engine to have server locally which can be written in golang. From our local server we make REST calls to chaincode.

Application Communication Flow