Smart Contracts: What Are They, How Do They Work and What Do They Offer?

A smart contract is a special type of instructions stored on the blockchain. It also has the ability to self-execute actions according to a set of pre-programmed parameters. All of this in an immutable, transparent and completely secure way.

In recent years, following the creation of Bitcoin and the launch of its first version in 2009, many interesting projects have emerged, bringing new ideas and decentralized solutions to many of the centralized processes or applications we all use today. So let us ask you: have you heard of smart contracts?

Well, this time we will take an in-depth look at these mechanisms. Smart contracts aim to eliminate intermediaries in order to simplify processes and, in doing so, save costs for the consumer. Most of the information related to smart contracts is only available in English. That is why, at Bit2Me, after a first chapter in our guide dedicated to introducing smart contracts, we don’t want you to be left with any doubts or without fully understanding what smart contracts are and what their potential is.

That is why we will discuss the origin of smart contracts. We will then analyze the current situation, and thirdly we will present some of the most important alternative projects to Bitcoin. Finally, we will describe the future of this technology.

What is a smart contract?

To understand a smart contract, we must first recall what a contract means. A contract is nothing more than an agreement between two or more parties, a framework defining what can be done, how it can be done, and what happens if something is not done. In other words, a set of ground rules that allow all the parties who accept it to understand what the interaction they are going to carry out will consist of.

Until now, contracts have been verbal agreements or expensive written documents. These documents are subject to territorial laws and jurisdictions, and sometimes require notaries. That means more costs, more time and more third parties involved in the process. As a result, they are not accessible to everyone. And that’s not the worst of it: the contents of contracts can be subject to interpretation. Hold on tight!

A smart contract, on the other hand, is capable of executing and enforcing itself, autonomously and automatically, without intermediaries or mediators. They avoid the burden of interpretation because they are not verbal or written in the languages we speak. Smart contracts are “scripts” (computer code) written in programming languages. This means that the terms of the contract are pure statements and commands in the code that makes it up.

Furthermore, a smart contract can be created and called by individuals and/or legal entities. But also by machines or other programs that operate autonomously. A smart contract is valid without depending on authorities. This is due to its nature: it is code visible to everyone and cannot be changed because it exists on blockchain technology. This gives it a decentralized, immutable and transparent character.

Smart contracts

Smart contracts and their enormous potential

With the above, you have surely been able to see the enormous potential these smart contracts hold. It is important to highlight that, because they are distributed across thousands of computers, no large company has custody of them, which eliminates bureaucracy, censorship and the large costs and delays inherent in this process, which, incidentally, is how custody has worked until now.

If we combine the principles of a smart contract with the creativity of many developers around the planet, the result is never-before-seen possibilities, accessible to everyone and at costs that are almost free. Ecosystems without authoritarian figures bending their members to their will. We are talking about a fairer world.

Imagine a self-driving Tesla, bought by a group, capable of managing itself and renting itself out on its own. All without an Uber-type company behind it taking 10%. Of that we can say: welcome to the world of smart contracts.

The first smart contracts

The first public record of smart contracts comes from Nick Szabo, the jurist and cryptographer who publicly mentioned the term in a paper in 1995. Two years later, in 1997, he developed a much more detailed paper explaining Smart Contracts.

Unfortunately, although he defined the theory, it was impossible to make it a reality with the existing technological infrastructure. For smart contracts to be executed, programmable transactions and a digitally native financial system that recognizes them must exist.

Precisely what Szabo described as non-existent in 1995 would become a reality in 2009 (almost 15 years later) with the emergence of Bitcoin and its technology, the chain of blocks (blockchain).

Bitcoin and smart contracts

Bitcoin has some smart contracts already created that run by default and transparently to the user. When we talk about distribution contracts, we are referring to one of Bitcoin’s use cases for forming agreements between people via the blockchain. Among all its advantages, Bitcoin allows logic to be added to money, something unique to this type of money: it is programmable money. This logic applied to money allows us to solve common problems we may encounter today, while increasing the level of trust throughout the entire automated process in which the interaction takes place.

Some examples of smart contracts on Bitcoin

