How to Build Your Own Blockchain For a Fintech Product

Mar 22, 2024
/
12 min read
How to Build Your Own Blockchain For a Fintech Product
Vadym Zakovinko
Vadym Zakovinko
Software Architect / Team Lead
Technologies are changing fast; people are not.

Jakob Nielsen

Blockchain is a relatively new technology that many deem is used only for buying Bitcoins. They try to implement it in whatever sphere comes to mind, whether it is fashion, education or healthcare. If you are interested in the practical application of blockchain, you may even consider building your own blockchain.

I would say it is okay — too little time has passed to determine which area of human activity can benefit the most from applying this technology. To understand the practical application of blockchain, we must first define why it appeared, and then study cases when blockchain can make a significant difference.

Note: This article does not explain the blockchain concepts; instead, it focuses on developing a fintech application using this technology. Since 2008, the Django Stars engineers have been participating in developing advanced fintech products, for example, the UK’s first digital mortgage lender Molo and the Swiss-German investment platform Sanostro. Based on this experience, I will explain why fintech can already adopt the blockchain, and most importantly, focus on developing a decentralized application using this technology. So this will give you a good understanding of how to create your own blockchain.

Industries That Are Ready for Blockchain

Don Norman once wrote that many products failed because they were released at the wrong time. I can remake this statement and say: Many technologies fail to find practical applications. When the Internet became widely available in the beginning of the ‘90s, each sphere tried to apply it to their business. It was a catastrophe, and its consequences are still visible by thousands of never-visited websites with horrible interfaces, clumsily created by anyone who had a computer. We are currently witnessing virtually the same situation—the most potential technology of the decade is associated with speculations on crypto-exchanges. It is widely used for financial scams, although it was initially created for the contrary.
How to Build Your Own Blockchain For a Fintech Product 1
Source: Microsoft Azure
An attempt to exclude the human factor from the business was one reason why blockchain appeared. That is why the industries that may have blockchain successfully implemented are those that (1) heavily depend on human activity, and (2) suffer most from human errors, like finance.
Important: Blockchain is being applied to various products from different industries; we just need more daring entrepreneurs who are willing to put a lot at stake.

Fintech deals with a very thorny matter – money. It is exactly where most fraud takes place. The desire to become richer is one fundamental mechanism that pushes people to do things, often bad things. Fintech startups aim to improve the traditional financial institutions, for example, excluding the human factor from the financial activities.

Utilizing blockchain 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 the inventory and logistics, trading goods, optimizing the person identification, tracking transactions and more.

It does not mean that every fintech product can easily adopt blockchain. Here are some cases when you might want to use blockchain:

  • You want to attract investments. Like it or not, blockchain is still a buzzword. It attracts more investments than common working products. Though, to get those funds you should prepare a convincing investment proposal, but blockchain solution may become a game changer for yor product.
  • You want to increase your competitiveness in the market. If you manage to build a product on blockchain successfully, you will instantly show your professionalism, thus becoming more attractive to investors and customers.
  • You are ready to experiment. Yes, any blockchain-based product is an experiment because few know what this technology is capable of. If you are ready to make a breakthrough in your industry, blockchain could be a right choice.

Read also: How to Write to a Request for Proposal (RFP)

I do not suggest implementing blockchain in the following cases:

  • You are limited in resources. It is a high-risk way to creating a product because (1) there are few blockchain engineers, and (2) it is expensive to have them in the team.
  • You are not ready for significant changes. The changes include operational management and human resources. 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 short-term vision. Blockchain is about long-term perspective. It cannot be implemented in a month or so. Unless you have a long-term product roadmap, do not bother yourself with dreams about changing everything tomorrow.

What you can do tomorrow, and even while reading this article, is to build a simple blockchain. It is the focus of part 2. I will tell you about the main components that are required to build a blockchain for fintech products, propose some tools, and show real pieces of code with explanations.

Disrupt the financial market
with a strong product

Learn how

How to Apply Blockchain in Fintech

Fintech products and services are gradually replacing traditional banking services and approaches. This underscores the importance of fintech product development to meet the evolving needs and preferences of modern consumers. Let’s find out how to build a blockchain and apply it to the fintech sector.

‘Frameworks’ to use

CryptoNote

CryptoNote is an open-source project that allows you to create your own blockchain and crypto coins. They have a simple, step-by-step guide to creating a cryptocurrency. To launch it, you will need to have two nodes which will be used to run the Monero server.
Useful links:
How to create a coin
How to create a wallet

