Book a free call

What Is DeFi, and How Does It Work?

DeFi is finance run by smart contracts instead of banks: lending, trading and interest with no company in the middle. Learn how it works and the risks.

Hertiv engineering teamReviewed by a senior engineer
7 min read
What Is DeFi, and How Does It Work?
On this page

Short answer

DeFi, short for decentralised finance, is a set of financial services that run on a blockchain through smart contracts instead of through banks, brokers or exchanges. You keep control of your funds, the rules are public, and anyone with a wallet can use them.

What is DeFi?

DeFi, short for decentralised finance, is a set of financial services that run on a blockchain through smart contracts instead of through banks, brokers or exchanges. Lending, borrowing, trading and earning interest happen in code that anyone can inspect, and no single company controls the service.

The key difference from a bank is who holds the money. In a bank, your deposit sits in the bank's accounts and the bank decides when you can move it. In DeFi, your funds stay in your own wallet or in a smart contract, and the contract moves them only when its rules say so.

ServiceIn traditional financeIn DeFi
LendingA bank lends its depositsA smart contract lends pooled funds
TradingAn exchange matches buyersA liquidity pool swaps tokens
InterestA bank sets the rateSupply and demand set the rate
PaymentsA bank moves the moneyA blockchain moves the tokens
CustodyA bank holds your fundsYou hold your own keys

DeFi is not one product. It is hundreds of protocols, each doing one job, that can be combined like building blocks. A lending protocol can use a price feed from another protocol and a stablecoin from a third, and the whole chain runs without any of them asking a bank for permission. For the exchange side, see what a DEX is.

How does DeFi work without banks?

DeFi works without banks because smart contracts replace the jobs a bank does: holding funds, checking rules, and settling trades. A smart contract is a program stored on a blockchain that runs exactly as written, and once it is live, nobody can change its rules without the change the contract itself allows.

The building blocks are simple. A stablecoin gives DeFi a dollar-like unit so prices stay steady. A liquidity pool holds two tokens and lets anyone swap one for the other at a price set by the ratio in the pool. A lending pool holds deposits and lets borrowers take funds against collateral.

Oracles feed outside facts into the contracts, such as the current price of a token, so the contract can decide when a loan is safe and when it must be closed. Governance tokens let holders vote on changes to a protocol, such as fees or new features, instead of a board deciding behind closed doors.

None of this needs a licence from a bank or a trading floor. Anyone with a wallet and an internet connection can use a DeFi protocol, which is why DeFi grew fastest in places where banking is slow or expensive. That openness is also its biggest risk, since there is no bank to call when something goes wrong.

What can you do with DeFi?

You can lend, borrow, trade, earn interest and send money with DeFi, and each service is a separate protocol you choose. The most used services are lending, decentralised trading, and earning yield on stablecoins, and each one works the same way: you connect a wallet, approve a transaction, and the contract does the rest.

Lending works by pooling deposits. Lenders put stablecoins or crypto into a pool and earn interest, while borrowers take funds from the same pool and pay interest. The rate moves with supply and demand: when many people want to borrow, the rate rises, which draws in more lenders.

Trading works through liquidity pools instead of order books. You swap one token for another at a price set by the pool, and the people who supplied the tokens earn a small fee on every swap. The pool is always open, so there is no market close and no broker in the middle.

You can also send money across borders in minutes, buy tokenised assets such as a share of a fund, or insure a position against a smart contract failure. Each service is built on the same idea: the rules are public, the funds are visible on the blockchain, and the user keeps control of their keys. For how teams build these services, see how to create DeFi dApps.

How do DeFi lending and swaps work?

DeFi lending works on collateral, not on credit checks. To borrow, you lock up crypto worth more than the loan, usually 150 percent or more, and the contract releases the loan. If the collateral falls in value and the loan is no longer covered, the contract sells some of it to repay the lender.

Take a simple case. You lock up $15,000 of ether and borrow $10,000 of stablecoins. Your loan-to-value is 67 percent. If ether falls and your collateral is worth $12,000, the ratio rises to 83 percent, and the contract warns you. If it falls further, the contract liquidates part of the collateral, so the lender is repaid even though you lost money.

Swaps work on a different rule. A liquidity pool holds two tokens, and the price comes from their ratio. If a pool holds 100 ether and 300,000 stablecoins, one ether costs about 3,000 stablecoins. When you buy ether from the pool, ether leaves and stablecoins enter, so the price rises a little for the next buyer.

That price move is called slippage, and it matters most in small pools. A $1,000 swap in a deep pool moves the price by almost nothing, while the same swap in a thin pool can cost several percent. Checking the pool size before a swap is the single most useful habit in DeFi.