By way of example, new products or applications could be developed, such as:

  • Distributed markets that would allow P2P contracts and trading on markets with Bitcoin, positioning it as a full competitor to the current financial system.
  • Property such as cars, phones, houses or non-physical items controlled through the blockchain make up what is known as smart property. The use of contracts and smart property allows for a much higher level of trust, reducing fraud and third-party mediation fees, and takes transactions to a new level.
  • Automation of inheritances by setting the allocation of assets after death. As soon as the death occurred, the contract would come into force and execute, in this case distributing the funds to the address set in the contract.
  • Insurance: accident reports, company payments for repairs, reduction of accident fraud…

The fact is that smart contracts rely on Bitcoin’s technology to exist, which is great for Bitcoin, as it is drawing much more attention and bringing hundreds of thousands of new users into its ecosystem. In fact, it is not hard to find statements such as: “Smart contracts are Bitcoin’s killer APP”.

This logic that can be applied to Bitcoin transactions is implemented through the use of an entire language of its own, allowing the blockchain itself to determine what to do based on the programmed instructions. This means we have a transaction with instructions in a distributed and immutable form, providing complete security with no room for interpretation.

A Smart Contract is not what you think

Nowadays everything is controlled by computer systems. Everything interacts with them. In application development, it is normal for programmers to create a series of “doors” to their application (called APIs). These doors allow other programmers to enter your application to create or obtain information. Almost every website or program has its own. In other words, a protocol is defined, a contract, a known way of calling the application with a data structure. It is through this door that we will get a response, but with a predictable data structure. In this case, so that communication, and with it the programs, do not fail.

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

People need predictable, transparent and incorruptible environments. Smart contracts are similar pieces of code, that is, they have ways of being called and returning responses, they have a contract, but they are also immutable because they are distributed across thousands of nodes that cannot alter their content. That way you get a program that will always act the same way without relying on the goodwill of that third party. Something that is necessary for almost any use case. Smart Contracts are programs in the cloud that always act the same, and they allow information to be stored that cannot be treacherously modified. They are the most secure programs ever created by humanity and only fail when they are poorly programmed.

Poorly programmed Smart Contracts

Smart Contracts are capable of managing digital assets with a certain economic value, so in reality Smart Contracts can manage money. This requires special emphasis on programming them correctly, as the Smart Contract could have security flaws or bugs that cause execution errors or unexpected behavior.

When this happens, the money can be lost completely. It has happened quite a few times, and without sufficient Know How it will keep happening 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 created on Bitcoin?

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

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

Smart contract generation process

There are several steps to creating secure smart contracts. Let’s illustrate with the case of making secure deposits on any website that accepts bitcoins. Nobody likes losing their money, right?

Taken together, all these features not only make it possible to build new and interesting financial tools on the Bitcoin blockchain but, since each smart contract is formed by people or machines, the possibilities for innovation in the fields of Internet of Things, Insurtech, Logistics, Administration are so broad that the first killer apps or revolutionary applications in these fields are likely to start appearing very soon.

Steps to generate a smart contract

  • The user and the website send each other a newly generated public key.
  • Next, the user creates the first transaction without broadcasting it, placing, for example, 5 BTC in an output that requires both the user and the website to sign it.
  • The user sends the hash of the first transaction to the website.
  • The portal creates a second transaction corresponding to the contract. This second transaction spends the first one and returns it to the user via the address provided in the first step. But since the first transaction required two signatures (user and website), this operation would not yet be complete. This is where a new parameter becomes important: nLockTime. It can be added to a bitcoin transaction by setting a future date of, for example, 6 months. Before this date, those funds could not be included in any transaction. The Sequence Number of the input is also set to 0.
  • Finally, the not fully signed transaction would be returned to the user. The user would check that everything is correct and that the coins would return to their possession. That said, only after the 6 months stipulated with nLockTime. With the Sequence Number at 0, this contract could be modified in the future if both parties deem it appropriate. But of course… If the website’s administrators disappear, how could the user recover the funds?
  • Bear in mind that the input script (instructions recorded in each transaction) has not yet been completed. The space reserved for the user’s signature is still made up of a set of zeros after the portal creates the second transaction. Now all that would be missing is the user’s signature on that contract.
  • From here, after the 6 months set, both the first and second transactions would be broadcast, and the 5 BTC from the first transaction would be returned to the user in question.

