What is a smart contract?
To understand a smart contract, we must first remember what the meaning of contract is. A contract is nothing more than an agreement between two or more parties, a situation in which you define what you can do, how you can do it, what happens if something is not respected . In other words, rules of the game that allow all parties who accept it to understand what the interaction they intend to put in place will consist of.
Until now, contracts have been verbal documents or expensive written documents. These documents are subject to local laws and jurisdictions and sometimes require notaries. That is, more cost, more time and third parties involved in the process. Because of this, they are not accessible to everyone. And the worst is yet to come: the content of each contract may be subject to interpretation. Brace yourself!
In contrast, a smart contract is able to realize and enforce itself autonomously and automatically, without intermediaries or brokers. Because it is neither verbal nor written in any of the languages we speak, it avoids the problem of personal interpretation. Smart contracts are “scripts” (computer code) written in programming languages. This means that the terms of the contract are pure decisions and commands within the code that makes them up.
On the other hand, a smart contract can be created and named 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 a code that is visible to everyone, which cannot be modified as it is on blockchain technology. This gives it a decentralized, immutable and transparent character.
Smart contracts and their huge potential
Based on the above, surely you have been able to imagine the huge potential possessed by these smart contracts. It is important to note that since it is distributed among thousands of computers, it is impossible for a large company to control and guard them, which eliminates the bureaucracy, censorship and large costs/time involved in this process.
If we combine the principles of a smart contract with the creativity of many entrepreneurs on the planet, the result will be unprecedented possibilities, accessible to all and at costs that border on free. Ecosystems without authority figures that subject the various members to their will. We’re talking about a more just world.
Imagine a self-driving Tesla car, purchased as a group and able to self-manage and rent itself. All this without a company like Uber taking 10%. That said, we can say:Welcome to the world of smart contracts.
The first smart contracts
The first time smart contracts became known is through Nick Szabo , the jurist and cryptographer Nick Szabo who mentioned them publicly in a 1995 paper. Two years later, in 1997, he completed a much more detailed paper to better explain what smart contracts were.
Unfortunately, while defining the theory, it was impossible to make it a reality with the technological infrastructure of the day. In order for smart contracts to be used, there must be programmable transactions and a financial system that recognizes them, digitally native.
Precisely, what Szabo called non-existent in 1995, became a reality in 2009 (almost 15 years later) with the emergence of Bitcoin and its technology, the blockchain.
Bitcoin and smart contracts
Bitcoin has some already created smart contracts that are executed automatically and transparently to the user. When we talk about distribution contracts, we are referring to one of Bitcoin’s use cases for creating agreements between people via the blockchain. Bitcoin, among all its advantages, allows us to add logic to money, something unique: it is programmable money. This logic applied to money allows us to solve common problems that we may encounter today, but increasing the level of trust throughout the automated process in which the interaction takes place.
Some examples of smart contracts in Bitcoin
As an example, new products or applications could be developed such as:
Distributed markets allowing the use of P2P contracts y trading in markets with Bitcoin proposing itself as a complete rival to the current financial system.
Properties such as cars, phones, houses or non-physical items controlled through blockchain are part of the so-called smart properties. Through the use of smart contracts and smart property, the level of trust would be much higher, fraud, third party brokerage fees would be reduced, and it would be possible to take transactions to a new level.
Automation in case of inheritance that establishes the distribution of assets after death. As soon as death occurs, the contract would go into effect and be put in place, in this case distributing the funds to the parties named in the contract.
Insurance: accident reporting, business payments for repairs, reducing accident fraud …
The fact that smart contracts use Bitcoin technology to “exist” represents something fantastic for Bitcoin as it is making it receive much more visibility by attracting hundreds of thousands of new users to its ecosystem. In fact, it’s not hard to find statements like: smart contracts are Bitcoin’s killer APP “.
This logic, which can be applied to Bitcoin transactions, is executed through the use of its own type of language, allowing the blockchain itself to determine what to do based on the programmed directions. This means that we have a transaction with instructions defined in a distributed and immutable way. Which offers complete security and without giving room for interpretation.
A smart contract is not what you think
Today, everything is controlled by computer systems. Everything interacts with them. In application development, it’s common for programmers to create a series of “ports” to their applications (called APIs). These ports allow other programmers to access an application to create or obtain information. Almost every website or program has their own. That is, a protocol is defined, a contract, a known way to call the application and with a data structure. It is through this port that a response is obtained, but with a predictable data structure. In this case, so that the communication does not fail and, with it, the programs.
But this contract is not guaranteed. The application server is controlled by someone who has the ability to make the program run differently from one day to the next. It is centralized and can change at the decision of that third party. It is not “smart.”
People need predictable, transparent and incorruptible frameworks. Smart contracts are similar pieces of code, i.e. there are various ways to call them and get answers, they have a contract, but they are also immutable because they are distributed across thousands of nodes that cannot alter their content. This way you get a program that will always act the same way, without requiring the goodwill of third parties – a necessary thing to use in various contexts. Smart Contracts are cloud programs that will always act the same way and allow you to store information that can’t be treacherously changed. They are the most secure programs ever created in humanity and only fail when they are poorly programmed.
Poorly programmed smart contracts
Smart Contracts are able to manage digital assets subject to a certain economic value; therefore, they can actually manage money. This requires special emphasis on their proper programming, as a Smart Contract could have security holes or issues that would generate execution errors or unexpected behavior.
When this happens, money could be completely lost. Not a few times this has occurred and without the necessary Know How it will continue to happen to several initiatives.
Unfortunately, this happens frequently, so it is really important to pay special attention when developing and testing these software.
How do you create a smart contract in Bitcoin?
For this to be possible, there has to be a completely secure process that ensures that at least two parties can enter into the contract without having 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 court systems, reducing the risk of dealing with unknown entities in financial transactions.
Process of creating a smart contract
There are several steps to creating secure smart contracts. Take, for example, the case of wanting to make secure deposits on any website that accepts bitcoin. No one likes to lose their money, right?
Together all these features not only allow the construction of new and interesting financial instruments on Bitcoin’s blockchain but, since each smart contract is composed of people or machines, the possibilities for innovation in the fields of Internet of Things, Insurtech, Logistics, Administration are so wide that it is likely that very soon the first killer apps or revolutionary applications of these sectors will be created.
Steps to create a smart contract
The user and the webpage exchange a newly created public key.
Then the user creates the first transaction without transmitting it, for example by putting 5 BTC into an output, which must be signed by both the user and the website.
The user sends the hash of the first transaction to the web page.
The portal creates a second transaction corresponding to the contract. In this second transaction, the first transaction is spent and returned to the user via the address provided in the first step. But since the first transaction requires two signatures (user and web page) this transaction is not yet completed. This is where a new parameter comes into play: nLockTime. This can be added in a bitcoin transaction by setting a future date of say 6 months. Before this date, these funds cannot be incorporated into any other transaction. The Sequence Number of the input is set to 0.
Finally, the entire unsigned transaction is returned to the user. This checks that everything is correct and the coins return to his possession. Obviously, after the 6 months set with nLockTime. Having the Sequence Number at 0, this contract could be modified in the future if both parties find it convenient. But of course … If the site administrators disappear, how would the user recover the funds?
Keep in mind that the input script (instructions recorded in each transaction) is not yet finished. The space reserved for the user’s signature still consists of a set of zeros, after the portal creates the second transaction. At this point, only the user’s signature is missing from the contract.
From here, after the 6 months that have been determined have passed, both the first and second transactions will be transferred and the 5 BTC from the first transaction will be returned to the user in question.
Together all these features not only allow the construction of new and interesting financial instruments on the Bitcoin blockchain but, since each smart contract is composed of people or machines, the possibilities of innovation in the fields of Internet of Things, Insurtech, Logistics, Administration are so wide that it is likely that very soon the first killer apps or revolutionary applications of these sectors will be created.
Current status of smart contracts on Bitcoin
Let’s not forget that when we talk about Bitcoin we are referring to a new dynamic ecosystem that is constantly growing but, as we indicated earlier, also to smart contracts. Little by little, new updates related to smart contracts on Bitcoin are being introduced but, currently, there are already some features that probably sound familiar to you such as multi-signature coin purses, where two or more parties have to approve the completion of a transaction before the funds are released.
Along with multi-signature addresses, dual deposits are one of the features that facilitate the proper functioning of smart contracts of this type. This feature was introduced by BitHalo and is innovative in that it eliminates the need for a third party to act as an arbitrator. Basically it provides that the parties, for example a buyer and a seller, perform BOTH a payment connected to a smart contract. The contract program is valid for a certain period before it expires. If the people involved in the deal don’t complete it within that time frame, the funds from the deposits will be burned, i.e. they will be sent to an address whose private key no one knows, which forces the parties to make a huge effort in finding solutions.
Although Bitcoin has a programming language to add logic, there are those who feel that it sometimes falls short. This is why solutions have been created that take smart contracts to new horizons, with full Turing language. Let’s get to know some of these new options.
What is Counterparty?
Counterparty was born in 2014. It is an open source platform where peer to peer applications can be developed. Initially, these applications were oriented to the financial sector, on the Bitcoin blockchain: currently, the protocol implements and supports the creation of assets, the issuance of bonds from these assets, the payment of dividends, the trading of assets using a decentralized market, binary bets and contracts for difference (CFDs). Its open source protocol, in addition to allowing you to create and trade digital assets, also allows you to write smart contracts, enabling you to turn many of the actions in the real world into code that works automatically without the need for intermediaries and is resistant to failure.
Counterparty also features a token (or cryptocurrency) called XCP. This is used to offer some possibilities that, at the moment, are not technically possible using BTC (bitcoin).
Although interest in more powerful smart contracts has been announced since the beginning of the project, it has only recently been confirmed that Ethereum’s EVM will finally be introduced within Counterparty,, which will allow for the execution of smart contracts identical to Ethereum’s but on the Bitcoin network, enabling a huge diversity of applications such as Decentralized Autonomous Organizations (DAOs), identity systems, consensus-based voting systems, among others. As of this chapter of the Bitcoin Guide, the Ethereum Virtual Machine (EVM) is only operational on the Counterparty testnet. How is it possible that they could reuse the free EVM software? Counterparty uses the same smart contract programming language, called Solidity.
According to Trevor Altpeter, director of the Counterparty Foundation, EVM will now be able to do everything Ethereum does, only in the Bitcoin blockchain.
Counterparty’s currency, XCP, is used to execute the contracts.
What is RootStock?
RootStock (RSK), known as the Ethereum of Bitcoin, is another platform that seeks to bring smart contracts to Bitcoin to leverage the network effect and security of Bitcoin without the need 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 actively participating miners. Its main goal is to add value and functionality to the Bitcoin ecosystem by activating secure smart contracts on the network, adding options for instant payments and greater scalability. To do this, RootStock uses side-chains (sidechains), which are connected to the Bitcoin blockchain, and its token (Roots), which will only be used to be exchanged for bitcoin.
Despite being relatively new, Rootstock has already secured $1 million from Digital Currency Group (DGC) during its latest funding round.
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 exclusively around the Bitcoin network and there are already several alternatives. First of all Ethereum and, during 2016, also Lisk. Let’s go into a bit of detail to describe both.
Smart Contract on Ethereum
Ethereum, which is one of the most famous projects in the smart contract industry, is a distributed computing platform based on a public blockchain like Bitcoin and also allows P2P smart contracts (between nodes, without central servers) to be applied in a decentralized virtual machine called Ethereum Virtual Machine (EVM).
It builds on the entire theory of Bitcoin in terms of being distributed, having its own cryptocurrency, miner and even its own blockchain among other things but unlike Bitcoin, Etherum has created a much more extensive programming language interpreter (full Turing), allowing for much more complex logic to be added within the blockchain. In other words, it could be compared to a distributed computer, which uses its cryptocurrency (the ether) as the “gasoline” the contract needs in order for the miners to enforce it. That is, now with Ethereum, contracts are programs with much more functionality and possibilities. Although for this (and this is something that many people criticize) they had to create a completely 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 developed on Ethereum on State of Dapps. Want to learn more about Ethereum? Here’s an infographic in Spanish that might interest you.
ehtereum of smart contracts
Smart contracts on Lisk
After a successful pre-sale of the currency, which will need the contract to work (the LSK), during which more than 14,000 bitcoins were collected, Lisk is still in an early stage but already has several DAPP concepts that are being worked on, such as the ‘proof of existence’ or a social network for artists called Discovr.
How much do you know, Kryptonite?
Can smart contracts interact with the physical world?
Because of the enormous programming flexibility of smart contracts and blockchain technology, it is possible to allow them to interact with the physical or real world through different interfaces. One of the most widely used today are cryptographic oracles.
We cannot forget about oracles. One of the most important features, so that a smart contract can interact with the real world, are the so-called oracles. The oracles are tools that allow to modify the internal states of a smart contract through external information (usually obtained through APIs), for example obtaining the price of a stock or a currency or if a package has been sent by the transport company.
To explain it better, let’s imagine a smart contract on a soccer bet, Madrid – Barça. The contract would use an official source as an oracle, such as the Spanish soccer league website. Depending on the outcome, funds are released to the winner. Who needs a betting center that keeps a percentage of your money? The oracle would become a commission-free, secure and intermediary-free (decentralized) betting center.
Oracles also function independently. However, it must be kept in mind that the source used by the oracle is a third party that must be trusted and could be corrupted by its owner, could be cracked or its server could simply fail; something bad could happen in short: we are CENTRALIZING trust, contrary to the blockchain philosophy. Fortunately, there are already some projects that are developing solutions for this problem, such as Orisi and Oraclize. Basically, these programs put together the results of all the information providers that are indicated and make a decision based on what the majority says. That is, it decentralizes the obtaining of the result, something brilliant.
A world dominated by Smart Contracts
Can you imagine that, in a few decades, the politicians of the moment will present a smart contract as a 4-year program, in which they will define how the money will be distributed and the shares they will have?
This way, society would only have to vote (through blockchain technology, of course) on the smart contract they want to use during that new period.
This would ensure that people’s votes are respected, that there is total transparency, and that expenses are tracked. Something that, given the current times, would already be urgent …
Before long, elections could also be held in this way.
This is just the beginning
It stops here, for now, our journey through this exciting branch of blockchain technology. As we could see, a number of platforms are competing to find similar solutions in an environment of constant creativity and all with the same goal: to eliminate the critical points of the traditional system to save people time and money. A few years after Bitcoin’s first steps, only a few will bother to read this text (feel lucky), even fewer will delve into it and very few will decide to step up and take action. Everything still has to be done, there are many problems, many things that are not working well: isn’t this a unique opportunity to do something?
As soon as you start imagining, you glimpse a tomorrow without big multinationals monopolizing sectors, but transparent codes that live indefinitely on a blockchain and are able to orchestrate the delivery of all kinds of services at zero cost (or a ridiculous cost compared to today). We are moving towards a global but distributed world, without intermediaries or large corporations who, in the shadows, organize everything to their liking. A global world with global services, where smart contracts have all the credentials to be the seed of an unprecedented change: there are estimated to be over 25 billion devices connected to the Internet in 2017, all capable of applying and sharing smart contracts with each other every day.
This and much more represent smart contracts. Now we just need to create simple interaction points that leverage this potential in specific cases. Are you ready?