What are the risks of DeFi?

The risks of DeFi are real, and they are different from the risks of a bank. The biggest are smart contract bugs, price falls that trigger liquidation, and scams that copy the look of a real protocol. There is no deposit insurance and no help desk that can reverse a transaction.

Smart contract bugs are the most feared risk. A flaw in the code can let an attacker drain a pool in minutes, and the money is usually gone for good. Audits help, but they do not prove a contract is safe, and new protocols carry more risk than ones that have run for years with large amounts of money in them.

Price risk is the everyday risk. Collateral can fall fast, and a loan that was safe in the morning can be liquidated by the evening. Stablecoins can also lose their peg, which is why many users spread funds across more than one stablecoin and more than one protocol.

Scams are the third risk. Fake websites, fake tokens and fake support accounts all try to get users to approve a transaction that hands over their funds. The defence is simple: only use links you typed yourself, check the contract address, and never approve a transaction you do not understand. For building with security in mind, see what a smart contract audit is.

Example (hypothetical): lending stablecoins on a DeFi protocol

Example (hypothetical): a user has $10,000 in stablecoins sitting in a wallet and decides to lend it on a DeFi protocol that pays 4 percent a year. Over one year, the interest is $10,000 times 0.04, which is $400, paid out as the rate moves with demand.

The same user also wants to borrow. She locks up $10,000 of ether as collateral and borrows $5,000 of stablecoins, a loan-to-value of 50 percent. The loan costs 5 percent a year, so the interest is $5,000 times 0.05, which is $250 a year.

Six months later, ether falls 40 percent, so the collateral is worth $10,000 times 0.6, which is $6,000. The loan is now $5,000 plus about $125 of interest, which is $5,125, and the collateral of $6,000 still covers it, so there is no liquidation. The user adds $1,000 of collateral to bring the ratio back down, and the loan stays safe.

The numbers show the trade-off. The user earned about $200 of lending interest in six months and paid about $125 of borrowing interest, a net gain of about $75, but she also watched $4,000 of collateral value disappear. DeFi rewards careful sizing, and it punishes borrowing close to the limit.

What are the common mistakes?

The most common DeFi mistakes are borrowing too much, trusting a new protocol with too much money, and approving transactions without reading them. Each one is easy to avoid with a small test first.

  • Borrowing close to the limit. A loan at 80 percent loan-to-value can be liquidated by one bad day.
  • Putting everything in one protocol. Spread funds across protocols and stablecoins so one failure does not take everything.
  • Skipping the test. Try a small amount first, and check that you can withdraw it before you add more.
  • Ignoring the audit. A protocol with no public audit is a gamble, not an investment.
  • Approving blindly. A wallet approval can hand over all your tokens, so read what it says.
  • Forgetting gas fees. Small transactions on a busy chain can cost more in fees than they earn.

Key takeaways

  • DeFi replaces banks with smart contracts that run exactly as written
  • Lending needs collateral, not a credit check, and the contract liquidates if it falls
  • Swaps use liquidity pools, and the price comes from the ratio in the pool
  • The main risks are contract bugs, liquidation and scams, with no deposit insurance
  • Start small, spread funds, and read every wallet approval before you sign

Frequently asked questions

Is DeFi the same as crypto?

No. Crypto is the asset, such as ether or a stablecoin. DeFi is the set of services built on top of those assets, such as lending, trading and earning interest, all run by smart contracts instead of by a bank or an exchange.

Do I need a bank account to use DeFi?

No. You need a crypto wallet, some crypto to pay transaction fees, and an internet connection. That is why DeFi is used in places where banking is slow or hard to access, though you still need a way to buy crypto in the first place.

How do DeFi protocols make money?

Most take a small fee on each trade or loan, which goes to the people who supplied the liquidity or to the protocol itself. The fee is written into the smart contract, so it is public and the same for everyone.

Is DeFi legal?

It depends on the country. Some countries have written rules for DeFi, others are still deciding, and a few restrict it. The protocol may be open to anyone, but the user is still bound by the laws where they live.

What happens if a DeFi protocol is hacked?

The funds are usually lost, because there is no bank to reverse the transaction and no deposit insurance. Some protocols hold insurance funds, but most do not, which is why audits, track records and small test amounts matter so much.

Can I lose money even if nothing is hacked?

Yes. Collateral can fall in value and trigger a liquidation, a stablecoin can lose its peg, and a thin liquidity pool can make a swap cost far more than expected. Price risk exists in DeFi just as it does in any market.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a DeFi product?

A senior engineer replies within one business day. Or see our DeFi Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call