bitcoin blockchain blockchain programming what is blockchain programming

What is Blockchain Programming - A Blockchain Deep-Dive

Written By Ivan on Tech

Jul 16, 2020

Blockchain technology is still a relatively new technology. However, it has become a widespread phenomenon through the rise of cryptocurrencies, such as Bitcoin. But even though it is easy to associate blockchain with Bitcoin, this is far from the only area where this technology can be utilized. Nevertheless, to understand how blockchain can be used in different industries, we first need to understand what blockchain programming is and what problems it solves.

Why Blockchain Programming?

To understand the advent of blockchain programming and blockchain solutions, it is necessary to understand where it comes from. In business, the top priority is to make money. However this can, in some cases, be detrimental to the end-consumer. Greed has become a big part of business in recent years. Moreover, the suppliers of services are taking full advantage of this, charging high fees for essential services.

The people who suffer the most from this greed and exorbitant costs are the consumers and the less fortunate people in society. An example of this can be seen in big banks, who charge massive fees for finance operations that are essential to society. Since such middlemen act only out of self-interest and greed, one solution to this problem would be to cut out the middleman.

Naturally, the most efficient distribution of services of offerings would be to directly connect producers and consumers, without any friction between them. Unfortunately, producers do not always have the resources to distribute their products or services directly to consumers, which makes it necessary to use middlemen. This means that the middleman often brings some value to the supply chain, but it comes at a cost since they act out of pure self-interest. And the people paying for this are the consumers. But is it possible to cut out the middleman completely? Ten years ago, many would argue that this was impossible. Nonetheless, with the help of blockchain, we are now able to replace the middleman with technology. Specifically, blockchain technology.

Most significantly, having a computer as the bridge between the producers and the consumers is that a computer isn't run by self-interest or greed. It doesn't seek to benefit itself at the consumer's expense. Put simply, the network does not require payment from the customer, like a traditional bank. This means that we can now distribute something to consumers without having to deal with a greedy intermediary.

How is Blockchain Programming in Use Today?

It is hard to talk about blockchain without first mentioning Bitcoin, which is perhaps the most famous example of blockchain and blockchain programming in use today. Bitcoin first saw the light of day back in 2008. Adding to the mythos surrounding this coveted "digital gold", the creator of this illustrious cryptocurrency is the mysterious Satoshi Nakamoto - the identity of which is still unknown. Some speculate that the name Satoshi Nakamoto is only a pseudonym, and the mysterious nature of the Bitcoin creator also means that we can only speculate what personal reasoning he/she/they had behind inventing Bitcoin. Nevertheless, the famous Bitcoin white paper clearly lists the benefits of peer-to-peer electronic cash systems. The fact that computers are not driven by self-interest is at the very center of Bitcoin, other cryptocurrencies, and all blockchain programming .

Bitcoin is an excellent example of when blockchain is in use to cut out an intermediary. Money has been around for ages, and money is - at the same time - continually evolving. Using gold was the standard back in the day where coins were used as the currency.

That later changed as paper money was introduced and replaced that of the gold. This was done since paper weighs a lot less than gold and other metals. This later became what we are seeing more and more today, a currency system without physical cash.

However, the systems of old and what is in use today requires banks by design. Furthermore, it is the banks that act as a middleman in this scenario. Banks can take advantage of this by taking transaction fees, among other things, and this was something that Bitcoin - and in extension blockchain programming - revolutionized.

Banks are also vulnerable by their very nature, since they use centralized systems to store money, both digitally and physically. This means that a bank is prone to hacking, and keeping all information/records in one place presents a risk for financial fraud.

What does Bitcoin do differently?

Some of the problems that fiat currencies - i.e. precursors to cryptocurrencies - had was that all the information was stored in one place, that the systems were not secure enough, and that there was nothing guaranteeing people their privacy.

This meant that a new system stemming from blockchain programming would need to become decentralized, secure, and ensure privacy. So how has Bitcoin done this?

Decentralization

To solve the issue of centralization, Nakamoto introduced a blockchain-driven, peer-to-peer (P2P) system that would allow us to store information in parts in different locations.

The system that Bitcoin is using is similar to that of torrents. However, instead of downloading information from one central server - such as when using a torrent - one connects to a network of people and downloads the information from someone who already has it.

Centralized Network Structure vs Decentralized Network

Blockchain works using these same principles, where different people have different information. This means that no single person or company owns all data, which means that they can not control it on their own. Moreover, this basically means that no single actor can control the system - just like no single entity can control the Bitcoin network, as more actors connect to it.

Cryptography

Cryptography takes care of the second problem with legacy middlemen, which is security. This also allows you to sign a message or transaction online. This uses a simple message, a private key, and a public key.

The private key acts more or less like a password; meanwhile, the public key can be likened to a username. These two keys consist of a long sequence of numbers, letters, and signs, and connect to each other.

When the message and the keys go into the algorithm, another sequence of letters, signs, and numbers appear - and this is the signature for the transaction. Once we create a message, we can verify it by using a cryptographic algorithm where we use both keys. When doing this, it will confirm that it was, in fact, the owner of the private key that signed.  

Since these keys and signatures consist of many letters and numbers, they become extremely hard to hack. In fact, it would take over one thousand years to crack a message using current technology.

Privacy

Privacy is also at the heart of cryptocurrencies, and important to the vast majority of those buying Bitcoin. When deciding to buy Bitcoin, the first thing a user needs to do is to create a wallet. The wallet is your public and private key. These have no tie to the true identity of the user, so unless he/she decides to tell someone precisely what his/her keys are, it is impossible to find out who owns them.