Taken together, all these features not only make it possible to build new and interesting financial tools on the Bitcoin blockchain but, since each smart contract is formed by people or machines, the possibilities for innovation in the fields of Internet of Things, Insurtech, Logistics, Administration are so broad that the first killer apps or revolutionary applications in these fields are likely to start appearing very soon.

Current state of smart contracts on Bitcoin

Let’s not forget that when we talk about Bitcoin we are talking about a new, dynamic ecosystem in constant growth, but also, as mentioned earlier, about smart contracts. New implementations of smart contracts on Bitcoin are gradually appearing, but they are already applied in some features that will probably sound familiar, such as multisignature wallets, in which two or more parties must approve a transaction before the funds are released.

Along with multisignature addresses, double deposits are one of the features that facilitate the proper functioning of smart contracts of this type. It was introduced by BitHalo and is innovative because it eliminates the need for a third party to act as arbitrator. Basically, the parties, say a buyer and a seller, BOTH make a deposit transaction linked to a smart contract. The contract program has a set time before it expires. If the people involved in the agreement do not resolve it within that period, the deposit funds will be burned, that is, sent to an address for which nobody knows the private key, which forces the parties to make every effort to find solutions.

Although Bitcoin has a programming language for adding logic, some believe it sometimes falls short. This is why solutions have been created that take smart contracts to new horizons, with Turing-complete languages. Let’s look at some of these new options.

What is Counterparty?

Counterparty was born in 2014. It is an open source platform on which peer-to-peer applications can be developed. They are initially geared towards the financial sector, on the Bitcoin blockchain: the protocol currently implements and supports asset creation, the issuance of bonds for those assets, dividend payments, asset trading using a decentralized market, binary bets, and contracts for difference (CFDs).  Its open-source protocol, in addition to allowing the creation and trading of digital assets, also allows smart contracts to be written, making it possible to transform many real-world actions into code that works automatically without intermediaries and is fault-tolerant.

counter party

Counterparty also has a token (or cryptocurrency) called XCP. It is used to offer some possibilities that are not technically possible for the moment using BTC (bitcoins).

Although interest in more powerful smart contracts has been announced since the start of the project, it is only recently that it has been confirmed that Ethereum’s EVM will finally be introduced into Counterparty, which will allow smart contracts identical to Ethereum’s to be executed on the Bitcoin network, enabling a huge diversity of applications such as Decentralized Autonomous Organizations (DAOs),  identity systems, and consensus-based voting systems, among others. As of this chapter of the Bitcoin Guide, the Ethereum Virtual Machine (EVM) is operational only on the Counterparty testnet. How were they able to reuse the free-software EVM? Counterparty uses the same smart contract programming language, called Solidity.

According to Trevor Altpeter, director of the Counterparty Foundation, the EVM will now be able to do everything Ethereum does, only on the Bitcoin blockchain.

Counterparty’s coin, XCP, is used to execute the contracts.

What is RootStock?

Rootstock, known as the Ethereum of Bitcoin,  is another platform trying to bring Turing-complete smart contracts to Bitcoin, thus leveraging Bitcoin’s network effect and security without having to create something from scratch (it has been reported that the platform will also be compatible with Ethereum). It is an open source platform for creating smart contracts that will reward miners who actively participate. Its main goal is to add value and functionality to the Bitcoin ecosystem by enabling secure smart contracts on the network, adding options for instant payments and greater scalability. To do so, RootStock uses sidechains, connected to the Bitcoin chain, and its token (Roots), which will only be used to be exchanged for bitcoins.

Despite being relatively new, Rootstock has already raised $1 million in its latest funding round from Digital Currency Group (DGC).

Nick Szabo himself said on his Twitter: “the best of Bitcoin (currency and system liquidity) + the best of Ethereum (smart contract programming ecosystem)”

RooStock or RSK

Platforms innovating with smart contracts

Not all projects revolve solely around the Bitcoin network, and there are already several alternatives. Initially, Ethereum stands out and, during 2016, Lisk. Let’s go into a bit of detail to describe each of them.

Smart contracts on Ethereum

Ethereum is one of the most famous projects in the smart contracts sector. It is a distributed computing platform based on a public blockchain like Bitcoin, which also allows P2P smart contracts (between nodes, without central servers) to be executed on a decentralized virtual machine called the Ethereum Virtual Machine (EVM).

