Advanced10 min read

Flash Loans Explained

Borrow millions without collateral in a single transaction. Flash loans are one of DeFi's most powerful and unique innovations - impossible in traditional finance.

What Are Flash Loans?

A flash loan is an uncollateralized loan that must be borrowed and repaid within the same blockchain transaction. If you don't repay the loan (plus a small fee) by the end of the transaction, the entire transaction reverts - as if it never happened.

This is only possible because of how blockchain transactions work: they're atomic. Either everything in the transaction succeeds, or everything fails. There's no in-between.

The Magic of Atomicity

Imagine if you could say: "Give me $1 million. I promise to return $1,001,000 in the next 12 seconds. If I don't, pretend this never happened."

That's exactly what flash loans enable. The lender has zero risk because if you can't repay, the loan never leaves their wallet from their perspective.

How Flash Loans Work

Transaction Flow

1
Request the loan

Your smart contract calls the flash loan function, specifying how much to borrow.

2
Receive the funds

The protocol sends you the requested amount. You now have millions in your contract.

3
Execute your strategy

Do whatever you want with the money - arbitrage, swap collateral, refinance debt.

4
Repay the loan + fee

Return the borrowed amount plus fee (0.05-0.09% on Aave). Must happen in same transaction.

Transaction succeeds

If you repaid in full, you keep any profits. If not, everything reverts.

// Simplified flash loan flow

1. Borrow $1,000,000 USDC from Aave

2. Buy 285 ETH on DEX A @ $3,500

3. Sell 285 ETH on DEX B @ $3,520

4. Receive $1,003,200 USDC

5. Repay $1,000,500 to Aave (0.05% fee)

6. Profit: $2,700 ✓

Flash Loan Use Cases

1. Arbitrage

Profit from price differences between exchanges. Flash loans provide the capital to execute large arbitrage trades that would be impossible with your own funds.

Example: ETH is $3,500 on Uniswap but $3,520 on Sushiswap. Borrow $1M, buy on Uni, sell on Sushi, pocket the difference minus fees.

2. Collateral Swap

Change your collateral without closing your position. Normally you'd need to repay your loan first, but flash loans let you swap in one transaction.

Example: You have ETH collateral and USDC debt. Flash loan USDC → repay debt → withdraw ETH → swap to WBTC → deposit WBTC → borrow USDC → repay flash loan.

3. Self-Liquidation

Avoid the 5-10% liquidation penalty by closing your own position before liquidators can.

Example: Your Health Factor is approaching 1. Flash loan enough to repay your entire debt → repay debt → withdraw all collateral → sell collateral → repay flash loan. You save the liquidation penalty.

4. Debt Refinancing

Move your debt from one protocol to another for better rates.

Example: You're paying 8% on Compound but Aave offers 5%. Flash loan from Aave → repay Compound → withdraw collateral from Compound → deposit to Aave → borrow from Aave → repay flash loan.

5. One-Click Leverage

Build a leveraged position in a single transaction instead of multiple loops.

Example: You have $10K ETH, want 3x leverage. Flash loan $20K ETH → deposit all $30K → borrow $20K USDC → swap to ETH → repay flash loan. Done in one tx.

Flash Loan Providers

ProtocolFeeNetworks
Aave V30.05%Ethereum, Arbitrum, Optimism, Polygon, Base
Uniswap V3Pool fee (0.05-1%)Ethereum, L2s
Balancer0%Ethereum, Arbitrum, Polygon
dYdX0%Ethereum

Aave pioneered flash loans and remains the most popular provider. The 0.05% fee goes to liquidity providers, making it a win-win: depositors earn extra yield, borrowers get access to massive capital.

Flash Loan Attacks

Flash loans have been used in some of the largest DeFi exploits. However, it's important to understand: flash loans don't create vulnerabilities - they just make existing vulnerabilities easier to exploit.

Common Attack Patterns

  • Oracle Manipulation: Use massive borrowed funds to manipulate DEX prices, then exploit protocols using those prices as oracles.
  • Governance Attacks: Borrow governance tokens, vote on malicious proposals, repay tokens - all in one block.
  • Reentrancy Exploits: Flash loans provide capital to exploit reentrancy bugs in smart contracts.

How Protocols Protect Themselves

  • Use time-weighted average prices (TWAP) instead of spot prices
  • Require multiple blocks for governance actions
  • Implement reentrancy guards
  • Get thorough security audits
  • Use Chainlink oracles instead of DEX prices

Major protocols like Aave, Compound, and Maker are designed to be flash loan resistant. The victims of flash loan attacks are typically newer, less audited protocols with design flaws.

Using Flash Loans

Flash loans require smart contract development skills. You can't use them from a regular wallet interface.

What You Need

  • Solidity smart contract development skills
  • Understanding of the flash loan callback interface
  • ETH for gas fees (flash loans are complex transactions)
  • Testing on testnets before mainnet

No-Code Alternatives

Tools like DeFi Saver and Furucombo let you use flash loans through a drag-and-drop interface. They handle the smart contract complexity for you, though they charge additional fees.

Frequently Asked Questions

What is a flash loan?

A flash loan is an uncollateralized loan that must be borrowed and repaid within the same blockchain transaction. If the loan isn't repaid (plus fees) by the end of the transaction, the entire transaction reverts as if it never happened.

Why would anyone lend without collateral?

Because the loan is atomic - if not repaid within the same transaction, it never happened. The lender has zero risk since they either get their money back plus fees, or the transaction reverts entirely. This is only possible due to blockchain technology.

How much can I borrow with a flash loan?

You can borrow up to the total liquidity available in the pool. On major protocols like Aave, this can be hundreds of millions of dollars. The only limit is how much is deposited in the protocol.

What are flash loans used for?

Common uses include arbitrage (profiting from price differences between exchanges), collateral swaps (switching collateral without repaying debt), self-liquidation (avoiding liquidation penalties), and debt refinancing.

Are flash loans dangerous?

Flash loans themselves are not dangerous, but they have been used in exploits against poorly designed protocols. The loan is just a tool - the vulnerability exists in the target protocol. Well-audited protocols are generally safe from flash loan attacks.

Key Takeaways

  • Flash loans are uncollateralized loans that must be repaid in the same transaction
  • They're risk-free for lenders because failed repayment means the transaction never happened
  • Common uses: arbitrage, collateral swaps, self-liquidation, debt refinancing
  • Flash loan attacks exploit protocol vulnerabilities, not the loans themselves
  • Require smart contract skills or use no-code tools like DeFi Saver

Master DeFi Fundamentals First

Flash loans are advanced tools. Make sure you understand basic DeFi concepts like Health Factor and liquidation before diving deeper.

Financial Disclaimer: The information provided on this website is for educational and informational purposes only and should not be construed as financial, investment, or legal advice. Cryptocurrency and DeFi investments involve substantial risk, including the possible loss of principal. Past performance does not guarantee future results. Always conduct your own research and consult with a qualified financial advisor before making any investment decisions.

Educational Purpose: This content is designed to help you understand DeFi concepts and is not a recommendation to buy, sell, or hold any cryptocurrency or use any particular protocol. The examples and calculations shown are for illustrative purposes only.

Risk Warning: DeFi protocols carry inherent risks including but not limited to: smart contract vulnerabilities, liquidation risk, impermanent loss, protocol insolvency, and regulatory changes. Never invest more than you can afford to lose.

Published:
Last Updated: