Flash Loan

A flash loan is an uncollateralised DeFi loan that must be borrowed and repaid within the same blockchain transaction; if it is not repaid, the whole transaction is reversed. Flash loans are used for arbitrage, and also in attacks that borrow huge sums to manipulate a vulnerable protocol.

A flash loan lets a smart contract borrow crypto with no collateral, as long as it pays it back in the same transaction. If repayment fails, everything is undone. Flash loans power arbitrage and collateral swaps, and they have also funded well-known DeFi attacks.

Category
Cryptocurrency and Blockchain
Reading time
4 min
Also called
Flash lending, Uncollateralized atomic loan, Flash swap
Updated

Flash loans in plain words

A flash loan lets a smart contract borrow tokens with no collateral, as long as it pays them back within the same transaction.1

If the money isn't returned, the whole transaction is cancelled as if it never happened.2

Before the transaction ends, the lender gets its tokens back, sometimes with a fee.1

How a flash loan runs

  1. Write the contract

    The borrower is a smart contract, not a person clicking a button.1

  2. Borrow

    The contract requests tokens from a lending pool with no collateral.

  3. Use the funds

    It trades, swaps collateral or repays debt; flash loans have been used for debt swaps and collateral swaps.2

  4. Repay plus fee

    The tokens plus an optional fee go back before the transaction ends.1

  5. Or revert

    If repayment fails, the whole transaction reverts.2

  6. Pay gas either way

    The network still charges for the attempt, so failed tries cost money.

Worked examples

Example 1 — Arbitrage with a flash loan

+$1,910 before gas

Hypothetically a token trades at $1.00 on DEX A and $1.02 on DEX B. A contract borrows 100,000 stablecoins with a 0.09% fee.

Example 1 — Arbitrage with a flash loan — calculation
Buy on A100,000 ÷ $1.00 = 100,000 tokens
Sell on B100,000 × $1.02 = $102,000
Fee100,000 × 0.0009 = $90
Profit before gas$102,000 − $100,000 − $90 = $1,910

Gaps like this are typical targets — three-way arbitrage chances come up often in DeFi.2

Example 2 — The gap closes first

Reverted, gas lost

Same trade, but by execution the DEX B price is $1.00.

Example 2 — The gap closes first — calculation
Sale proceeds100,000 × $1.00 = $100,000
Owed$100,000 + $90 = $100,090
Shortfall$100,000 − $100,090 = −$90

Repayment failed, so the entire transaction was cancelled; only the gas fee was lost.2

Example 3 — Collateral swap

Collateral switched

Hypothetically a user has a loan backed by 10 ETH and wants to switch it to a different collateral token without first raising cash.

Example 3 — Collateral swap — calculation
Flash borrowEnough to repay the old loan
Release and swap10 ETH swapped into new collateral
Reopen and repayNew loan repays the flash loan

This is a collateral swap: close one position and reopen it with different collateral, all in one atomic transaction.2

Flash loan vs ordinary crypto loan

AspectFlash loanCollateralized loan
CollateralNoneRequired, often over 100%
DurationOne transactionDays to months
Default risk for lenderRemoved by revertingCovered by liquidation
Who can use itSmart contractsAny account

Common flash loan uses

  • Arbitrage

    Close price gaps across venues to tighten Bid-Ask Spread differences.

  • Self-liquidation

    Repay debt to avoid a costly Liquidation.

  • Collateral swaps

    Change Exposure without unwinding by hand.

  • Testing liquidity

    Check how much Slippage a large trade would face.

Advantages and disadvantages

Advantages

  • No collateral needed.
  • Lender faces no default risk.
  • Enables complex trades in one step.
  • Failed attempts are reverted.

Disadvantages

  • Requires smart contract skills.
  • Gas is paid even if it fails.
  • Competition makes profits thin.
  • Used in price and governance attacks.

Going deeper

Read as far as you need. Each level builds on the one before it.

Borrow and repay at once

Beginner

The defining rule is atomicity: the loan must come back within the same transaction.1

Uses beyond arbitrage

Intermediate

Beyond arbitrage, flash loans are used for swapping debt or collateral and for repaying loans with the collateral itself.2

Attacks

Advanced

ESMA lists flash loan attacks among new DeFi market manipulation techniques.3 In the Beanstalk case, an attacker bought enough governance tokens to acquire a super majority and immediately executed a proposal.3

Common mistakes

  1. Forgetting gas

    A reverted loan still costs network fees.

  2. Ignoring the fee

    Thin gaps vanish after the loan fee.

  3. Assuming free money

    Bots compete for the same gap.

  4. Trusting unaudited code

    A bug can lose the profit or more.

Check your understanding

Test yourself before moving on. Each answer comes with an explanation.

Q1What happens if a flash loan is not repaid?
Q2Borrow 50,000 at a 0.05% fee. What is the fee?

Key points to remember

  1. Flash loans need no collateral.
  2. They must be repaid in the same transaction.
  3. Failure reverts everything except gas.
  4. Main uses are arbitrage and collateral swaps.
  5. They have also funded DeFi attacks.

Frequently asked questions

Can anyone take a flash loan?

Only through a smart contract, so it needs coding or a tool built on one.

Are flash loans risky for lenders?

Default risk is removed by reverting, but protocol bugs remain a risk.

Are flash loans illegal?

The tool itself is neutral; rules on market abuse differ by country.

Further learning

Sources

This article is written in our own words. The sources below support the specific facts, rules and figures marked with a number in the text. Links open the original publisher’s page.

  1. Ethereum Improvement Proposals. ERC-3156: Flash Loans (opens in a new tab) Checked .
  2. Bank of Canada. Risk-Free Uncollateralized Lending in Decentralized Markets: An Introduction to Flash Loans (Staff Discussion Paper 2025-6) (opens in a new tab) Checked .
  3. European Securities and Markets Authority (ESMA). Decentralised Finance in the EU: Developments and risks (TRV, Oct 2023) (opens in a new tab) Checked .

Educational content, not financial advice. Examples use hypothetical prices and simplified costs; actual fees, margin rules and regulations vary by broker, market and country. We are not affiliated with any publisher linked above. Last reviewed . Report an error or request a source credit.