It is based on all of Bitcoin’s theory in terms of being distributed, having its own cryptocurrency, miners and even its own blockchain, among other things, but unlike Bitcoin, Ethereum has created a much more extensive  programming language interpreter (Turing complete), allowing much more complex logic to be added within the blockchain. In other words, it could be likened to a distributed computer, which uses its cryptocurrency (ether) as the “gas” the contract needs for miners to execute it. So now, with Ethereum, contracts are programs with many more features and possibilities. However, to achieve this, and this is something many people criticize them for, they had to create a whole new network from scratch, giving up the Bitcoin network (the most powerful in the world).

You can browse, study or copy an extensive list of decentralized applications built on Ethereum at State of Dapps. Want to learn more about Ethereum? Below is an infographic in Spanish that may interest you.

ethereum smart contracts

Smart contracts on Lisk

Lisk is a platform for creating and executing smart contracts in a decentralized way. It was launched in 2016, presenting itself as one of the best options for developing secure and fast smart contracts thanks to the use of Javascript (the most widely used programming language) as the language for creating smart contracts, thus becoming an alternative to Ethereum, where the programming language used is Solidity.

After a successful presale of the coin the contract will need to operate (LSK), which raised more than 14,000 bitcoins, Lisk is still at a very early stage but already has several DAPP concepts being worked on, such as ‘proof of existance’ or a social network for artists called Discovr.

Due to the enormous programming flexibility of smart contracts and blockchain technology, it is possible for them to interact with the physical or real world through different interfaces. One of the most widely used today are cryptographic oracles.

Oracles

We cannot forget oracles. One of the most important features enabling a smart contract to interact with the real world are so-called oracles. Oracles are tools that allow the internal states of a smart contract to be updated using external information (usually obtained through APIs), for example obtaining the price of a stock or currency, or whether a package has been shipped by the courier company.

To explain it better, let’s imagine a smart contract for a football bet, Madrid – Barça. The contract would use an official source as its oracle, for example the Spanish football League’s website. Depending on the result, it releases the funds to the winner. Who needs a bookmaker that keeps a percentage of your money? This would be a commission-free, secure bookmaker without intermediaries (decentralized).

Oracles also work autonomously. However, bear in mind that the source used by the oracle is a third party that must be trusted, and that could be corrupted by its owner, hacked, or its server could simply fail, which has negative implications: we are CENTRALIZING trust, something contrary to the blockchain philosophy. Fortunately, there are already projects developing solutions to this problem: Orisi and Oraclize. In essence, they combine the results of all the information providers specified, and the decision is determined based on what the majority says. In other words, it decentralizes how the result is obtained, which is great.

A world dominated by Smart Contracts

Can you imagine that, in a few decades, the politicians of the day spend 4 years preparing the smart contract in which they define how money will be distributed and the actions they will take?

That way, society would only need to vote (also through blockchain technology, of course) on the smart contract it wants to use during that new period.

This would guarantee that what was voted on is executed, with full transparency and tracking of spending. Something urgently needed, given the times we live in…

Perhaps this is what elections will look like before long.

This is only the beginning

And this, for now, concludes our tour of this fascinating branch of blockchain technology. As you have seen, some platforms compete for similar solutions in an environment of constant creativity, but all with the same goal: eliminating friction points in the traditional system to save people time and money. Just a few years after Bitcoin’s first steps, only a few will bother to read this text (consider yourself lucky), even fewer will dig deeper into it, and very, very few will decide to step forward and take action. Everything is yet to be done, there are many problems, many things that don’t work well. Isn’t this a unique opportunity to do something?

With a little imagination, one can glimpse a tomorrow without large multinationals monopolizing sectors, but rather transparent code that lives forever on a blockchain and is capable of orchestrating the provision of all kinds of services at no cost (or at a ridiculous cost compared to today’s). We are heading towards a global but distributed world, without intermediaries or large companies organizing everything at will from the shadows. A global world with global services, where smart contracts have every chance of being the seed of unprecedented change: more than 25 billion devices were estimated to be connected to the Internet in 2017, all of them capable of executing smart contracts with each other on a daily basis.

This and much more is what smart contracts translate into. Now all that remains is to create simple interfaces that harness this potential in specific cases. Are you ready for it?

The image has an empty ALT attribute; its file name is bit2me-white_bg-blue.png