Ethereum

A popular open software platform for building decentralized applications. Its focus is running the programming code of your blockchain-based app. Quoting the Ethereum website: “Ethereum is a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third party interference.”

ZeroNet

ZeroNet is used for creating decentralized websites. It uses the Bitcoin addressing and verification mechanisms, and the BitTorrent distributed content delivery network to create sites that cannot be censored, forged or blocked.

Create Your Own Blockchain

Now that you know the tools – Cryptonote, Ethereum and ZeroNet – we are moving to building a basic blockchain of our own. I will be using Python in this example, but if it is not your primary coding language, you will still understand the logic and be able to write it in another language.

First, I will explain the fundamental elements required to build a block. I will start with date of creation, nonce, checksum and transaction data. Transaction data in our case could be just a string to simplify the code.

Date of creation

It is the current and time in unix format. It is required for the future development of your blockchain; when there are many running nodes and you add a new block to your branch, the node will decide which block to use based on Date of Creation.

Nonce

It’s a unique set of symbols that we need to add to the block to build the checksum that fits the requirement. For example, if the nonce value is 5, then we have to add 5 zeros (00000) to the data block to calculate the right checksum.

Checksum

Also sometimes referred to as hash value, hash code, or simply a hash. It is block data with nonce plus checksum of previous block. SHA256 protects the ledger chain from being rewritten.
How it works: Node calculates the checksum and compares to the one of the new block; if they match, the block is added to the blockchain.

Data

It’s a set of data that will be stored in block and signed. It can contain any sort of data: e.g., bitcoin stores a list of transactions, not only the last transaction; or you can store the information about the computer that created the block, like its MAC address; or you can have a more detailed date of creation, say, adding the time zone.

Proof of work

Proof of work (PoW) is a unique consensus algorithm in a blockchain network. It is used to validate the operations and the creation of new chains in the blockchain network. The main idea of PoW is to add complexity to building a block on the client side and reduce the load on the server side. For example, I say checksum has to have 5 lead zeros; it means that we will increase nonce until checksum will not have 5 lead zeros.

Let’s start with a code

First of all, I will create a class for a block. It will be a very simple class with a constructor, a method for calculating the checksum and property to check that block is valid. We will have two constants, one for 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:
    CHECKSUM_LEAD_ZEROS = 5
    NONCE_SYMBOL = 'Z'
    def __init__(self, prev_block, data):
        self._prev_block = prev_block
        self.data = data
        self.checksum = None
        self.nonce = 0
        self.timestamp = time.time()
    @property
    def is_valid(self):
        checksum = self.calculate_checksum()
        return (
            checksum[:self.CHECKSUM_LEAD_ZEROS] == '0' * self.CHECKSUM_LEAD_ZEROS
            and checksum == self.checksum
        )
    def calculate_checksum(self):
        data = '|'.join([
            str(self.timestamp),
            self.data,
            self._prev_block.checksum,
        ])
        data += self.NONCE_SYMBOL * self.nonce
        return sha256(bytes(data, 'utf-8')).hexdigest()

Constructor

Constructor accepts only two parameters; the first is a previous block, and the second is the current block data. Also, constructor creates the time mark and sets nonce to zero as its initial value.

Is valid

A property that calculates checksum and compares if the current one is equal to the calculated and has the right number of zeros.

Calculate checksum

The most complicated method in our code. This method packs the time mark, data, and checksum of the previous block to one string. Then we add a nonce string; in our case, it will be a list of ‘Z’. Then it calculates the checksum of result string.

Now we have a simple yet fully functional block. I will move on to creating a chain of blocks. For now, it will be a simple chain without the ability to store and load data, but it will convey the main idea.

import json
class Chain:
    def __init__(self):
        self._chain = [
            self._get_genesis_block(),
        ]
    def is_valid(self):
        prev_block = self._chain[0]
        for block in self._chain[1:]:
            assert prev_block.checksum == self._prev_block.checksum
            assert block.is_valid()
            prev_block = block
    def add_block(self, data):
        block = Block(self._chain[-1], data)
        block = self._find_nonce(block)
        self._chain.append(block)
        return block
    @staticmethod
    def _get_genesis_block():
        genesis_block = Block(None, None)
        genesis_block.checksum = '00000453880b6f9179c0661bdf8ea06135f1575aa372e0e70a19b04de0d4cbc7'
        return genesis_block
    @staticmethod
    def _find_nonce(block):
        beginning = '0' * Block.CHECKSUM_LEAD_ZEROS
        while True:
            checksum = block.calculate_checksum()
            if checksum[:Block.CHECKSUM_LEAD_ZEROS] == beginning:
                break
            block.nonce += 1
        block.checksum = checksum
        return block

