Smart Contracts on Blockchain (Guide)

How the word smart contract is used can be vastly misleading.

First, a smart contract is not, to a large extent, a traditional contract or agreement as we understand it in legal terms. As you read through the post, it will become apparent how it is not.

Secondly, while the word smart contract is relatively new, the technical concept it describes is not. At least not entirely. Smart contracts have been around for as long as computers have been around.

For example, vending machines and Automated Teller Machines (ATMs) use smart contracts. When fed with the right data, in terms of cash and instructions, the machines perform particular tasks on their own.

If smart contracts have been around for several decades, why all the excitement about the concept in the recent past?

The blockchain, technology best known for bringing us Bitcoin and other digital currencies, has granted smart contracts qualities that give them the potential to disrupt almost every industry.

Indeed, the application of blockchain systems that could impact human society the most is not cryptocurrencies but smart contracts.

What is a Blockchain Smart Contract?

A smart contract is "if/when…then…" logic programmed into a physical or virtual machine. Indeed, it is a program or software that executes on the machine when certain predetermined conditions are met.  

The blockchain replaces the physical computer that had to be used prior to 2015 as the backend for smart contract execution. Indeed, blockchains that execute smart contracts are often referred to as virtual machines. For example, the Casper Virtual Machine (CVM) and the Ethereum Virtual Machine (EVM).

How Do Smart Contracts Work?

A smart contract directs a machine to perform a specific task if particular predetermined conditions are met.

For example, "if/when $.71 is inserted into the slot, then dispense a 0.5 liter can of soda." Or, "if/when a buyer sends USDT (stablecoin) to a given address, determine the ETH due to them based on reigning market prices, then release it from the escrow to the wallet address they provide."

Smart contract applications can be very complex. It can be an elaborate system on the blockchain that delivers services to its users. Indeed, decentralized applications (DApp) such as decentralized exchanges like Uniswap are complex smart contracts on the Ethereum blockchain that function without a centralized authority, such as a company actively managing its processes.

Today, it is possible to have most of the processes and systems of an entire organization automated through a smart contract with blockchain technology. Such organizations are known as Decentralized Anonymous Organizations (DAO). They can procure as well as deliver services to others without having an active workforce.  

Utilizing blockchain for secure smart contracts

Before the blockchain and distributed ledger technology, a smart contract could only be installed and run on a local device such as a computer, vending machine, or ATM. It could also be accessed remotely on a server. All these are centralized platforms.

Blockchain is designed to be decentralized. It is a peer-to-peer network of independent computers that act together as a unit through a robust consensus mechanism.

This unit can act together as a virtual machine on which a smart contract is executed. That means every step in a smart contract has to be agreed upon and approved by multiple parties on the blockchain network through a consensus mechanism.

Every step in the execution of the smart contract being agreed upon and approved collectively by independent computers on a peer-to-peer network is where the actual disruptiveness of blockchain smart contracts comes from.

The blockchain provides smart contracts with three qualities that are hard to find elsewhere:

Immutability

If a smart contract is written and deployed on a centralized platform such as a computer, a server, or another type of device, then there is a possibility that its details or processes can be arbitrarily changed while it is being executed.

On a centralized system, a few, in particular administrators, have the privilege to arbitrarily change how the smart contract is executed.

Since the blockchain is decentralized, no one has the power to effect changes arbitrarily once the smart contract is live. It has to run to the end or change through consensus on the network. It becomes immutable.

The immutability of smart contracts on the blockchain makes them tamperproof. Not even the developer who wrote it has the power to halt or change it except through predetermined mechanisms.

Security

Centralized systems always run the risk of being hacked remotely. That means hackers can easily compromise a smart contract on such a platform.

Since every step in the smart contract has to be approved by independent parties on a peer-to-peer network through a consensus mechanism, it is nearly impossible for a well-written and reviewed smart contract to be hacked to change its execution path.

The only way the execution path of a smart contract can be tampered with is by feeding it with the wrong data, especially from external sources. This has happened before, for example, through flash loan attacks on decentralized lending protocols.

Transparency

Smart contracts are used to handle critical processes. It is important that stakeholders can audit and verify these processes. The blockchain, especially permissionless ones, makes it possible that anyone who wants to can audit the processes of a smart contract on the blockchain.

Of course, there are cases where the creators of a smart contract want its details only accessible to stakeholders. Some smart contract blockchains, such as the Casper Network, have made it possible to make a smart contract private. However, this does not mean it is not as secure as one that is accessible to the public.

Smart contract and data

