Yesterday I was reading about Blockchain, its architecture and other technical detail. I being from ABAP background thought of coding a basic blockchain in ABAP. Please note that intent here is to build a basic blockchain so that its understanding can be increased. Implementation of the blockchain may differ based on the requirements but basic concept remains the same.

The other features such as power of distributed data management and sync, validation of blocks etc. is out of scope of this blog.

Blockchain Basics

As the name suggests Blockchain is basically chain or collection of blocks. Typically a block comprises of a header which has different fields, a hash (cryptic value) of previous block and Transactions Data in hashed form (we will dig into this in our next blog). The first block in the blockchain is known as genesis block. N number of transactions together make a block. These all block are distributed over the network as local copy on each connected node.

Once the maximum number of transactions in a block is reached, the three parts of the block which are header, data(detail of transactions) & previous block hash are combined and hashed(encrypted ) with a key known as proof of work or nonce. The correct key or proof of work is determined based on the difficulty level. For example we say a generated hash is valid only and only if it contains 5 leading zero’s. So this leading 5 zero’s is known as the difficulty level.

The process of determining the right key consumes the major time and is known as mining. Depending on which currency it is, rewards are given accordingly to the one who finds a valid Proof of Work. The moment someone finds a valid proof of work all the connected nodes are informed and if 50% of the nodes agreed then this new hash is added as a new block to the chain.

What we are planning to build

A basic prototype of Blockchain, where a report will take input as difficulty level and number of blocks to be generated and then output will be hash and nonce for value for each hash. In the current blog our focus is to highlight how it works. In next blog we will focus on how the transactions are arranged in a block:)

ABAP Implementation of basic Blockchain

Created a basic report with below mentioned selection screen parameter

Thanks for this blog. It’s an interesting topic, I’m looking forward for the upcoming blogs.

BTW is it possible to add the source code as code and not as screenshot? It would be more readable. Example here: https://blogs.sap.com/2017/09/20/abap-news-for-release-7.52-virtual-sorting-of-internal-tables/

Nice blog, thanks for sharing! +1 from me on the suggestion to post the code as text (there is a code formatting option in the blog editor) instead of a screenshot. Screenshots are not searchable and it’s customary in ABAP tag to post the code so that it can be copy-pasted.

Blockchain explanations often explore Proof of Work, but PoW does not have to be part of blockchain. It is one of several validation/authorisation methods being explored; Proof of Stake, for example.

For private networks, where a public/democratic validation/authorisation process isn’t required, such as the Citizen Id as found in Canton Zug in Switzerland, Proof of Authority is used. Here, most users of the chain have read access. Only the government can authorise new blocks. Or, to put it into blockchain parlance, only the government can “mine”. There is no concept of rewards for mining with such a database.

Second, blockhain has more applications than just currency. Zug’s Citizen Id is one. Blockchain is an automatically audited distributed database, where if you can trust the block authorisation process, you can trust the contents of the blockchain.

Thanks Matthew Billingham for the awesome feedback. I agree we have N number of validation methods anyone can use anything. Yes the concepts of rewards and all those depends on what you want to achieve not only currency:)

I was reading other blogs people are doing crazy things with Blockchain. It is almost everywhere. Too many changes happening so too many things to learn, i feel the time ahead will be exciting:)