DeFi Basics
What Is Decentralized Finance (DeFi)?
Learn what decentralized finance (DeFi) is, how it works, and why it matters. Understand the core concepts of DeFi including smart contracts, blockchain, and permissionless financial services.
Learn what smart contracts are, how they work on blockchain networks, and why they are the foundation of DeFi applications like lending protocols and decentralized exchanges.
A smart contract is a self-executing program stored on a blockchain that automatically carries out the terms of an agreement when predefined conditions are met. Once deployed, it runs exactly as programmed — no intermediary, no discretion, no business hours.
The concept was first described by computer scientist Nick Szabo in 1994, but smart contracts only became practical with the launch of Ethereum in 2015. Ethereum was specifically designed to support arbitrary programmable logic on the blockchain, making it the first platform where developers could build complex applications — not just transfer currency.
Today, smart contracts are the foundation of the entire decentralized finance ecosystem. Every DeFi lending protocol, decentralized exchange, yield optimizer, and stablecoin system runs on smart contracts.
A smart contract works in a straightforward sequence:
Consider a simple escrow smart contract:
No escrow agent, no legal paperwork, no trust required — just code executing predictably on the blockchain.
Smart contracts are not just a component of decentralized finance — they are its entire infrastructure. Every DeFi application is a collection of smart contracts working together.
In DeFi lending protocols like Aave v3 and Morpho Blue, smart contracts handle:
All of this happens automatically, 24 hours a day, 7 days a week. When you use an aggregator like Borrow by Sats Terminal to take out a Bitcoin-backed loan, you are interacting with these smart contracts through a simplified interface.
On a decentralized exchange, smart contracts manage liquidity pools, calculate exchange rates using mathematical formulas, execute swaps, and distribute fees to liquidity providers — all without a central operator.
Algorithmic and crypto-collateralized stablecoins rely on smart contracts to maintain their peg to a target value. DAI, for example, is issued by smart contracts that accept crypto collateral and maintain system-wide collateralization ratios.
Solidity is the most widely used smart contract language, designed specifically for Ethereum and compatible blockchains (including all EVM-compatible chains like Arbitrum, Optimism, Base, and Polygon). Its syntax is similar to JavaScript, making it accessible to web developers. The vast majority of DeFi protocols — including Aave, Morpho Blue, Compound, and Uniswap — are written in Solidity.
Vyper is an alternative language for EVM-compatible blockchains. It prioritizes simplicity and security over flexibility, intentionally omitting features like inheritance and operator overloading that can introduce subtle bugs. Curve Finance is a notable DeFi protocol that uses Vyper extensively.
Rust is used for smart contracts on Solana (via the Anchor framework) and for Cosmos-based chains (via CosmWasm). Move is used on Aptos and Sui. Each language reflects the design philosophy of its target blockchain.
Once a smart contract is deployed to the blockchain, its code generally cannot be changed. This is a powerful guarantee: users can verify exactly what the contract will do, and no one — not even the original developer — can alter the rules after the fact.
However, this immutability also means that bugs cannot be simply patched. If a vulnerability is discovered in an immutable contract, the only option may be to deploy a new contract and migrate users to it.
Given the same inputs and the same state, a smart contract will always produce the same output. This determinism is essential because thousands of nodes must independently execute the contract and agree on the result. If execution were non-deterministic, the network could not reach consensus.
Smart contract code on public blockchains is visible to anyone. Major protocols publish their source code on GitHub, and verified contracts on block explorers like Etherscan allow anyone to read the code and understand exactly how the protocol works. This transparency enables community auditing and builds trust.
Smart contracts can call other smart contracts, enabling complex applications to be built by combining simpler building blocks. A single transaction might interact with a lending protocol, a DEX, and an oracle contract in sequence. This composability is one of DeFi's most powerful features and is often described as "money Legos."
Smart contracts often control millions or billions of dollars in user funds. A single vulnerability can lead to catastrophic losses. The history of DeFi includes several high-profile exploits where attackers drained hundreds of millions of dollars from vulnerable contracts.
The DeFi industry has developed several layers of defense:
Smart contract audits are professional reviews conducted by specialized security firms. Auditors analyze the code for common vulnerability patterns, logic errors, access control issues, and potential attack vectors. While an audit significantly reduces risk, it is not a guarantee of security — auditors may miss novel attack vectors, and the protocol's security also depends on external factors like oracle reliability and governance decisions.
While the base property of smart contracts is immutability, the DeFi industry has developed patterns that allow contract logic to be updated:
The most common approach uses a proxy contract that delegates calls to an implementation contract. When an upgrade is needed, a new implementation contract is deployed, and the proxy is pointed to it. The proxy's address — and therefore all user interactions and stored data — remains the same.
Upgradeability introduces a trust assumption: users must trust that whoever controls the upgrade mechanism (usually a governance process or a multisig wallet) will not deploy malicious code. Protocols manage this through:
Some protocols, like Uniswap v2, have chosen to deploy immutable contracts with no upgrade capability, accepting the limitation in exchange for stronger trust guarantees.
For most DeFi users, smart contracts work behind the scenes. When you visit a platform like Borrow by Sats Terminal and deposit Bitcoin as collateral to borrow stablecoins, you interact through a web interface that translates your actions into smart contract calls. Your wallet prompts you to approve each transaction, showing you exactly what the contract will do before you confirm.
Understanding that smart contracts power these interactions helps you:
Smart contracts are the engine of decentralized finance. They make it possible to lend, borrow, trade, and earn without intermediaries — and understanding how they work gives you a better foundation for navigating the DeFi ecosystem safely and effectively.
Common Questions
A smart contract is a program stored on a blockchain that runs automatically when certain conditions are met. Think of it like a vending machine: you put in the right inputs (money and a selection), and the machine automatically delivers the output (your snack) without needing a cashier. Similarly, a smart contract automatically executes agreed-upon actions — like transferring funds or issuing a loan — without needing a middleman.
Related Questions
DeFi Basics
Learn what decentralized finance (DeFi) is, how it works, and why it matters. Understand the core concepts of DeFi including smart contracts, blockchain, and permissionless financial services.
DeFi Basics
Understand how DeFi lending protocols work, including how interest rates are set, how collateral is managed, and which protocols are most widely used for crypto-backed borrowing.
Crypto Borrowing
A complete guide to how crypto borrowing works — from depositing collateral to repaying loans — covering DeFi protocols, CeFi lenders, and key concepts every borrower needs to know.
Crypto Borrowing
Understand the key risks of borrowing against Bitcoin, including liquidation risk, smart contract vulnerabilities, market volatility, and how to mitigate them.