BooksC

How C++ Can Help You Become A Blockchain Developer

4 Mins read

Blockchain has taken off as one of the biggest tech advances in this decade. There are courses everywhere, news, updates and things are even more active on the development side. Yet it does seem like a strange concept to wrap your head around.

What Is blockchain?

A Blockchain is a distributed decentralized chain of units called blocks. These units hold data of value, and the type of data differs from one implementation to another. In a sense, it’s not so different as an abstract idea from Wikipedia. Wikipedia is a community held technology, people can add or edit information, and everyone has got access to. On the backend, however, things are totally different when it comes to a blockchain.

The blockchain is a digital ledger, transparent and visible to anyone (with access) to see, a distributed database that’s not held by anyone. It was originally devised for the digital currency, Bitcoin whose total worth today exceeds 230 billion dollars.

Blockchain has evolved today, and it’s becoming the father of new businesses in the world of the internet. However, when the internet of things hits the floor, blockchain technology will ascend to new heights as it leverages the power of IoT.

How Is It Developed?

Now, how can you become a blockchain developer? It might seem like rocket science, but it really isn’t. First, you need to understand the ideas underlying the security. Remember that security is of the essence here, otherwise, people would go around messing up the ledger as they please. In blockchain, you don’t rely on usernames and passwords for security. Blockchain uses encryption technology as the security method. So you need to get familiar with keywords like hash functions, public keys, and private keys, etc…

Like anything in the digital world, blockchains are developed using certain general purpose programming languages. Something like Go, C, C++, Java or Python. The bitcoin’s source code was written in C++ so let’s focus on it.

There are certain criteria that have to be met in a blockchain code.

First of all, your blockchain has to be a fortress. Since the code is open source and the public for everyone to see, anyone can identify the bugs and the vulnerabilities lying in the code. Such exploits might cost millions of dollars at a time. Despite the fact security is a major issue, it’s not the only one. There’s the topic of isolation and efficient resource management, and of course the performance. However, for the sake of simplicity, we will not dive too deep into these topics. C++, in fact, does meet a lot of these harsh requirements, which makes it an ideal candidate for the job. C++ allows for an extra degree of freedom in what it can do, with the memory management, but it comes at a price. Degrees of freedoms are usually degrees of responsibilities as well.

For the sake of demonstration, let’s build our own blockchain here. We’ll demonstrate the concepts in Javascript for simplicity but we’ll also show the equivalent C++ code.

Remember we said blocks are the building unit of a blockchain, so we start there. Each block contains some information which are:

The index of this block in the entire ledger.

The actual data that it is holding, whether transaction information or a smart contract( we’ll take about it later in more details).

The timestamp of when the block was created. The hash of this block and the hash of the previous block. This serves to keep the data valid and consistent at all time. So we start out by creating the block constructor, which is a special function or method that’s invoked when an instance of the object is created. It takes the information of the block as parameters, sets the value then calls the function SHA256 to compute the hash of the data.

In C++ however, we need to define the block data explicitly and then compute the hash. Computing the hash is actually an interesting thing, you can refer to this page to see the entire code and how to do it Link: https://gist.github.com/hak8or/8794351

Though, it’s not as simple as Javascript, at least without using a library.

Now that we’ve created a block let’s see how our blockchain technology will unfold. We now need to create a blockchain class, which is like the data structure we’ll be using for our data.

A lot of things are going on here, so don’t get frustrated if you can’t wrap your head around the syntax. Conceptually, Our blockchain should do a few things. First of all, when it’s first created, it needs to create the “Genesis block” The block that’s not preceded by any other block. Then our blockchain should keep on doing two things. Namely, adding new blocks when they’re valid, and validate the chain. Of course, there’s much more to this than that, it’s an entire branch of science, but we’re taking the first steps in a vast sea of knowledge.

C++ Foundations

Now if you have no prior knowledge of C++, rest assured that it’s not as hard as people say. Here are four tips that can bring you from a novice level to pretty much wherever your efforts take you.

  • Digest the basics. You need to build a solid foundation in programming. Whether it’s data structures, algorithms, or plain code, you need to be able to understand the content ahead of you.
  •  Don’t be intimidated to start a new course. You can find the best C++ tutorials and courses on the internet over diverse platforms. Don’t be afraid to start a course.
  • Learn by practice. This is the most important thing of all. You can go ahead and binge-watch all courses on c++, but unless you start working with your own hands you won’t get anything done. Websites like Codeforces and Code Academy are there to help you get to the next level.
  • Ask an expert, don’t be shy. There’s no shame in asking someone with experience, the community is huge, and you can easily find someone to help you. Hackpledge is an amazing website for the job.

Final Thoughts

Recently, a new type of data emerged into the blockchain world. Smart Contracts, mini-programs sometimes equipped with a database, that executes under certain conditions. For example, pay bob 100$ if the date is 3/1/2019 and so forth.

While it comes with its own challenges, it shows how far the blockchain technology can go. The blockchain is now used not only for digital currencies but also for businesses like Crowdfunding, sharing economy and even file storage. 

The technology is certainly walking by leaps and the future is deemed to witness more of it. Some people have gone as far as calling the new web. It’s a very blooming and promising field, and definitely worth learning.

Leave a Reply

Your email address will not be published. Required fields are marked *