By their nature, smart contracts act when predetermined conditions are met. A smart contract must receive data from outside to determine if a predetermined condition has been met.

For simple smart contracts, that is easy to achieve. For example, in the case of a vending machine, inserting coins is sufficient information for it to determine whether it should give out a can of soda or not.

How about a smart contract (DeFi) that buys and sells digital assets, for example?

How can it determine the price to transact at, given that the market prices are continually changing?  

Such smart contracts rely on protocols and networks of computers known as oracles. The oracles can be centralized, such as the Coinbase Price Oracle, or decentralized, such as the Chainlink network.

The oracle protocols are designed to focus on incentivizing those who run them to provide accurate data to the smart contracts. For example, they receive the fees paid by the users of the smart contract. Those who provide erroneous data are punished for it by taking away part of their stake.

Smart Contract Use Cases on Blockchain

Smart contract application is proving critical in the building of both centralized as well as decentralized applications (DApps). Today almost every industry has a startup using smart contracts to solve problems.

Already this technology has been tested in a wide variety of industries and areas with significant success.

The following are some of the use cases of smart contracts.

Decentralized Finance (DeFi)

Most of the services we get through financial institutions such as banks and insurance companies can be accessed through smart contracts on the blockchain.

According to data from Coinmarketcap.com, the market cap of the decentralized finance (DeFi) industry is growing fast. The bulk of the amount processed is conversions on decentralized exchanges (DEXs) and credit on decentralized lending protocols.

The DeFi applications get liquidity from individual investors, who the smart contract pays from the profit it generates.  

Government Contracts

Some government services can be delivered at significantly less cost and with high efficiency through smart contracts on the blockchain.

For example, instead of citizens relying on centralized systems to trade real estate, it is possible to turn land titles into non-fungible tokens (NFTs) and then have buyers transact peer to peer using a smart contract. The cash agreed upon is simultaneously exchanged with the land title.

Governments attempting to build land registry systems on the blockchain include the Republic of Georgia, the United Arab Emirates, and the Netherlands.

Supply Chain Management Deals

There is a lot of documentation involved in the movement of goods from the producers to the consumers. This creates loopholes for counterfeits and adds a high cost to the final price paid by consumers.

Every interaction in the chain can be enhanced, and the cost involved is significantly reduced with smart contracts.

Also, through smart contracts on the blockchain, transparency in the supply chain of such goods as medication, food, and art. This can minimize counterfeits, which are worth over $500 million annually.  

Smart Contract blockchains

Not every blockchain has the capacity to host and execute custom smart contracts. Nevertheless, the list of blockchains to choose from is growing fast. It is becoming difficult to decide which blockchain to write and launch a smart contract.

The following are the things to consider when choosing a blockchain for a smart contract:

Capacity to process transactions

Some blockchains, especially the earliest ones, have struggled to scale. If a blockchain processes a limited number of transactions in a second, it is likely to slow the smart contracts that execute on top of it.

Gas fees

Most blockchains charge users a fee used to incentivize those who keep their computers on the network to process transactions. Some blockchain networks charge higher than others. Meanwhile, some are predictable and others are not.

For example, the gas fees on the Ethereum blockchain can not only be high but are also unpredictable. Meanwhile, the  Casper Network charges predictable low gas fees.

Impact on the environment

Different blockchains use different consensus mechanisms on their peer-to-peer networks. Some consensus mechanisms consume more energy than others. For example, proof of work used by Bitcoin consumes a significant amount of electric energy. Meanwhile, Casper and the planned upgrade to Ethereum 2.0  proof of stake (PoS) uses negligible amounts of electricity.

Smart contract dynamism

A smart contract must be sensitive to what happens in the real world. It has to be dynamic.

Smart contracts are made dynamic in two ways; through a robust oracle system that feeds it accurate information and a mechanism through which the smart contract can be upgraded to meet emerging needs.

It is important to consider if a blockchain offers this flexibility.

The following are five of the currently most used networks for smart contracts:

Ethereum (ETH)

Ethereum, launched in 2015, was the first blockchain to support smart contracts. Today, almost 70% of the active smart contracts are domiciled on the Ethereum network.

Nevertheless, using the Ethereum blockchain has posed several challenges. They include low transaction capacity. Initially, the network could only process about 15 transactions per second. The Ethereum community has been working on layer one and layer two scaling solutions.

The other challenge users of Ethereum smart contracts face is high gas fees for transactions. It can be very expensive to run a smart contract or carry out any other transaction on the blockchain.

