- November 30, 2018
- Posted by: fyber
- Category: Development
Advantage & Disadvantage | How To Apply | Code
You are searching, how to create your own Blockchain, it means you know about the blockchain but maybe some user don’t know about blockchain. Therefore, first of all, let’s some discuss Blockchain.
What is Blockchain?
The blockchain is a growing list of records that are called blocks and that blocks are linked using cryptography. Each & every block contains a cryptographic hash of the previous block, a timestamp, and transaction data.
In simple word, blockchain is an open, distributed ledger that can record transactions between two parties efficiently and in a verifiable and permanent way. Blockchain was invented in 2008 and by Satoshi Nakamoto to serve as the public transaction ledger of the cryptocurrency bitcoin.
Many people can write entries into a record of information with a blockchain, and a community of users can control how the record of information is improved and updated.
Blockchain: How does work
Let’s recall a few key features before explaining this topic.
- Blockchain keeps a record of all exchanges data and then this record is referred to as a “ledger” in the cryptocurrency world, and each data exchange is a “transaction”. After this, every verified transaction is added to the ledger as a “block”.
- Blockchain utilizes a distributed system to verify each transaction (a peer-to-peer) network of nodes.
- If once signed and verified, then the new transaction is added to the blockchain and cannot be altered.
To begin, we need to examine the concept of “keys”. You get a unique identity with a set of cryptographic keys. Your keys are the two types, the Private key, and Public key. They are combined together to give you a digital signature.
The public key is how others are able to identify you and private key gives you the power to digitally sign and authorize different actions on behalf of this digital identity when used with your public key.
In the world of cryptocurrency, the public key represents your wallet address and your private key is that you authorize transfers, withdrawals, and other actions with your digital property like cryptocurrencies.
This is why because it is so important to keep your private key safe. Anyone who has your private key, they can use it to access any of your digital assets associated with your public key and do what they want with it.
When a transaction occurs then everytime that transaction is signed by whoever is authorizing it. That transaction quite similar like “X is sending Y 0.8 BTC”, will include Y’s address (public key), and will be signed by a digital signature using both X ’s public key and private key. This gets added to the ledger of that blockchain that X sent Y 0.8 BTC, and will also include a timestamp and a unique ID number. After occurs or this transaction, it is broadcasted to a peer-to-peer network of nodes.
Each transaction in that ledger will have same data like a digital signature, a public key, a timestamp, and a unique ID. Each transaction will be connected, so if you move back one transaction in the ledger, you may see that Chuck sent X 0.8 BTC at some time. If you move back another transaction, you might see Z sent chuck 0.2 BTC at some other time before that.
Blockchain: Benefits
- All information and transaction are in control of users.
- Data is consistent, accurate and widely available.
- Blockchain does not have a central point of failure because of the decentralized network.
- It reduces complexity because all transactions are added in the form of blocks to a single public ledger.
- Reduction in transaction fees.
- Faster transactions (as the bank can take days for clearing all the formalities and authentications).
Blockchain: Disadvantages
- Every transaction requires signature verification because in the centralized database once a connection has been established, it is used for further transactions. But here we have a decentralized system.
- There is a tough barrier to entry to become a Node, encouraging a larger amount of centralization in the network, with bigger players being able to take more control.
- There is one important security flaw in bitcoin and other blockchains. When more than half of the computers working as nodes to service the network tell a lie, then the lie will become the truth. This is called a ‘51% attack’ and that was highlighted by Satoshi Nakamoto, when he launched bitcoin.
Industries That Are Ready For Blockchain
Donald Arthur Norman (the director of The Design Lab at University of California) once wrote that many products failed because they were released at the wrong time. But in my point of view, I remake this statement and say “Many technologies fail to find practical applications. In the ’90s when the internet became widely available, each field tried to apply it to their business.
It was a failure, and its outcomes are still visible. Thousands of never-visited websites with horrible interfaces, which is clumsily created by anyone, who had a computer. We are currently going through the same situation i.e; the most potential technology of the decade is associated with speculations on crypto-exchanges. However, it was initially created for the contrary but now it is widely used for financial scams.
One reason for blockchain appeared was to exclude the human factor from the business. Therefore the industries that may have blockchain successfully implemented are those that heavily depend on human activity and suffer most from human errors, like finance.
From different industries, blockchain is being applied to the various product. Therefore we just need more daring entrepreneurs who are willing to put a lot at stake.
Fintech deals with a very thorny matter that is money. It is exactly where most of the fraud takes place. One fundamental mechanism that pushes people to do bad things is the desire to become richer. The important aim of fintech startups is to improve the traditional financial institutions. For instance, excluding the human factor from the financial activities.
Blockchain utilizing excludes third parties from the financial transactions, like a bank that verifies the person between which the transaction is made. It can be used for managing inventory and logistics, optimizing the person identification, trading goods, tracking transaction and more.
But it does not mean that every fintech product can easily adopt blockchain. Here we describe some cases when you might want to use blockchain:
- You want to attract investments: Blockchain attracts more investments than real, working products.
- You want to increase your competitiveness in the market: You will instantly show your professionalism, thus becoming more attractive to investors and customers, if you manage to build a product on blockchain successfully.
- When You are ready to experiment: Any blockchain-based product is an experiment because few know what this technology is capable of. Blockchain could be the right choice if you are ready to make a breakthrough in your industry.
In the following cases, I do not suggest to implementing blockchain
- You are limited in resources: There are few blockchain engineers, and it is expensive to have them in the team. Therefore it is a high-risk way of creating a product.
- You are not ready for important changes: The changes include operational management and human resources. Assume that if you are a bank that has implemented blockchain, you will most likely need to let many employees go since there will be less work for people.
- You have a short-term vision: Blockchain is about long-term view. It cannot be executed in a month or so. Unless you have a long-term product roadmap, do not bother yourself with dreams about changing everything in tomorrow.
Blockchain: How To Apply In Fintech
‘Frameworks’ to use
CryptoNote
It is an open-source project that allows you to create crypto coins. For creating a cryptocurrency, they have a simple step-by-step guide. You will need to have two nodes to launch it, which will be used to run the Monero server.
Ethereum
It is a popular open software platform for building decentralized applications. Ethereum focus is running the programming code of your blockchain-based app. It is an application that runs exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference.
ZeroNet
It is used for creating decentralized websites. Zeronet uses the Bitcoin addressing and verification mechanism, and the BitTorrent distributed content delivery network to create sites that cannot be censored, forged or blocked.
Build simple blockchain
Now that you know the tools which are described above. For instance, Cryptonote, Ethereum, and Zeronet. Now we are moving to build a basic blockchain of our own. In this, I will be using Python as an example, but if python is not your primary coding language, you will still understand the logic and be able to write it in another language.
First of all, I will explain the fundamental elements required to build a block. I will start with the date of creation, checksum, nonce, and transaction data. Transaction data in our case could be just a line to simplify the code.
Date of creation
Date of Creation is the current and time in Unix format. It is required to development of your blockchain in future. When there are many running nodes and you want to add a new block to your branch then the node will decide which block to use based on Date of Creation.
Nonce
The nonce is a unique set of symbols that we need to add to the block to build the checksum that fits the requirements. For instance, if the nonce value is 4, then we have to add 4 zeros (0000) to the data block to calculate the right checksum.
Checksum
Sometimes checksum referred to as hash value, hash code, or simply a hash. A checksum is a block data with nonce plus checksum of the previous block. SHA256 protects the ledger chain from being rewritten.
How it works: first, the node calculates the checksum and compares to the one of the new block then the block is added to the blockchain if they match.
Data
It is a set of data that will be stored in the block and signed. It can contain any kind of data. For ex., bitcoins stores not only the last transactions, but it can also store a list of transaction or you can store the information about the computer that created the block. For exa., its MAC address or you can have a more detailed date of creation, say, adding the time zone.
Proof of work
Proof of work is a unique consensus algorithm in a blockchain network. POW is used to validate the operations and the creation of new chains in the blockchain network. The main work of POW is to add complexity to building a block on the client side and reduce the load on the server side. For ex., I say checksum has to have 4 lead zeros that mean we will increase nonce until checksum will not have 4 lead zeros.
You can also read “Things to Consider Before Launching a Fintech Product”
Let’s start with a code
Firstly, I will create a class for a block. It is a method for calculating the checksum and property to check that block is valid. we will have two constants, one for a number of lead zeros in checksum and a second to identify which symbol we will use with the nonce.
import time from hashlib import sha256 class Block: def __init__(self, prev_block, data): @property return ( def calculate_checksum(self): return sha256(bytes(data, ‘utf-8’)).hexdigest() |
Constructor
It accepts only two parameters. The first is previous block data, and the second is the current block data. It also creates the time mark and sets nonce to zero as its initial value.
Is valid
It is a property that calculates the checksum and compares if the current one is equal to the calculated and has the right number of zeros.
Calculate checksum
It is the most complicated method in our code. It packs the time mark, data, and checksum of the previous block to one string. Now we add a nonce string, in our case, it will be a list of ‘z’. Then this calculates the checksum of the result string.
Now we have a simple and fully functional block. Now I will move on to creating a chain of blocks. Without the ability to store and load data, it will be a simple chain, but it will convey the main idea.
import json
class Chain: def __init__(self): def is_valid(self): def add_block(self, data): return block @staticmethod return genesis_block @staticmethod block.checksum = checksum return block |
Let’s take a look in our chain class method:
Constructor
I just created a chain with only one genesis block. The first block of the chain that has only a checksum is genesis block. The real genesis block requires a checksum of the last block in the chain. Therefore, this block is required for adding the first real block to the chain.
Adding a new block
It has only one parameter that is data for a new block. This method creates a new block with the help of given data and runs a method to find a correct nonce value. Only then, it will add a new block to the chain.
Find the nonce
The aim of this method is to find the right nonce for a block. It has an infinite loop where I increase the nonce and calculate a new checksum. Then it compares the checksum with the rules, but for now, it is only the number of zeros.
Validate the chain
This method goes through all blocks in the chain and checks if each block is valid.
Conclusion:
From this article, I attempted to prove that building a simple and working blockchain is not as difficult as it may seem. My advice is to take the required information from here and start playing with blockchain by experimenting with blocks and data.
Some people belong from the fintech industry. I want to suggest those people, study more about the products that are using blockchain.