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:
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.
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:
On the Ethereum network, anyone can write and deploy a smart contract, making it globally available to anyone on the network to use.
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.
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.
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.
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.
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.