There have also been concerns about the Ethereum network's impact on the environment. The Ethereum blockchain was designed to use the energy-intensive Proof of Work consensus mechanism. The Ethereum community is working towards transitioning to proof of stake.

Casper

This is a relatively new network built off the Casper CBC specification, designed by Ethereum developers. The network attempts to overcome the challenges developers and users face on the older blockchains.

For example, it uses the environmentally friendly Proof of Stake (PoS) consensus mechanism.

It also enables the building of upgradable smart contracts. The smart contracts launched on other blockchains are largely rigid. When there are unforeseen emerging needs, they continue performing as designed.

The Casper Network attempts to create the mechanism for making smart contracts highly dynamic without compromising their credibility.

The network is also developer-friendly. Instead of using a proprietary language, it supports rust and webassembly. Developers around the world can start building applications on the Casper network using tools and languages already familiar to them.

It also focuses on stabilizing gas fees so that users can adequately plan on how their smart contracts execute. This also translates to relatively lower and predictable gas fees.

Although Casper is a permissionless blockchain, it provides the capability for developers to build secure public or private applications on top of it.  

Hyperledger Fabric

This is a permissioned blockchain launched in 2015 by a consortium led by the Linux Foundation and includes major global banks and technology companies.

Smart contracts in the Hyperledger Fabric blockchain system are also referred to as chain codes. The control of the network is in the hands of the Hyperledger consortium. Unlike the other networks on this list, you cannot join the hyperledger network without being let by this entity.  

It concerns some that Hyperledger Fabric is not decentralized enough to provide the qualities that a blockchain should give a smart contract.

Cardano

Cardano is a proof of stake blockchain launched by Charles Hoskinson and Jermy Wood through Input Output Hong Kong (IOHK). The two were also co-founders of ethereum.

The Cardano blockchain uses delegated proof of stake consensus mechanism. The transaction fees on the Cardano blockchain are mostly constant, mostly around 0.16 ADA per transaction.

Other blockchains with smart contract capacity include Algorand, Polkadot, Ergo, Solana, Wave, NEO, and NEM.

Advantages to Using Smart Contracts (Blockchain)

The following are the reasons using blockchain to host and execute a smart contract is preferable, especially when compared to automating a process on a centralized platform such as a server:

Accuracy of the Contract Terms

Once terms of an agreement or steps of a process have been agreed upon, written down in code, and launched on the blockchain, all the stakeholders are assured that nothing will change in the future.

Trust and Transparency

In addition to the agreement of process being accurate, the smart contract is publicly accessible to anyone who wants to audit it. This is especially the case because the contract exists on a public blockchain. On some blockchains, such as the Casper Network, the smart contract can be private but still be audited by stakeholders.

Speed and Efficiency of the Agreement

The blockchain is on a global network. That means it never experiences downtime. You are not worried about the machines being offline. Even if three-quarters of the internet is offline, the blockchain will still work optimally and execute the smart contract as expected.

Security of Data on the Blockchain

Using cryptography and data storage architecture, the blockchain makes it easier to protect data integrity. The control over the data is given to the end-user and not a cooperation.

Disadvantages of Smart Contracts (Blockchain)

Smart contracts are not completely foolproof. Indeed, it is still early for this technology, and a few things need to improve. The following are areas where smart contracts have shortcomings.

Limited Use of External Data

It can be challenging to bring into a smart contract the reliable data it needs to execute specific tasks. While robust oracles exist now, they cannot provide every type of data your smart contract might need.

Also, in a few cases, oracles have been compromised and the erroneous data fed into the smart contract. A case in point is flash loan attacks on a few DeFi applications.

Implementation and Use of Smart Contracts

Writing and executing smart contracts is a highly technical process that requires high skill. Smart contracts, in particular, can encompass putting a significant number of steps together, and a single error can make the entire smart contract fail to achieve its goal. It can even lead to a huge loss.

In 2016, a DAO lost $60 million because of an error in its smart contract that an attacker used to siphon the funds. This event also led to the split of Ethereum into Ethereum and Ethereum Classic.

Limited Legal Rulings on Contract Law Cases with Smart Contracts

Contracts and agreements are ultimately enforced through the courts. As things stand today, the legal system in most jurisdictions does not recognize smart contracts.

This limits the amount of innovation that can be achieved. For example, while it is technically possible to create a system where real estate can be traded peer-to-peer through smart contracts, no legal system would recognize such a transaction at the moment.

Contact Casper for more resources on blockchain and smart contracts

We provide blockchain and cryptocurrency expertise.

Get Started with Blockchain-Based Smart Contracts Today!