Smart Contracts: What Are They, How Do They Work And What Do They Contribute? (Part II)

Smart Contracts What Are They How Do They Work And What Do They Contribute (Part II)

A Smart Contract is not what you think

Today everything is controlled by computer systems. Everything interacts with them.

In the development of applications it is normal for programmers to create a series of “doors” to their application (called APIs) with which other programmers can enter your application to create or obtain information.

Smart Contracts What Are They How Do They Work And What Do They Contribute (Part II)

Almost every web or program has its own. That is to say, a protocol is defined, a contract, a known form in which the application is called with a data structure, by which we are going to obtain an answer, but with a predictable data structure. In this case so that communication does not fail, and I get the programs.

But this contract is not guaranteed. The application server is controlled by someone who has the ability to make tomorrow’s program work differently. It is centralized and can mutate to that third party’s decision. It is not “Smart”.

People need predictable, transparent and incorruptible environments.

Smart contracts are pieces of similar codes, that is, they have ways of calling them and getting answers, they have a contract, but they are also immutable because they are distributed in thousands of nodes that cannot alter their content.

In this way you get a program that will always act in the same way without requiring the goodwill of that third party. Something that for almost any case of use is necessary.

Smart Contracts are programs in the cloud that always act in the same way, and allow to store information that cannot be treacherously modified.

They are the safest programs ever created in mankind and only fail when badly programmed.

Badly programmed Smart Contracts

Smart Contracts are capable of managing digital assets, subject to a certain economic value, so Smart Contracts can actually manage money.

Smart Contracts What Are They How Do They Work And What Do They Contribute (Part II)

This requires special emphasis on the correct programming of the same, as the Smart Contract could have security flaws or failures that generate execution errors or unexpected behaviors.

When this happens, the money can be completely lost. It has not happened a few times, and without sufficient Know How it will continue to happen to many initiatives.

Unfortunately this happens frequently. So it is really important to pay special attention to the development and testing of these pieces of software.

How is a Smart Contract made in Bitcoin?

For all this to be possible, there has to be a completely secure process that guarantees that at least two parties can execute the contract without needing to trust each other, or even knowing each other.

Smart Contracts What Are They How Do They Work And What Do They Contribute (Part II)

Contracts use Bitcoin’s decentralized system to enforce financial agreements without reliance on outside agents, such as court systems, reducing the risk of dealing with unknown entities in financial transactions.

There are several steps to creating secure smart contracts. Let’s exemplify the case of making secure deposits on any web page that accepts bitcoins.

Nobody likes to lose their money, right?

  1. The user and the website send each other a newly generated public key.
  2. The user creates the first transaction without transmitting it by putting for example 5 BTC in an output that requires both the user and the website to sign it.
  3. User sends the hash of the first transaction to the website.
  4. The portal creates a second transaction corresponding to the contract.

    In this second transaction, the first one is spent and returned to the user through the address provided in the first step, but as the first transaction required two signatures (user and web page) this operation would still not be complete.

    This is where a new parameter takes on importance: nLockTime. This can be added in a bitcoin transaction by setting a future date of e.g. 6 months.

    Before this date, those funds could not be incorporated into any transaction. The Sequence Number of the input is also set to 0.
  5. Finally, the unsigned transaction would be completely returned to the user. This would check that everything is correct and that the coins would be returned to the user’s possession.

    However, after the 6 months stipulated with nLockTime. Having the Sequence Number at 0, this contract could be modified in the future if both parties consider it convenient. But of course… if the administrators of the website disappear, how could the user recover the funds?
  6. Keep in mind that the input script (instructions recorded in each transaction) has not yet finished. The space reserved for the user’s signature still consists of a set of zeros after the portal will create the second transaction. Now only the user’s signature would be missing on that contract.
  7. From here, after the 6 months that were delimited, both the first and the second transaction would be transmitted and the 5 BTCs of the first transaction would be returned to the user in question.
Smart Contracts What Are They How Do They Work And What Do They Contribute (Part II)

All these characteristics not only allow new and interesting financial tools to be built on the Bitcoin blockchain. But also, as each smart contract is made up of people or machines, the possibilities of innovation for the Internet of Things, Insurtech, Logistics, Administration are so wide that it is likely that the first killer apps or revolutionary applications in these fields will begin to emerge very soon.

This post continues at Smart Contracts: What Are They, How Do They Work And What Do They Contribute? (Part III)

For further information you can visit:

Maybe you are also looking for: