Ethereum Smart Contracts: What Are They & How Do They Work?

Ethereum Smart Contracts: What Are They & How Do They Work?

You may have heard about smart contracts and their potential to replace lawyers. Read on to learn what Ethereum smart contracts are, how they work, and if they can indeed replace lawyers.

What Are Smart Contracts?

Smart contracts are self-executing computer programs stored on a blockchain. They are programmed to automatically carry out an outcome based on predetermined conditions triggered by an input.

Unlike conventional contracts, the execution of smart contracts is automatic. Hence, it does not involve any intermediary. That means parties can enter into agreements directly, eliminating costs that are otherwise paid to intermediaries that make sure a contract is executed properly.

Commonly, it takes time for traditional contracts to be executed because of the constant back and forth between parties and intermediaries like banks and lawyers. With smart contracts, however, parties can reduce the time it takes to put an agreement into effect.

Ethereum has made smart contracts popular, but the concept isn’t new. Nick Szabo introduced the idea of a smart contract in a 1994 paper, where he defined it as “a computerized transaction protocol that executes the terms of a contract.” Two years later, he followed up with another paper in 1996 that further explored the concept. 

How Do Smart Contracts Work on Ethereum?

A smart contract is code deployed on the blockchain that automatically executes transactions based on predetermined factors. Developers deploy smart contracts on the Ethereum network, which then run autonomously as programmed. Smart contracts reside at a particular address on the Ethereum blockchain.

A smart contract is a collection of two things: code and data. When you interact with a smart contract, you submit a transaction that executes the terms defined by the code. A smart contract follows the “if/when…then”-structure.

For instance, let’s say a property owner and a buyer have entered into an agreement. The buyer locks funds in a smart contract programmed to release the money if the property owner vacates the property, completes renovations, and shares digitized transfer ownership documents at a certain date. Therefore, the seller can not receive the payment until the predetermined terms have been met. Only then, if the buyer is sure to be the rightful owner of the property, will the funds be released by the smart contract.  

Smart contracts define the rules of an agreement and automatically enforce them via code. Since they’re on the blockchain, it’s theoretically impossible to delete smart contracts. Transactions are also irreversible, meaning once you activate a smart contract, it will implement the pre-defined terms, and no one can undo this action once it’s done.

Ethereum smart contracts are recorded on a public blockchain that is visible to everyone. Therefore, anyone can track information related to a particular smart contract through a block explorer. Nevertheless, your identity remains private because smart contract transactions are only tied to an address. Ethereum smart contracts also allow parties to view the terms before signing.

How to Write Smart Contracts on Ethereum

Writing Ethereum smart contracts requires coding knowledge. In the case of Ethereum, you need to be familiar with the programming language Solidity and Vyper to build smart contracts. Having experience in JavaScript and Python will help too. 

The code defines the rules of the smart contract according to the “if/when… then” structure. 

To illustrate, you can write a smart contract that will release 5 ETH to pay a developer’s salary every 5th of the month out of a company’s Ethereum wallet. 

Once the code is ready, you need to deploy it to the Ethereum network. Deployment means sending an Ethereum transaction containing the smart contract code. Like any other transaction, you’ll have to pay gas, which are fees required to carry out a transaction on the Ethereum network successfully.

Examples of Smart Contracts on Ethereum

Smart contracts have real-world use cases. If you decide to explore Ethereum’s decentralized applications (DApps) from the DeFi ecosystem like token swaps, lending, payment, investment, and insurance platforms, you might interact with a smart contract without even knowing it.

Here are examples of smart contract use cases on Ethereum:

Issuing Crypto-Backed Stablecoins

Stablecoins are digital assets that are less volatile than other cryptocurrencies because they are designed to remain at a fixed value vis-a-vis a fiat currency or a commodity. Stablecoins may be backed by other assets, either from the fiat world or in the form of crypto collateral. For example, a crypto-backed stablecoin is backed by a crypto asset. When minting a crypto-backed stablecoin like DAI, you lock ETH in a smart contract to receive DAI tokens.  

DeFi Lending Protocols

Decentralized lending protocols leverage smart contracts to enable lending market participants to come together to borrow and lend crypto assets without handing over control of their funds to a centralized third party. Instead of a centralized entity matching borrowers and lenders, smart contracts fulfill this role, creating autonomous money markets for crypto holders.  

P2P Trading on DEXs

Smart contracts enable peer-to-peer (P2P) trading on decentralized exchanges (DEXs) powered by Automated Market Maker protocols without intermediaries. The AMM protocol uses smart contracts to match buyers and sellers. Examples of popular AMMs include Uniswap and PancakeSwap.

What Can & Can’t Smart Contracts (Currently) Do? 

Smart contracts provide efficiency in a world that is becoming more and more digital every day. They facilitate the execution of agreements between two or more parties, and no one can take action outside the defined rules. Several industries such as finance, insurance, real estate, trading, gaming, and legal are benefiting from smart contracts. Bear in mind, however, that smart contracts may not be suitable for all businesses.

Smart contracts cannot run outside of blockchain networks. Also, they can’t automatically retrieve external information from outside the blockchain network from sources like websites. So, developers have tried to solve this problem with off-chain data feeds called oracles that act as a bridge between the blockchain network and the real world. However, single source oracles raise data validity and decentralization concerns. Moreover, an insecure website could compromise the security and integrity of an oracle.

Furthermore, smart contracts aren’t legally binding unless a country’s regulations recognize them as legally binding contracts. Smart contracts may be legally enforceable if they adhere to the basic rules of traditional legal contracts.

That said, developers generally design smart contracts to exist outside the legal system because they can be executed without third parties like lawyers. As long as they work as intended, conflicts should not arise, eliminating the need for lawyers and courts. 


Can You Build Smart Contracts on Other Blockchains?

Yes. Blockchains like Algorand, Avalanche, Cardano, Solana, Polkadot, and Hyperledger Fabric support smart contracts.

Are Ethereum Smart Contracts Costly?

Currently, yes. They demand higher gas fees than simple transfers on the Ethereum blockchain. Generally, already the average price of regular transfers is high. Planned changes to the Ethereum network, however, could see the cost of smart contracts decline in the future.

Are Smart Contracts Safe?

Smart contracts are susceptible to security risks due to bugs in the code. Hackers can exploit weaknesses in the code to implement attacks that could lead to the loss of locked funds. Therefore, smart contracts should be tested for bugs and any loopholes that hackers might utilize, just like any other computer program.

Can You Deploy Smart Contracts on Private Blockchains?

Yes, you can. These smart contracts are usually deployed in the context of sensitive information that is not meant for public viewing.

Can Smart Contracts Interact?

Yes. Smart contracts can deploy other smart contracts to the blockchain network. Multiple smart contracts can also interact with each other in one transaction.

What’s the Future of Smart Contracts?

Smart contracts are likely to get “smarter” as developers find solutions to the current problems. Also, many more mainstream organizations could adopt smart contracts as they look for ways to increase efficiency in their operations. Regulators may, therefore, see the need to provide clarity on the legal enforcement of smart contracts.