WTF Is... A Smart Contract

TLDR: A smart contract is an agreement that gets executed as code on a blockchain like Ethereum, Tezos, Avalanche or others. When the conditions of the contract are met, the blockchain's nodes automatically perform and validate the functions of the code.

If you've ever used a vending machine, you're likely more familiar with the concept of smart contracts than you realize. Say you want to buy a Coke for $2 from a vending machine. The machine's computer needs two inputs in order to execute the transaction:

  1. The position of the Coke can (A1, B2, C3, etc.)
  2. The price

To get your soda, you must press buttons to input the necessary information. Once you do, the machine follows the instructions. The computer knows exactly how much change to give in return and what product to deliver. As long as you enter the appropriate information, the computer can execute the transaction without much management.

Simple enough, right? Interestingly, vending machines are a lot like smart contracts.

Smart contracts are hard-coded, permanent and permissionless pieces of code that require zero third-party intermediaries to execute a transaction on blockchain. Just like vending machines, which exchange your money for the Coke you’ve purchased, smart contracts automatically exchange crypto according to the instructions when the agreement's conditions (or inputs) are met.

Why care about smart contracts?

Smart contracts are core to many blockchain networks. On the Ethereum network, smart contracts are the building blocks for dApps, or decentralized applications. They are used to automatically execute transactions between two parties and can be used for virtually any use case.

For More: WTF Is… A DAPP

Smart contracts have many benefits:

  1. Open source: Anyone on the network can use them.
  2. Transparent: You can see the transactions that have interacted with them.
  3. Permissionless: No third party is involved in the transaction
  4. Secure: They rely on the security of the blockchain network on which they live.
  5. Instantaneous. Transactions can occur within seconds!

On the Ethereum network, anyone can write and deploy a smart contract, making it globally available to anyone on the network to use.

Popular uses and real world examples of smart contracts

On the Ethereum network, a smart contract is a type of account. The smart contract has a balance and can accept transactions and will contain a transaction history. However, no one owns this account; instead, users can interact with the account by submitting a transaction that executes a function from the smart contract code.

Minting NFTs

A great example of how users can interact with smart contracts is minting NFTs. A simple mint function on a smart contract takes in a recipient address and a metadata source, which is the info describing the NFT. If you’re curious, you can follow this Ethereum tutorial to create your own mint NFT function on a smart contract that you deploy.

DAO governance

Smart contracts can be used to create multi-signature (multisig) accounts which are used by decentralized autonomous organizations (DAOs) to enforce rules about how money is spent. For example, a DAO might apply a rule that determines funds can only be spent when two-thirds, or 66%, of its members agree. When these conditions are met through a community vote, the smart contract can be programmed to deploy.

Decentralized finance (DeFi) protocols

Swapping, staking and lending crypto are common activities in decentralized finance (DeFi). Traders can use smart contracts to manage their positions by determining the prices or exchange rates at which they want to buy or sell, or set other conditions that, when met, trigger a transaction. For example, Uniswap is a protocol that consists of many smart contracts enabling users to trade tokens on the Ethereum ecosystem. Each of the smart contracts that enable trading consist of a pool of a specific token and Ether that users can swap against, and contains a swap function, amongst others, that users can execute.

Security risks

Transactions made through smart contracts are irreversible, similar to how you cannot return your Coke to the vending machine once you’ve purchased it. It’s especially important for smart contract code to be audited by to find any security vulnerabilities or flaws before deploying. 

The 2017 DAO Hack, an infamous $60 Million hack of one of the earliest investment DAOs (known as The DAO), was caused by the exploitation of a vulnerability in a smart contract which took more than one-third of the funds raised by The DAO. This vulnerability notoriously caused the Ethereum hard-fork and split off Ethereum from Ethereum Classic.

Smart contracts are powerfully good and must be used with caution!

Akhila Raju is a Product Manager at Dune based out of NYC. Previously, she was an engineer at Coinbase, ConsenSys and Google, and graduated with a Computer Science degree from UC Berkeley.

This article and all the information in it does not constitute financial advice. If you don’t want to invest money or time in Web3, you don’t have to. As always: Do your own research.

More Articles

Shop NFTs

Browse the official collections on OpenSea:
BFF Friendship Bracelet
BFF Friendship Bracelets
The BFF 'You' Collection. Artwork by Jade Purple Brown.
You PFP Collection