This concept allows for a lot of privacy. In theory, even governments would not have an idea of who a person is trading and sending money too. This, however, has a backdraw, though, since it is easier to make trades for illegal activities.

So What is Blockchain Programming?

Naturally, blockchain programming is at the core of blockchains. As the name might suggest, blockchain technology encases information in chains of blocks. Arguably the most well-known example of a blockchain is the Bitcoin blockchain. The Bitcoin blockchain creates new transaction blocks approximately every 10 minutes. When a new block forms, this block contains several transactions. The block also includes a cryptographic signature known as a hash from the previous block, meaning one block verifies the block before.

Through the process of validating transactions, the validators receive Bitcoins. This process is what is commonly known as mining, or crypto mining. The process of crypto mining essentially revolves around solving cryptographic puzzles. As more and more puzzles are getting solved, the difficulty of the puzzles increases, and at some point, they will become unsolvable. This means that there exists a cap on how many Bitcoins will exist around 21 million BTC. Moreover, the rate of Bitcoin mining decreases through "halving events", which make new Bitcoin increasingly scarce.

Hash

One of the main parts of a blockchain is its digital signature. That is what we are calling a "hash". From a blockchain programmer's or coder's perspective, a hash can be seen as a function that will return a string that someone types in, and then return it in a fixed string.

Once we enter a string into the function for the hash, it will result in a long string of numbers and letters. Once we receive a hash we can never change it; it is therefore irreversible. The hash function is designed in a way that two hashes will never have the same value. This means that every hash is unique, and no digital signature can ever be the same. If the underlying data changes by even a smidge, the hash will change complete.

So why is the hash so important?

As mentioned before, the hash is a crucial component in blockchain programming. This is because when a new block is created within the chain, it will contain the hash from the previous block.

To clarify, this can look something like [aaa, "X paid $50 to Y", bbb].

In this case, "aaa" is equal to the hash of the previous block, "X paid $50 to Y" is the transaction that took place, and "bbb" is the hash of the current block. So when the next block forms "aaa" in block 2 will be equal to "bbb" in block 1.

This example is naturally just a simplified version of what this is going to look like in practice. For example, "aaa" and "bbb" will be longer and more complex than they appear above. The transaction's list can also be far longer; it can, for example, contain various transactions. This means that a block can contain more than one transaction, but it will nevertheless precisely show the transactions that have been made.

Ethereum and Smart Contracts in Blockchain Programming

As we mention in the section "Why Blockchain?", the middleman can be eliminated through smart programming. The blockchain programming that underpins Bitcoin presents a breakthrough innovation in many ways, but it lacks in one area; autonomy.

This potential "lack of autonomy" with Bitcoin partly led to the development of another cryptocurrency; Ethereum. Vitalik Buterin is the creator of this cryptocurrency, and one way Ethereum differs from Bitcoin is through something known as "smart contracts". These smart contracts essentially hold a piece of code that runs whenever something successfully interacts with the code.

Vitalik Buterin

Smart contracts generally contain certain conditions, and when these are met, the code that the contract is holding will activate. Many argue that this is a distinct advantage, since smart contracts make the system more autonomous. If someone is to sell something online, a smart contract could, for example, help people upload a listing for the item.

However, eventhough smart contracts are a great supplement, they are still somewhat dumb. Some of the contracts can not only be run solely by a computer; in some instances, a human needs to interact as well. It can also be hard to utilize this technology in the real world.

How to program smart contracts with Solidity

Ethereum runs on a blockchain programming language called Solidity (among other programs). Solidity is the most popular language for smart contracts.

Example:

Let's say we are trying to create a smart contract that will store someone's salary for one month and where the employee can retrieve this information. When creating a smart contract for this scenario, we need two things; firstly, we need the name of the employee. Secondly, we need the salary of the same person.

Before coding this information, we need to notify the compiler what version of Solidity is running. A compiler is a program that basically translates code from one programming language to another.

Once this is complete, we can start coding the names and the salary. The first thing to do is to create a string array of the names, and after this, we can create another string array that is working together with the name array.

Once the arrays are complete, we can program the contracts so that we can send them to the employees. The names of the students will then be made into arguments and then stored in the array for the names. When we finish this, we can create a function where we can assign the employees their salaries. To make sure that the employee will receive their correct salary, we must also create a function that ensures that the employee is the right one.

After this, the function to give an employee their salaries will need two arguments. The function requires the name and the salary of that employee. Moreover, the function to verify the name of the employee will only execute if someone writes the right name.

The last step would be to create a function for the employees. This function should allow employees to acquire their salary. This function would only accept the employee's name as an argument and will, in return, give the salary.

Gas

Once someone writes the code and everything is working, we need to deploy it on the blockchain. When implementing the contract on the blockchain, this will cost you gas. And this is to "pay" other people who are allowing you to use the power of their computers.

If you are creating your private blockchain, there is no need to pay for gas. But if it were to become public on the Ethereum blockchain, a payment of gas is a requirement.

If you would like to learn more about what blockchain programming is, how to code smart contracts, and blockchain in general, feel free to sign up at the go-to online blockchain academy Ivan on Tech Academy for a great selection of blockchain courses.

Like what you're reading?

Get to work in a fast growing industry. Start learning blockchain together with our 20,000+ students today.
Use coupon code BLOG20 for 20% off.

Become Blockchain Certified Today No Prior Knowledge Needed!
Close

Get our Free Ebook

Enter your email and we will send it to you!