Blockchain – First Level Implementation Guide for System Architects


Do you know why you are here? Yes! I shared this link to you and you opened it! If you are interested in designing or constructing Blockchain Network, this page may be your alphabet of your idea or innovation. Here you can also learn and understand how Blockchain can be designed for your Business Requirements.

I hope that you are already familiar with Ledger, Distributed Database, Cryptography, Hashes and Decentralization from my last article. If you don't have any idea, No Problem! I will try to explain my design by providing simple algorithms to implement Blockchain Network for adding Transactions, Blocks, Mining and Chaining.

I want to start this article with a fundamental which may answer why Blockchain will be inevitable. I start with few basic questions.
  • Why are you using Coins and Currencies rather they are just metals and papers? And why are they over-valued?
  • Why are you depositing your Money into Banks? Are they your relatives or friends?
Reason is that You Trust Them.
  • You trust your Government
  • You trust your Financial Regulatory Authority
  • You trust your Bankers
Commonly you trust a system or organization. What will happen if all your trusts are replaced with technology? It happened before and it is called Evolution. Blockchain is the trust which protects data from third-party and increases the efficiency of transaction without any Government, Regulations and Bankers involvement.

This is the article for System Architects to design Blockchain Network so I want to move to the topic directly. I have already explained the core concepts in my previous articles with Cryptocurrency and please refer if you would like to.

Before Getting Started

We need to define our goal and strategy for our further sections. This step will narrow down to design and learn Blockchain Server and Client implementations. 

Usecase: 
  • Creating a new transaction with Sender and Receiver details
  • Adding them into Blockchain Network by verifying the transactions
  • Data should be updated in all Blockchain Hosts
Technology Requirements:
  • Blockchain Server: Python 3.7
  • HTTP Client: Postman
  • IDE: PyScripter
Technical Implementation:
  • Blockchain Server Class Building with Creating Block, Adding Transactions and Mining methods
  • Developing HTTP requests to communicate with Blockchain functions from Python Flask
  • Blockchain API Integration and Data Decentralization

Blockchain Implementation

Blockchain Server Design

Can we directly start with code? Ok,

This is the main class of our Blockchain which takes charge on maintaining entire Blockchain Network. We will see the definition and need of all core methods and helper methods.

New Block

Block consists of Index which helps to manage or assign unique ID to each Block. Timestamp helps to get current date and time of Block Creation. Block is attached with Hash and it also has information about previous Hash. Rather very first block in the network does not have any previous Hash References.

New Transactions

Transaction is the data part which consists of encoded details of the transactions. In our usecase, each transaction must have Sender, Receiver and Amount details which should be added into New Block.

Proof of Work for Mining

Miners Proof is the core concept of Blockchain which creates artificial complexity to identify the key to verify transactions by Minors. Until identifying valid proof, miner's also continuously running their proof of work algorithm. For making this step easier, I made it to four zeros.

Blockchain API Interaction from HTTP Client

There is a framework in Python called Flask which provides facility to access Python functions from HTTP Requests. For accessing our BlockchainCore Class, I am going to create three methods or links which are for Creating New Transaction to a Block, Mining New Block and Adding New Block into Core Blockchain.

Adding New Transaction


In new transaction link, details of Sender, Receiver and Amount will be sent from HTTP Client in POST Method. As a client, we submit the required details to BlockchainCore API.

Data Mining Method

This is our PoW implementation and miners will run the script for finding Hash. Once Hash is identified, New Block is forged with transaction details and Hash details. For ensuring the chain, few basic validation has been done from Server side like Previous Hash / Last Proof.

Maintaining Chain

Chain link is requested to add the newly identified Block with Transaction into existing chain. Once New Block is created with transaction successfully then it should be added and maintained in core Blockchain network. Chain method is called to perform this task.

Running Blockchain Network


1. Run BlockchainCore.py in 172.10.20.5:9000
2. Initiate HTTP Client from Postman http://localhost:9000/transaction/new (Adding New Transaction)
3. Initiate HTTP Client from Postman http://localhost:9000/mine (Data Mining Method)
4. Initiate HTTP Client from Postman http://localhost:9000/chain (Maintaining Chain)

