Education

What is a Smart Contract?

8 minutes

A smart contract is a piece of code that automatically executes the terms of a contract based on predetermined conditions. Such a program runs off a blockchain ecosystem, which gives it security, reliability, and immutability.

Just like a traditional contract, a smart contract allows two or more parties to code the conditions of their agreement. The smart contract will administer these without fear or favour, which is why smart contracts are one of the most revolutionary developments running off blockchain technology.

Smart Contracts Revolutionised Blockchain and Crypto

Smart contracts aren’t merely transactional. Today, blockchain developers can build complex applications called Decentralised Applications or DApps using smart contracts.

DApps are decentralised due to the design of blockchain ecosystems such as Ethereum. No central authority is necessary to execute and mediate agreements between parties. No single user controls the DApp, and all the rules are contained in the terms coded in the smart contract.

Decentralised finance(DeFi) is one of the most well-known examples of DApps. For example, decentralised exchanges allow for complex transactions like lending, savings, or insurance without any central oversight. No institution or middle man is required to facilitate transactions on these platforms. DeFi also ensures universal access to financial cryptocurrency services.

Examples of advanced DApps include:

  • Compound is a platform that allows peer-to-peer lending and borrowing. Lenders earn interest on their crypto, and borrowers access funds easily and quickly.
  • USDC is a stablecoin that keeps the value of one coin at the value of one dollar. It is a type of digital currency backed by the value of a fiat currency.
  • CryptoMines is a SciFi game launched on the new Binance Smart Chain (BSC). CryptoMines allows players to explore the Metaverse and earn crypto tokens called ETERNAL.
  • Raydium is a decentralised cryptocurrency exchange (DEX) running on Solana.

How Smart Contracts Work

Despite the name, smart contracts aren’t actually "smart". They don’t think on their own, even though they can make real-time decisions. Their autonomy comes from the pre-coded rules and conditions in their functions.

  • Anyone can write a smart contract to create a DApp for a smart contract-enabled ecosystem like Ethereum or Solana. This is done by using programming languages supported by the platform’s protocol.
  • The platform serves as a secure database to administer the smart contract. Everyone in the network can see and vote on the terms of the smart contracts. Each node (or "user") keeps a copy of the code and all transactions to prevent any discrepancies.
  • When a transaction in the smart contract is performed, every node uses its copy of the code to carry out the transaction and verify it. A majority of the nodes have to agree on the outcome of the transaction (reach a consensus) for the transaction to be approved.
  • For their trouble in transaction verification (or mining), these nodes get paid fees (gas fees in Ethereum). These are transaction fees paid by the people using the smart contract.
  • Once deployed, no single person can alter the smart contract. Even the owner doesn't have the power to do so unless this was coded into the smart contract in the first place.

In addition, smart contracts aren't legally enforceable. There is no legal framework existing that offers recourse in case of failure or error. In fact, some contracts depend entirely on the coding and development skills of the team behind them. If an error is made that creates security gaps or bugs, huge losses can be incurred.

For example, one of the largest crypto hacks of all time was the DAO (decentralised autonomous organisation) attack on the Ethereum blockchain in 2016. In the attack, a hacker took advantage of what is called a recursive call bug and stole over 3.6 million Ether.

At the time, that was worth over $170 million AUD. Because the hacker technically played by the rules of the DAO’s smart contracts, he claimed that he didn’t actually steal the Ether.

It is important to note that the DAO hack wasn’t due to a failure of the Ethereum blockchain, it was simply a bug in the DAO built on top of the ecosystem.

Since smart contracts are self-executing and self-arbitrating, they must cover every scenario and condition. What makes them secure is the fact that a public blockchain database maintains mutual trust. Everyone can see what transactions are taking place and has to vote on them.

Smart contracts are already revolutionising business, online communities, finance, and so much more. While the technology is still improving, its potential is inconceivably large, especially as the IoT and Web3 come into mainstream use.

Share this article