What Is a Smart Contract?

A smart contract is a program stored on a blockchain that automatically executes predefined actions when specific conditions are met. The term was coined by computer scientist Nick Szabo in the 1990s, but it became practically deployable with the launch of Ethereum in 2015, which introduced a programmable blockchain capable of running arbitrary code.

Think of a smart contract as a vending machine: you insert the correct input (coins + selection), and the machine delivers the output (your snack) without requiring a human cashier. The rules are encoded in the machine itself, and they cannot be overridden.

How Smart Contracts Execute

When you interact with a DeFi protocol, you're sending a transaction to a smart contract address on the blockchain. Here's what happens step by step:

  1. Transaction broadcast: Your wallet signs and broadcasts a transaction to the network.
  2. Validation: Network nodes verify the transaction is correctly formatted and your account has sufficient funds to cover gas costs.
  3. Execution: The Ethereum Virtual Machine (EVM) — a decentralized global computer — runs the contract's bytecode using the parameters you provided.
  4. State update: The blockchain's state is updated to reflect the outcome (e.g., your token balance changes, a new LP position is recorded).
  5. Finality: Once included in a confirmed block, the outcome is permanent and immutable.

Key Properties of Smart Contracts

  • Trustless: No intermediary is required. The code enforces the agreement.
  • Transparent: Contract code is publicly verifiable on the blockchain.
  • Immutable: Once deployed, the core logic cannot be changed (unless upgradeability was built in via proxy patterns).
  • Deterministic: Given the same inputs, the contract always produces the same outputs.
  • Composable: Contracts can call other contracts, enabling complex "money lego" interactions between protocols.

Smart Contracts vs. Traditional Contracts

FeatureTraditional ContractSmart Contract
EnforcementCourts and legal systemCode execution on blockchain
SpeedDays to weeksSeconds to minutes
CostLegal fees, intermediariesGas fees only
TransparencyPrivate, parties onlyPublicly auditable
Counterparty riskHighMinimal (code risk instead)

The Role of Gas

Every operation a smart contract performs — storing data, running calculations, transferring tokens — consumes gas, a unit measuring computational effort. Users pay gas fees in the blockchain's native currency (ETH on Ethereum) to compensate validators for executing their transactions. Complex contracts with many operations cost more gas than simple token transfers.

Gas prices fluctuate with network demand. During periods of high activity, executing a smart contract can become expensive. This is why many DeFi users operate on Layer 2 networks (Arbitrum, Optimism, Base) or alternative EVM chains that offer lower fees.

Upgradeable vs. Immutable Contracts

A common design question in DeFi: should a contract be upgradeable? Immutable contracts offer maximum trustlessness — the code can never change. Upgradeable contracts (using proxy patterns) allow teams to fix bugs or add features, but introduce governance risk — whoever controls the upgrade key can potentially alter behavior.

Many mature protocols use a hybrid approach: core logic is immutable, but parameters (like fee rates) can be adjusted through on-chain governance votes.

Why This Matters for DeFi Participants

When you deposit funds into a DeFi protocol, you are trusting its smart contracts absolutely. There is no customer support line, no deposit insurance, and no legal recourse if the code behaves unexpectedly. This is why reviewing audit reports, understanding protocol architecture, and limiting exposure to any single contract are non-negotiable habits for serious DeFi participants.