How Do Ethereum Smart Contracts Work?

Smart contracts are programs that automatically execute transactions if certain conditions are met, without the need of an intermediary.

Updated Sep 29, 2023 at 11:50 a.m. UTC

Smart contracts are tools that can automatically execute transactions if certain conditions are met without requiring the help of an intermediary company or entity. They are often associated with Ethereum, a blockchain that was designed to accommodate smart contracts, but the idea isn’t restricted to any particular platform or network.

Whether obvious or not, intermediaries permeate our digital lives. Even simply sharing a cat photo with friends online requires the services of an intermediary like Facebook or Twitter – a central authority that doesn’t just manage the network, but also set the rules and enforce their violation. Smart contracts make it possible to automate these digital tasks without needing a centralized entity to manage and approve the transaction.

Smart contracts are made possible by blockchains, a network of computers that work together to enforce rules on the network without requiring the help of an intermediary.

With conventional contracts, a document outlines the terms of a relationship between two parties, which is enforceable by law. If one Party A violates the terms, Party B can take Party A to court for not complying with the agreement. A smart contract fortifies such agreements in code so the rules are automatically enforced without courts (or any third party) getting involved.

screen-shot-2017-03-28-at-5-43-08-pm

Ethereum, the world’s second-largest cryptocurrency by market cap, was created in 2013 specifically for creating smart contracts. To date, it is the most popular platform for doing so.

Smart contracts aren't widely used outside of Ethereum, and some are skeptical they'll ever achieve mainstream popularity as a way to manage transactions. Ethereum proponents, however, believe they could eventually become the norm for executing and securing online relationships.

Hundreds of apps that use smart contracts are already up and running. Popular Ethereum apps MakerDAO and Compound use smart contracts at their core for lending and allowing users to earn interest.

First conceived in 1993, the idea of a "smart contract" was originally described by computer scientist and cryptographer Nick Szabo as a kind of digital vending machine. In his famous example, he described how users could input $1, and receive an item from a machine, in this case a snack or a soft drink.

Smart contracts are the same in that with a certain input (the $1), the user should be able to expect a certain outcome (the chosen drink).

In a simple example of an Ethereum smart contract, a user sends a friend 10 ether – the token native to Ethereum – but requires that it can't be dispersed until after a certain date using a smart contract.

Why Ethereum smart contracts?

The world's first cryptocurrency, Bitcoin, was the first to support basic smart contracts, although they are extremely limited in comparison with Ethereum. Each transaction is a smart contract because the network will only approve of the transactions if certain conditions are met – that the user provides a digital signature proving that they indeed own the cryptocurrency they claim to own. Only the owner of a Bitcoin private key can produce such a digital signature.

By contrast, Ethereum replaces Bitcoin’s more restrictive language, replacing it with language that allows developers to use the blockchain to process more than just cryptocurrency transactions. The language is "Turing-complete," meaning it supports a broader set of computational instructions. Without limits, programmers can write just about any smart contract they can think of.

While this has obvious advantages, it also means that, because novel smart contracts are less tested, there is a higher chance of vulnerabilities. Ethereum has already seen millions of dollars of losses from exploited vulnerabilities in smart contracts.

Smart contract FAQs

What can smart contracts be used for?

Some common ways of using smart contracts are:

  • Multisignature accounts: Funds can only be spent when a required percentage of people agree.
  • Encoding financial agreements: Manage agreements between users. Say, if one person buys insurance from an insurance company, the rules of when the insurance can be redeemed can be programmed into a smart contract.
  • Agreements based on the outside world: Pull in data from the outside world (financial, political, or whatever) with the help of oracles.
  • Provide third party: Similar to how a software library works, smart contracts can work with other smart contracts in a chain.
  • Storage: Store information about an application, such as domain registration information or membership records. Storage in a blockchain like Ethereum is unique in that the data is immutable and can't be erased.

How can smart contracts work together?

Smart contracts aren’t intended to be used in isolation. Some smart contracts are built to assist other smart contracts.

When someone, say, places a simple bet on the temperature on a hot summer day via a smart contract, it might trigger a chain reaction of contracts under the hood. One contract would use outside data to determine the weather, and another contract could settle the bet based on the information it received from the first contract when the conditions are met.

With this in mind, smart contracts form the building blocks for decentralized applications and even whole companies, dubbed decentralized autonomous companies, which are controlled by smart contracts rather than human executives.

How is a smart contract set up?

A developer can create a smart contract by writing a slab of code – spelling out the rules, such as that 10 ether can only be retrieved by Alice 10 years from now.

The developer then pushes the smart contract to the Ethereum network, which is what enforces the contract – not allowing anyone to take the money unless they follow the exact rules in the code. Thousands of computers from around the world then all have a copy of this smart contract.

How do I use a smart contract?

Anyone can use smart contracts if they have Ethereum's native token ether, which can be bought on cryptocurrency exchanges.

Ethereum apps will usually provide instructions for how to use their specific app and underlying smart contracts. A common method is to use an Ethereum wallet tool, such as Metamask, to send the ether.

Users can use smart contracts for a range of use cases. Users can publish uncensorable posts to microblogging apps or lend out money without an intermediary, using a variety of Ethereum apps.

Do smart contracts cost anything?

Getting thousands of computers across the world to validate smart contracts often isn't cheap, though, as recent ballooning Ethereum fees highlight. The user must pay a fee, typically in ether (Ethereum’s native token), to keep the network up and running. Fees go up when the network grows more congested.

Are smart contracts legally enforced?

To many Ethereum advocates, smart contracts are intended to live outside of the legal system because they are enforced automatically. If they work as they're supposed to, users won't need to go to a court to settle conflicts.

That said, many wonder how these contracts would be treated under the current legal system. The answer is complicated. One 2018 research paper from partners Stuart D. Levi and Alex B. Lipton determined that U.S. law should recognize many smart contracts.

But, every country has a different legal approach to cryptocurrencies and blockchains, with some more accepting of the new technology than others.

Are smart contracts the future?

Many developers, researchers, and even lawyers and doctors are excited about the promises of smart contracts.

But it’s early days for smart contracts. While users of smart contracts don’t need to trust intermediaries, users must trust that the code was written correctly, which is a big ask seeing as there are still plenty of security issues. Many bug exploits have been unearthed over the years which allowed bad actors to steal user funds. The hope is these issues will grow rarer as the code matures.

By Alyssa Hertig

This article was originally published on Mar 30, 2017 at 3:45 p.m. UTC

Disclosure

Please note that our privacy policy, terms of use, cookies, and do not sell my personal information has been updated.

CoinDesk is an award-winning media outlet that covers the cryptocurrency industry. Its journalists abide by a strict set of editorial policies. In November 2023, CoinDesk was acquired by the Bullish group, owner of Bullish, a regulated, digital assets exchange. The Bullish group is majority-owned by Block.one; both companies have interests in a variety of blockchain and digital asset businesses and significant holdings of digital assets, including bitcoin. CoinDesk operates as an independent subsidiary with an editorial committee to protect journalistic independence. CoinDesk employees, including journalists, may receive options in the Bullish group as part of their compensation.

Alyssa Hertig

Alyssa Hertig is a programmer and journalist specializing in Bitcoin and the Lightning Network. She's currently writing a book exploring the ins and outs of Bitcoin governance. Alyssa owns some BTC.


Learn more about Consensus 2024, CoinDesk's longest-running and most influential event that brings together all sides of crypto, blockchain and Web3. Head to consensus.coindesk.com to register and buy your pass now.