Result View
 "chain": [
    {
      "index": 1,
      "previous_hash": 1,
      "miners_proof": 100,
      "timestamp": ,
      "transactions": []
    },
    {
      "index": 2,
      "previous_hash": ,
      "miners_proof": ,
      "timestamp": ,
      "transactions": [
        {
          "amount": 1,
          "recipient": ,
          "sender": ,
        }
      ]
    } ]

Conclusion

I don't still talk about decentralization in this article because I just wanted my code to be worked with sample PoC transactions. Probably I will talk about Cryptocurrency implementation in my BlockchainCore class with multiple Host Systems. In the mean time, please comment your suggestions and queries for improving my base class or methods. Thanks for your time. Good Day!

Share:

Digital Currency - Beginners Guide for Bitcoin Investors and Traders


Good Day Readers! Here I would like to share an overview of Cryptocurrency concepts which are inevitable definitions for having discussion about Bitcoin, Blockchain and Digital Asset Trading/Investing. Before reading about Trading or Investing Strategy, every Investor must understand the nature of Cryptocurrency and what are the functions available in your Exchange.

Beginners (Investor or Trader)

Cryptocurrency is a digital asset or virtual currency that uses cryptography algorithms for enabling security and artificially complicated to make difficult to counterfeit. Cryptocurrency is waving in decentralized systems based on Blockchain Technology, a distributed ledger enforced by a disparate network of computers. It does not have either any central authority to issue or regulatory authority to control.

If you would like to invest or trade in Cryptocurrency, you must know the followings to start with.

  • You must have a wallet
  • You should be registered and subscribed in Cryptocurrency Exchange


Cryptocurrency wallet is a digital space where your coins are stored with encrypted passwords. It is similar to your Bank Account where you safely have your Money with digital security enabled. A Cryptocurrency Exchange is a Digital Market Place where Buy/Sell happens on Cryptocurrency like Bitcoin where Cryptocurrency Trade happens for other Cryptocurrency or Fiat Currency. Coinbase Pro and Binance are couple of top service providers of Cryptocurrency Trading. You can gain knowledge on Cryptocurrency Trading by reading their Product Description and Service Details.

What A  beginner should know before starting the trades in Cryptocurrency? Because of your curiosity, you will start loosing your money in Cryptocurrency Trading of its high volatility in nature. You must start with an exchange and wallet provider with good reputation. Coinbase looks decent and it allows to trade or invest most of the popular digital coins like Bitcoin (BTC) and Ethereum (ETH). It is also not advised in margin trading until realizing the risk associated with it. I will come to Margin Trade later.

Understanding Wallet


Generally Wallets are Web based or Mobile based application which allows clients to invest in Cryptocurrency and Digital Assets. Wallets must have the following properties to provide better service.

User Experience: Clients can view their Cryptocurrency Investments, Performance Reports, Buy/Sell Suggestions, Risk Managements and Watch List.

Secured Wallets: The coins can be stored in secured e-wallets that are built on the blockchain to enable safe and secure storage of Cryptocurrency.

Multi-signature Wallets: Multi-signature wallet addresses require another user or users sign a transaction from the wallet which enables additional security.

Two Factor Authentication: 2FA is a method of confirming a user's identity by utilizing two different factors, Private Keys and QR Scanner.

Cryptocurrency Exchange Features

Binance or Coinbase Cryptocurrency Exchange has the following features which are considered as minimum vital features to serve Cryptocurrency Investors.


  • Leverage Trading
  • Margin Trading
  • Order Sharing
  • Matching Engine
  • Multi-currency Wallet
  • Payment Gateway Integration
  • API Integration
  • Admin Backend Panel



Also clients are allowed to trade by placing Buy/Sell Orders in the following Order Types.

Market Order: A Market Order will allow the user to trade Coins at the current price. The user can set a market buy or market sell in order to protect themselves from slippage in a volatile market.

Limit Order: A Limit Order will allow users to trade Coins by placing an order on the hopes that it will be fulfilled by someone else’s market order. The orders are not limited to slippage due to volatility in the market. The user can set a Limit Buy or Limit Sell.

Stop Order: Stop Order is a conditional market order where the user sells the order after reaching a specified price. A user can set a Stop Buy or Stop Sell/Loss thereby taking precautionary actions.

