Aave Guide

Flash Loans: How They Work, Explained Simply

A flash loan is an uncollateralized loan that must be borrowed and repaid inside one blockchain transaction. If the repayment doesn't happen before the transaction ends, the whole thing reverts as if it never occurred. No credit check, no collateral locked up for weeks — just an atomic block of code that either finishes clean or vanishes.

The One-Block Rule

Normal DeFi lending asks you to deposit more than you borrow. Want $1,000 of USDC? Post $1,500 of ETH first. Flash loans flip that. You post nothing because the protocol knows the money can't leave without coming back.

On Ethereum, a transaction executes in steps. A smart contract can call a lending pool, receive funds, run arbitrary logic, and return the funds — all before the transaction is finalized. Aave popularized this pattern with its flashLoan function, and the pool charges a small fee for the service. That fee gets added to the amount you must repay. If your logic fails at any step, the transaction reverts. The loan never existed. You pay only gas for the failed attempt.

Where the Money Actually Goes

People assume flash loans are free money. They're not. They're free capital, which is a different thing.

Arbitrage

The classic use. A token trades at slightly different prices on two exchanges. You borrow a large amount, buy low on one, sell high on the other, repay the loan plus fee, and pocket the difference. The window is often seconds wide.

Collateral Swaps

Say you've got a loan on Aave backed by ETH and you'd rather back it with wBTC. Without a flash loan, you'd need fresh capital to repay, withdraw, and re-deposit. With one, you borrow the repayment amount, swap your collateral, and close the loop in one go.

Liquidations

Liquidators use flash loans to buy discounted collateral from underwater positions without tying up their own cash. Borrow, repay the debt, collect the bonus, return the principal.

A Concrete Run-Through

Imagine you spot ETH at $3,000 on Exchange A and $3,030 on Exchange B — a 1% spread. You flash borrow 100 ETH from Aave. You sell it on Exchange B for $303,000. You buy 100 ETH back on Exchange A for $300,000. You now hold $3,000 in profit before fees. Repay the 100 ETH plus Aave's fee — historically around 0.05% to 0.09% of the loan, though it varies by pool and asset — and you're left with a thin margin. Gas costs eat into it too. On a busy day, that spread might not survive the fees at all.

The mistake beginners make: they calculate profit before fees and gas, then wonder why the transaction reverts. It reverts because the math didn't clear. That's the system working correctly.

Why Most Flash Loan Attempts Fail

Three reasons dominate.

  • Fee blindness. People forget the pool fee, the DEX swap fees, and gas. Stacked, they can exceed a small arbitrage spread.
  • Front-running. Bots with faster infrastructure see your opportunity and take it first. Your transaction lands after the price has moved.
  • Logic bugs. A single wrong variable in your contract and the whole thing reverts. No partial credit. No do-over.

This is why flash loans are mostly a developer and bot game. Writing a working flash loan contract requires Solidity knowledge, testing on a fork, and an understanding of how Aave's pool interface expects the callback function to behave.

Do You Need One?

Probably not, if you're a regular borrower. Flash loans solve a specific problem: needing large capital for a few seconds with zero collateral. If you're borrowing to hold a position over days or weeks, you want a normal collateralized loan. Where they're genuinely useful for individuals: collateral swaps and self-liquidation. Both save you from needing to source cash on short notice.

One more thing worth knowing. Flash loans aren't a hack. They're a tool. When you read about a protocol getting exploited, the flash loan usually just supplied the capital — the vulnerability was already there. Blaming the loan is like blaming the crowbar.

Frequently Asked Questions

Can I get a flash loan without writing code?

Some interfaces and aggregators offer simplified flash loan execution for common tasks like collateral swaps, but anything custom requires a smart contract. You can't just click "borrow" and walk away with funds. The loan has to be repaid in the same transaction, and that transaction has to be programmed.

What happens if I can't repay in time?

Nothing bad, in the sense that you don't owe anything. The transaction reverts entirely, meaning the borrowed funds never actually moved to your wallet in a finalized state. You lose the gas you spent attempting it, which on Ethereum can be meaningful during high congestion.

Are flash loans only on Aave?

No. Aave is one of the best-known providers, but other lending protocols and specialized services offer similar functionality. The mechanics are broadly the same — borrow and repay within one transaction — though fees, supported assets, and interfaces differ between platforms.

Is a flash loan risky?

The loan itself carries little risk to the borrower since it either completes or reverts. The risk sits in the logic you write. A buggy contract can waste gas repeatedly, and poorly planned strategies can execute successfully while still losing money to fees.

If you want to try one, start on a testnet fork with Foundry or Hardhat. Break it there first.