Let’s take a look at methods in our chain class:

Constructor

I just created a chain with only one block – a genesis block. Genesis block is a first block of the chain and has only a checksum. This block is required for adding the first real block to the chain because the real block requires a checksum of the last block in the chain.

Adding a new block

It has only one parameter — data for a new block. This method creates a new block with the given data and run method to find a correct nonce value. Only then, it will append a new block to the chain.

Find the nonce

This method aims 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 — for now, it is only the number of zeros.

Validate the chain

This method tells us if the chain is valid. It goes through all blocks in the chain and checks if each block is valid.

Bottom Line

In this article, I attempted to prove that building your own blockchain, simple and yet working, is not as difficult as it may seem. My general advice is to take the lesson you learned here and start playing with blockchain by experimenting with blocks and data. All great products, including blockchain, were experiments once.

If you are from the fintech industry, I suggest you study more about the products that are using blockchain. Some things about them are certain; they are more secure, more attractive for investments, and, if they succeed in the global market, will be called game changers. The first step of adapting the new technology has been taken. The next step is to spread the knowledge and educate people about the features of blockchain.

Stay tuned for the next part about blockchain and fintech, most likely with more complex pieces of code and suggestions on its practical application in fintech from our Python development company.

Thank you for your message. We’ll contact you shortly.
Frequently Asked Questions
What are the benefits of building my own blockchain?
  • With blockchain — which is still a buzzword — and a convincing investment proposal you can attract more investments than with common working products.
  • If you manage to build a product on blockchain successfully, you can show your professionalism, thus becoming more attractive to investors and customers, and increase your competitiveness in the market.
  • Any blockchain-based product is an experiment because few know what this technology is capable of. If you are ready to make a breakthrough in your industry, blockchain could be a right choice.

Also, utilizing blockchain excludes third parties from the financial transactions, like a bank that verifies the person between which the transaction is made.

What programming languages are commonly used to build a blockchain?
Various programming languages are used to build a blockchain, but the most popular ones are Solidity (for Ethereum blockchain development), JavaScript (to build decentralized applications (dApps) on blockchain platforms such as Ethereum and NEO), Go (to build blockchain infrastructure, including nodes, mining software, and APIs), C++, Rust, Java, Python, and Ruby. The choice largely depends on the requirements of the project and the particular blockchain platform being used. The examples in the article use Python as it's one of the most popular and easy-to-read programming languages.
How can Django be used in blockchain development?
Django can be used as a backend framework to build web apps that interact with blockchain networks. Django's web development capabilities and its built-in Object Relational Mapping (ORM) make it easy to integrate blockchain functionality into web applications. With Django, developers can build blockchain-based applications that utilize smart contracts, interact with nodes on the network, and perform transactions on the blockchain. Additionally, Django's security features and support for multiple authentication methods can help ensure the security of blockchain-based apps.
What are some use cases for combining Django and blockchain technology?

Among other things, Django can be used

  • to build a web app that integrates with a blockchain-based supply chain management system,
  • to build a backend for DeFi apps that leverage smart contracts and blockchain technology to provide financial services such as lending, borrowing, and trading,
  • to build a web app that uses blockchain technology to securely store and manage user identities,
  • to build a web app that integrates with a blockchain-based voting system to provide a secure and transparent voting process,
  • to build a backend for blockchain-based gaming apps that utilize non-fungible tokens (NFTs) to represent in-game assets and provide secure ownership and transferability.

Have an idea? Let's discuss!

Contact Us
Rate this article!
2 ratings, average: 2 out of 5
Very bad
Very good
Subscribe us

Latest articles right in
your inbox

Thanks for
subscribing.
We've sent a confirmation email to your inbox.

Subscribe to our newsletter

Thanks for joining us! 💚

Your email address *
By clicking “Subscribe” I allow Django Stars process my data for marketing purposes, including sending emails. To learn more about how we use your data, read our Privacy Policy .
We’ll let you know, when we got something for you.