Copy Order: Copy Order is an order where a user receives updates on the top crypto-traders and copy their trades. This will help beginners to the crypto-trading. The top order would receive a commission based on the earnings of the copy trader.

P2P Trading: Peer to Peer Trading is unique and allows buyers and sellers to negotiate a price before a coin is transferred. The Cryptocurrency is stored on escrow, thereby ensuring safety of the coin. Only when the buyer and seller agree is when the transaction is completed.

We should also know about what are security features are available in Cryptocurrency Exchanges. The list is below


  • HTTP Authentication
  • Jail Login
  • Encrypted Data
  • Cross-Site Request Forgery(CSRF) Protection
  • Escrow System

Conclusion

Intention of this article is to provide an overview of fundamentals for Trading and Investing in Cryptocurrency Beginners. You must also read and understand various technical and fundamental analysis techniques before putting your money into your Wallet. I plan to provide few successful trading and investment strategies for Cryptocurrency in my next article. In between, if you are curious on trading Cryptocurrency, please refer some successful technical and fundamental analysis techniques of Equity Trading. It will help you to understand my next article better. Now I would like to end this article and special thanks to you for reading and following.

Share:

Digital Currency - Understanding Blockchain Network and Mining Process



Good Day! Hope you had a good reading on my previous article about Basics of Digital Currency. Now I would like to try to demystify Blockchain Networking and Mining Process which is apparently mandatory for understanding Cryptocurrency from Engineering & System Architecture perspective. This article deals with Blockchain Definitions, Digital Ledger and Mining Process.

Blockchain - Definition of Definition

Definition of Blockchain says that it is a distributed database that maintains a continuously growing list of ordered records called Blocks. Blockchain is also referred as a digital ledger in which transactions are recorded chronologically and publicly.

In general, we can store any transactions in Distributed Database if it is really necessary. What is transaction and why it is needed? The following are some examples of transactions.
  • Withdrawing money from ATM
  • Swiping your credit card in KFC
  • Purchasing medicines in Apollo Pharmacy
  • Claiming insurance for repairing your car
  • Buying 500 AAPL stocks in your account
Do you understand why these transactions are stored or needed? Yes, it is essentially required for verification, validation and reconciliation.


Now we can move into understanding “Digital Ledger” concept. Archetypal meaning of Ledger is “A Place to Keep Something”. And, definition of ledger is an account to record, categorize and sort transactions, for maintaining the balance such as Asset, Liabilities, Revenue and Expenses to prepare Balance Sheet and Income Sheet. Digital Ledger is a database or electronic storage area where all records or transactions are stored in chronological order.

For reiterating the definition of Blockchain, it is a Digital Ledger where all transactions are electronically stored in chronological order; distributed in different locations with same transaction details called Blocks; continuously adding new transactions and available to public for processing transactions.

I hope that you have more idea on how Blockchain is organized. No?? Not Yet?? It’s Okay. I have given some usecases of Blockchain for various industries and it will help you to think through it.

Area
Usecase
Banking
Managing transactions and avoid data tampering from third-party requires advanced Business and Process solutions which can be easily solved by implementing Blockchain Network.
Trading
Distributed Ledger provides Investment Management, Order Execution Management and Clearing & Settlement Platforms to perform their Affirmation and Confirmation activities by using decentralized database to settle transactions safer.
Healthcare
Securely storing Medical Details and maintaining single version of Patient & Insurance Modules to avoid information conflicts.
Insurance
Fully automated and decentralized platforms allowing to invest in insurance and claim profits from insurance premiums as well as get insured.
Social Media
Sharing or broadcasting News or Blog and Running Reward Programs will require a decentralized ledger to manage the operations and services.

Miners - Digital Currency Engine

Now we jump into next tricky concept called “Mining” and players who are participating in mining activity called “Miners”. All Cryptocurrency transactions are intimated to all Blockchain Hosts (Also known as Miners) to validate and add the particular transaction in Digital Public Ledger (Blockchain Database) as a New Block (Transaction). One of the miners will process the transaction and update into Blockchain Network then broadcast the details to other Hosts for synchronizing transaction details. For this service, miners are rewarded with Cryptocurrency or some units of Cryptocurrency.

