Coinbase Logo

Language and region

Don’t invest unless you’re prepared to lose all the money you invest. This is a high-risk investment and you should not expect to be protected if something goes wrong. Take 2 mins to learn more

What is a smart contract?

Smart contract

Definition

A smart contract, like any contract, establishes the terms of an agreement. But unlike a traditional contract, a smart contract’s terms are executed as code running on a blockchain like Ethereum. Smart contracts allow developers to build apps that take advantage of blockchain security, reliability, and accessibility while offering sophisticated peer-to-peer functionality — everything from loans and insurance to logistics and gaming.

Just like any contract, smart contracts lay out the terms of an agreement or deal. What makes smart contracts “smart,” however, is that the terms are established and executed as code running on a blockchain, rather than on paper sitting on a lawyer’s desk. Smart contracts expand on the basic idea behind Bitcoin — sending and receiving money without a “trusted intermediary” like a bank in the middle —  to make it possible to securely automate and decentralize virtually any kind of deal or transaction, no matter how complex. And because they run on a blockchain like Ethereum, they offer security, reliability, and borderless accessibility.

Why are smart contracts important?

Smart contracts allow developers to build a wide variety of decentralized apps and tokens. They’re used in everything from new financial tools to logistics and game experiences, and they’re stored on a blockchain like any other crypto transaction. Once a smart-contract app has been added to the blockchain, it generally can’t be reversed or changed (although there are some exceptions).

Smart-contract-powered apps are often referred to as “decentralized applications” or “dapps” – and they include decentralized finance (or DeFi) tech that aims to transform the banking industry. DeFi apps allow cryptocurrency holders to engage in complex financial transactions — saving, loans, insurance — without a bank or other financial institution taking a cut and from anywhere in the world. Some of the more popular current smart-contract powered applications include:

  • Uniswap: A decentralized exchange that allows users, via smart contract, to trade certain kinds of crypto without any central authority setting the exchange rates.

  • Compound: A platform that uses smart contracts to let investors earn interest and borrowers to instantly get a loan without the need for a bank in the middle. 

  • USDC: A cryptocurrency that is pegged via smart contract to the US dollar, making one USDC worth one U.S. dollar. UDDC is part of a newer category of digital money known as stablecoins.

So how would you use these smart contract-powered tools? Imagine you’re holding some Ethereum that you’d like to trade for USDC. You could put some Ethereum into Uniswap, which, via smart contract, can automatically find you the best exchange rate, make the trade, and send you your USDC. You could then put some of your USDC into Compound to lend to others and receive an algorithmically determined rate of interest — all without using a bank or other financial institution. 

In traditional finance, swapping currencies is expensive and time consuming. And it isn't easy or secure for individuals to loan out their liquid assets to strangers on the other side of the world. But smart contracts make both of those scenarios, and a vast variety of others, possible.

How do smart contracts work?

Smart contracts were first proposed in the 1990s by a computer scientist and lawyer named Nick Szabo. Szabo famously compared a smart contract to a vending machine. Imagine a machine that sells cans of soda for a quarter. If you put a dollar into the machine and select a soda, the machine is hardwired to either produce your drink and 75 cents in change, or (if your choice is sold out) to prompt you to make another selection or get your dollar back. This is an example of a simple smart contract. Just like a soda machine can automate a sale without a human intermediary, smart contracts can automate virtually any kind of exchange.

Currently, Ethereum is the most popular smart contract platform, but many other cryptocurrency blockchains (including EOS, Neo, Tezos, Tron, Polkadot, and Algorand) can run them. A smart contract can be created and deployed to a blockchain by anyone. Their code is transparent and publicly verifiable, which means that any interested party can see exactly what logic a smart contract follows when it receives digital assets.

  • Smart contracts are written in a variety of programming languages (including Solidity, Web Assembly, and Michelson). On the Ethereum network,  each smart contract’s code is stored on the blockchain, allowing any interested party to inspect the contract’s code and current state to verify its functionality. 

  • Each computer on the network (or “node”) stores a copy of all existing smart contracts and their current state alongside the blockchain and transaction data. 

  • When a smart contract receives funds from a user, its code is executed by all nodes in the network in order to reach a consensus about the outcome and resulting flow of value. This is what allows smart contracts to securely run without any central authority, even when users are making complex financial transactions with unknown entities.

  • To execute a smart contract on the Ethereum network, you will generally have to pay a fee called “gas” (so named because these fees keep the blockchain running).

  • Once deployed onto a blockchain, smart contracts generally can’t be altered, even by their creator. (There are exceptions to this rule.) This helps ensure that they can’t be censored or shut down. 

Explore Bitcoin

Create a Coinbase account to start your crypto journey.