A Smart Contract is an agreement between parties which contains a set of instructions in the form of code and that is executed in the blockchain, so that it is stored in a public database and cannot be modified. Transactions in a smart contract are processed by the blockchain, which means that they can be sent automatically without any intermediary. Transactions only occur when the conditions of the prearranged agreement are met: there is no third party, so there are no trust issues.

Let’s imagine that we want to rent a car to spend a week on vacation. Usually, we would pay the cost for the entire week in advance and return the car within a prearranged schedule. Instead, with the use of Smart Contracts (and through the Internet of Things) the car itself can calculate the time of use and the kilometers traveled, so that we are charged cent by cent in real time, having the possibility of returning it before the established date and end the contract.

The main advantage of making this transaction through a Smart Contract is that the contract is transparent (visible to everyone in the blockchain), immutable (once stored in the blockchain, it can no longer be modified) and impartial (the code is objective). On the other hand, one of the disadventages is that, in the event that a Smart Contract presents vulnerabilities (not necessarily intentional), the security of all money and data that have been transferred in the contract can be put at risk.

What are Smart Contracts used for?

There is a wide range of opportunities in the implementation of Smart Contracts, since they can be used for any type of transaction, it does not necessarily have to be a financial one.

Medicine: EncrypGen has developed an app that uses Smart Contracts to securely transfer patient data to researchers, without allowing third party access. If researchers want to use patient data, they have to pay and the patient must choose whether or not to sell their data.

Insurance: the French insurer AXA has already started testing Smart Contracts to insure plane flights. In case the plane arrives on time, the passenger pays the cost of the insurance. In the event that the plane arrives late, the Smart Contract claims the money from the insurer and pays it to the passenger, so it automates the claim process.

Digital identity and voting: some new projects have recently emerged seeking to validate the identity of a voter and register their vote. This information could be used to start actions after all voting has ceased. As the blocks within a blockchain cannot be alterable once registered, fraud would not be possible and this would prevent many electoral fraud issues.

Supply chains: using Smart Contracts for inventories and order management seems to be a reality that is getting closer every day. The implementation of the Internet of Things could make a factory’s own machines place an order for materials when they detect they are running low.

Challenges of Smart Contracts

One of the biggest challenges that exists is the need to adjust Smart Contracts to a legal framework that is different in each country (it can even be different for each region within a country). Transferring the legal language to the world of programming and proving the legal validity of a contract which does not have intermediaries seems to be quite difficult for now. However, the legal landscape is beginning to adapt to these new ways of doing business.

Another key element in the future of Smart Contracts will be the legibility and accessibility of contracts. Currently, only expert programmers are able to understand the code (and therefore the terms of the contract). Eventually, everything indicates that forms adapted to natural language will emerge to read and understand the operation of the contract. Also, the creation of Smart Contracts is being simplified thanks to new platforms in which, without programming and with a couple of clicks, we can generate and put into operation our Smart Contract.

Finally, for Smart Contracts to work properly, we need to provide them reliable data of what happens in the real world. Keep in mind that, in a blockchain, the only known world is what is stored in the blocks (to make it easier to understand, the blockchain is “isolated”). Those who are in charge of providing this data to the Smart Contracts are the so-called oracles.

Oracles allow us to monitor Internet activity in order to transfer this data to the blockchain. Its functions are so extensive that they can range from verifying results of sporting events, locating objects anywhere in the world with the help of geolocation, or providing stock prices in real time. Projects such as Chainlink, Band Protocol or API3 aim to improve the interoperability of blockchains with the real world thanks to these oracles.

How to program a Smart Contract?

The most common programming language for programming Smart Contracts is Solidity, a high-level language which has a certain resemblance to JavaScript and that allows us to program in the Ethereum Virtual Machine (EVM). The EVM is used not only in the Ethereum blockchain, but also in some others that are based on the same technology, such as Binance Smart Chain, Polygon, Celo, TRON, RSK and many more. The programming environment (IDE) that is normally used to publish Smart Contracts is Remix (you can find a tutorial with the first steps here).

On the other hand, Rust has been recently used to program Smart Contracts in blockchains such as Solana, Terra, Polkadot, NEAR Protocol. This programming language introduces interesting changes and generates some debate in the programming community about which language is more optimal when developing projects on the blockchain. Even so, Solidity is still the most relevant and the most used by programmers.