“Miners have a job and they are paid for that” Now you got this statement! Couple of questions must come to your mind and they can be one of the followings.
  • Can anyone have the infrastructure of Blockchain Host?
  • Can anyone participate to add Block into Ledger and get paid?
  • If I have the complete access of Cryptocurrency transactions then I can hack the system. Can’t I?
  • What will happen if all miners update a specific transaction at the same time?
Yes, anyone can have infrastructure of Blockchain and participate in adding Blocks in the network and get paid for that. There are some advanced algorithms and consensus mechanisms used in Blockchain Network to avoid concurrent update or duplicating Blocks. You can also tamper the data by hacking Blockchain Network but it is too costly.

How it is too costly because I already knew to verify the transaction as a Miner and it is very simple process.

Correct! You know how to validate transactions and add them into Blockchain Network so hacking must be simple. Yes, it is very simple but Not Easy! Have you heard about Hash? Yes, I mentioned in my last article that Hash is a type or method of Cryptography. All Cryptocurrency transactions are attached with Hashes which is known as Digital Fingerprint and then Miners have to decode or find the Target Hash (Matching Key) for validating and processing transactions.
Hashes! Does it really complicate? Yes, it is artificially complicated.

Target Hash for Digital Fingerprint (Hash) which is associated with the Cryptocurrency transaction should be identified by Miners. Target Hash is just like a random number (Nonce) by which Miners can process the transaction and add new Block.

How do Miners find the Target Hashes? As a miner, you have to either solve a Puzzle or win in a Lottery System to identify the Target Hash. Is it a difficult work? Yes, I told you already that it is artificially complicated in which miners require more effort and energy to find Target Hash.



Miners are rewarded with some units of Cryptocurrency for the time, effort and energy spent for Lottery System or Puzzle solving process for adding new Block. Miners can also make considerable amount of profit from the reward. If a miner wants to hack the system and tamper the previous transactions then miner has to put huge effort to find all Target Hashes in the ledger until the desired Block or Transaction comes. Do you know why? because all blocks are logically linked in Blockchain Network. Moreover tampered information cannot be updated to all other distributed databases without other Blockchain Host’s knowledge. This artificial complexity is considered as a main advantage of Blockchain which is the combination of Digital Ledger, Digital Fingerprint and Distributed Database. 


Blockchain Networking


There are 6 Blockchain Hosts are available in different regions and they are working for same Cryptocurrency. Gopal in USA, has advanced and high processing Blockchain Host infrastructure and he is also known as the most rewarded Miner. The rest of the Miners have medium infrastructure for Blockchain Network. Why I am talking about Blockchain Infrastructure now! Coming to the point!

Gopal’s hash-rate is high. Wait! What is Hash-Rate? Gopal can process more Hashes compare to other Miners because of having advanced Blockchain Infrastructure. Hash-Rate is the computing power of Processing Number of Hashes per Second. Now you got why Gopal is the most rewarded miner. Yes, he processed more hashes which made him to add more Blocks in Network and get more rewards as Digital Currency. Other miners have decent hash-rate and get paid for their transactions processing over the Blockchain Network.

Yuvaraj is one of the skilled Miners and he would like to hack the Blockchain Network. Reason is to modify the Blocks and Transactions in the network and add more Digital Currency into his personal or favorite Wallet. For achieving his goal, Yuvaraj has to find all Target Hashes for each Block in the Digital Ledger and update all Blockchain Hosts with new Blocks. Technically it is possible but effort is very high. This effort is as high as upgrading Blockchain Host Infrastructure and process more transactions. There are many chances to lose his infrastructure effort and energy without getting paid.

From these two cases, you can get an idea that success rate of Miners is far better than Hackers in Blockchain Network due to artificially complicated process.

Conclusion

Blockchain is the decentralized database network which helps to maintain transactions safely and securely. Cryptography and Digital Ledger idea provide more security to the transactions which is almost impossible to modify or tamper. Lottery and Puzzle Solving mechanisms are designed to consume more energy from the miners to validate and process a Block. At last, combination of above creates a solid decentralized database for maintaining transactions for Cryptocurrency.

Thanks for reading my article. Your patience & time are much appreciated. Please shoot your queries and I will try to answer as soon as possible. Have a nice day!


Share:

Categories

Follow Me