What Are Smart Contracts?

Last updated on 11/29/2018

A smart contract is a piece of software that automatically enforces an agreement between two or more parties when certain conditions are met. The agreement is enforced by exchanging resources between the parties on a blockchain.

A key feature of a smart contract is that it makes it possible to enforce a contract without relying on oversight or intervention by a third party. Instead, smart contracts are executed in a decentralized fashion in a way that makes cheating or fraud virtually impossible.

Smart Contract Example

As an example of a smart contract, consider a situation in which Company A agrees to pay Company B a predetermined amount of bitcoin if Company B delivers a given item to Company A by a specified date. A smart contract to govern this exchange would represent this agreement in the form of computer code.

If the conditions of the agreement are met — meaning that Company B supplied the specified item by the agreed-upon date — the amount of bitcoin that Company A has agreed to pay will be automatically transferred from Company A’s digital wallet to Company B’s wallet by the smart contract.

In this scenario, Company B enjoys the advantage of being paid trustlessly. Company A can’t receive the item without paying for it because the contract would not execute if Company A backs out of its side of the agreement. Meanwhile, Company A benefits from the smart contract because the contract creates an immutable record showing that Company A issued payment as agreed. Company B cannot claim that it was not paid in a timely fashion.

Smart Contract Challenges

Although smart contracts are innovative in that they make it possible to enforce agreements without centralized control of a contract, they pose challenges that developers must consider in order to design the most effective smart contracts.

One smart contract challenge is that the conditions associated with a smart contract sometimes rely on real-world information. In the example above, a smart contract might not be able to detect on its own whether Company B delivered the item it promised to Company A. However, with the assistance of an oracle, this issue could be overcome. An IoT sensor could report to the smart contract whether the item was delivered as promised, for example.

There are also a number of events that smart contracts were not designed to handle. For instance, if Company A in the example above goes out of business and dissolves its assets while the item it agreed to purchase is in transit, when Company B delivers the item it will not be paid because Company A no longer has funds in its wallet. The severity of issues like this depend on how the smart contract was constructed, as each contract is different because contracts are written by humans. This scenario could be handled by designing the smart contract so that Company A has to send the bitcoin funds to the contract. In this case, the funds are locked up for the agreement and are only returned back to Company A if the criteria of the contract are not met.

A third challenge is that, because it is impossible to guarantee that any software is free of flaws, there is always a risk that a malicious party could exploit a security vulnerability in a smart contract’s code and cause problems. Because this has happened before, it’s worthwhile for smart contract developers and users to keep in mind that their smart contracts are not an absolute guarantee against cheating and fraud — even though in most respects they provide greater assurance against fraud than do traditional centralized contracts.

Which Blockchains and Programming Languages Are Best for Smart Contracts?

In theory, a smart contract could be executed on any blockchain. However, to date, Ethereum has been the most popular blockchain for running smart contracts because smart contracts were a key feature of Ethereum’s protocol.

Smart contracts can also be written in many programming languages, but Solidity, Ethereum’s smart contract language, is the most widely used due to Ethereum’s popularity.