What Is a Flash Loan? How MEV Bots Borrow Millions in One Transaction
By Merunas Grincalaitis, founder of MEV DAO and a developer who builds MEV, sniping and trading bots on Ethereum. Last updated: October 2026.
TL;DR: A flash loan is a loan with no collateral that has to be borrowed and paid back inside one Ethereum transaction. If the money isn't back by the end, the whole transaction reverts as if it never happened, so the lender can't lose. Aave V3 charges 0.05% by default, while Balancer and Morpho charge nothing. MEV bots use flash loans to run arbitrage and liquidations with capital they don't own, but the loan only removes the capital problem. It does nothing for the hard part, which is finding the trade before someone else does.
The first time I wrote a flash loan contract, what surprised me was how boring the code is. All the difficulty lives in what you do between borrowing and paying back.
What is a flash loan?
A flash loan is an uncollateralized loan that must be repaid, plus any fee, before the transaction that took it finishes. Nobody checks your credit and you post nothing. The guarantee comes from how Ethereum executes transactions: every step either completes together or gets rolled back together. This property is called atomicity.
So the lender's contract does three things in order. It sends you the tokens, it calls a function on your contract, and then it checks its own balance. If the balance isn't back to where it started plus the fee, it reverts. A revert undoes every token movement in that transaction, including the loan itself.
Aave's own docs describe it as access to pool liquidity "for one transaction as long as the amount taken plus fee is returned" (Aave flash loan guide). That one sentence is the whole concept.
How does a flash loan work, step by step?
Your contract asks the lender for tokens, gets a callback while holding them, and has to approve or transfer the repayment before the callback ends. Here's the flow with Aave V3's flashLoanSimple:
- Your bot sends a transaction that calls your own contract.
- Your contract calls
Pool.flashLoanSimple(receiver, asset, amount, params, 0)on Aave. - Aave transfers
amountof the asset to your contract. - Aave calls
executeOperation(asset, amount, premium, initiator, params)on your contract. - Inside that function you run your logic: swaps, a liquidation, a collateral swap, whatever you planned.
- Before returning, your contract approves the Pool for
amount + premium. - Aave pulls the money back. If it can't, the transaction reverts.
A stripped-down receiver looks like this. It isn't production code, but it shows the shape:
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external returns (bool) {
require(msg.sender == address(POOL), "not pool");
require(initiator == address(this), "not me");
// your arbitrage or liquidation logic goes here
IERC20(asset).approve(address(POOL), amount + premium);
return true;
}
The interface comes straight from Aave's IFlashLoanSimpleReceiver. Those two require lines matter more than they look. Without them, anyone can call your callback and make your contract do things with its own balance.
Where can you get a flash loan on Ethereum, and what does it cost?
The main sources are Aave, Balancer, Morpho and Uniswap, and the fees run from zero to the pool's swap fee. Here's how they compare from the docs:
| Source | Function / callback | Fee | Notes |
|---|---|---|---|
| Aave V3 | flashLoanSimple / executeOperation |
0.05% at deployment, set by governance | Read the live value with FLASHLOAN_PREMIUM_TOTAL |
| Balancer V2 Vault | flashLoan / receiveFlashLoan |
0 | Governance could set a fee but never has |
| Balancer V3 | Vault unlock (transient accounting) | 0 | Fee-free by design |
| Morpho | flashLoan / onMorphoFlashLoan |
0 | Only tokens held by the Morpho contract |
| Uniswap V2 | flash swap via uniswapV2Call |
0.3% swap fee | About 0.3009% if you repay in the same token |
| Uniswap V3 | flash / uniswapV3FlashCallback |
The pool's fee tier | 0.05%, 0.3% or 1% depending on pool |
Sources: Aave docs, Balancer protocol fees, Morpho flash loans, Uniswap V2 flash swaps, Uniswap V3 flash callback.
Free sources like Balancer and Morpho are the natural first choice. Aave makes sense when the token you need just isn't sitting in those other contracts in the size you want. The fee is a percentage of the amount borrowed, so on a large arbitrage leg 0.05% can eat the entire edge.
How do MEV bots use flash loans?
They use them to fund trades that pay back more than they cost within one transaction, mainly DEX arbitrage, liquidations and collateral swaps. The loan turns a capital problem into a code problem.
Arbitrage. If WETH is cheaper on one pool than another, a bot can borrow USDC, buy WETH on the cheap pool, sell it on the expensive one, repay, and keep the difference. Uniswap's own V3 flash swap guide walks through exactly this between two fee tiers of the same pair. I've covered whether this still pays in is MEV bot arbitrage still profitable, and the short version is that the obvious routes are crowded.
Liquidations. To liquidate an unhealthy loan on a lending protocol, you repay part of the borrower's debt and receive their collateral at a discount. A flash loan provides the debt token, the bot sells some of the collateral to repay the loan, and it keeps the rest. That's the standard pattern in how liquidation bots work on Aave.
Collateral swaps. Some DeFi apps use flash loans behind the scenes to swap your collateral or move a position between protocols without unwinding it.
What the loan doesn't give you is speed. If your arbitrage only works when you're first, you're racing every other bot that sees the same price gap, and most of them can borrow the same free capital.
Flash loans vs Flashbots: what's the difference?
A flash loan is atomicity inside one transaction, while a Flashbots bundle is atomicity across several transactions in one block. People mix them up because both sound like "flash", but they solve different problems.
| Flash loan | Flashbots bundle | |
|---|---|---|
| What it is | A lending feature in a smart contract | A group of transactions sent privately to block builders |
| Scope | One transaction | One or more transactions, in a fixed order, in one block |
| Main job | Borrow capital you don't have | Control ordering and keep the tx out of the public mempool |
| Failure mode | Transaction reverts, you pay gas | Bundle simply isn't included, you usually pay nothing |
They work well together. A bot will often put a flash-loan-funded arbitrage transaction inside a bundle, so it doesn't leak to the public mempool and doesn't pay gas if it loses the race. If bundles are new to you, I wrote a full walkthrough in Flashbots bundles explained.
What is a flash loan attack?
A flash loan attack is an exploit where someone uses borrowed capital to push a bug or a weak assumption in a protocol far enough to drain it. The flash loan itself isn't the vulnerability. It just lets an attacker with little money act like someone with a lot of it, for one transaction.
Two cases worth knowing:
- Euler Finance, March 2023. The attacker flash-borrowed about $30 million DAI from Aave and abused a
donateToReservesfunction that skipped a solvency check. That created an insolvent position the attacker could liquidate from a second account at a discount. Losses were about $197 million, and the funds were later returned (CertiK, Chainalysis). - Beanstalk, April 2022. The attacker flash-borrowed enough to gain a supermajority of governance votes, then passed and executed a malicious proposal in the same transaction through
emergencyCommit. Around $182 million of protocol assets moved out (Immunefi analysis).
The lesson for builders is simple. Any check that relies on someone's balance, voting weight or a spot price inside one block can be gamed with borrowed money.
Is the YouTube "flash loan arbitrage bot" real?
No. The popular YouTube and TikTok "flash loan bot" tutorials are a known scam that gets you to deploy a contract and fund it, then sends your ETH to the scammer. The developer known as Jeiwan took a BSC version apart in Analysis of a technical smart contract scam, and academic researchers have measured the pattern at scale in Towards Understanding and Characterizing the Arbitrage Bot Scam In the Wild.
The tell is right there in the pitch. A real flash loan doesn't need your deposit, because the capital is borrowed. If a video tells you to send ETH to a contract "for gas" or "for liquidity" before it can start earning, stop. I covered the Remix version of this in detail in the YouTube MEV bot scam.
How do you test a flash loan contract safely?
Run it against a mainnet fork first, so you're borrowing real liquidity from real contracts without spending real money. Here's the process I follow:
- Fork mainnet locally with Anvil at a recent block.
- Deploy your receiver contract to the fork.
- Call your entry function and confirm the loan is taken, used and repaid.
- Check what happens when the trade is unprofitable. It should revert cleanly, not leave tokens stuck.
- Try calling your callback from a random address. It should revert.
- Only then simulate on mainnet with
eth_callBundleor a tool like Tenderly, and send through a private route.
I wrote up the fork setup in how to test an MEV bot on a mainnet fork with Anvil. Step 4 is the one people skip. They test the happy path and forget the case where the trade turns out to be a loss.
Frequently asked questions
Do you need collateral for a flash loan?
No. The loan has to be repaid within the same transaction, and if it isn't, the transaction reverts, so the lender never takes credit risk and asks for no collateral.
What happens if you can't repay a flash loan?
The whole transaction reverts and every transfer in it is undone, including the loan. You still pay gas for the failed transaction unless you sent it in a bundle that simply wasn't included.
How much does an Aave flash loan cost?
Aave V3 set the flash loan premium at 0.05% of the borrowed amount at deployment, and governance can change it. Read the current value from the Pool contract's FLASHLOAN_PREMIUM_TOTAL.
Are flash loans legal?
Flash loans are a standard feature built into protocols like Aave and Balancer, and using them for arbitrage or liquidations is normal DeFi activity. Using one to exploit a bug and take other people's funds is a different matter and has been treated as theft.
Can a beginner make money with flash loans?
Rarely, at least on obvious routes, because experienced bots compete for the same opportunities with the same free capital. The loan removes the need for money but not the need for an edge in finding or landing the trade.
Is a flash loan the same as Flashbots?
No. A flash loan borrows capital inside one transaction, while Flashbots is a way to send transactions privately to block builders as an ordered bundle. Bots often use both at once.
Related guides
- How to create a MEV bot: from mempool to first bundle
- Is MEV bot arbitrage still profitable in 2026?
- Liquidation bot development: Compound, Morpho and Spark
- MEV bot meaning: 60 terms every searcher should know
Flash loans are one of those tools that look like free money from the outside and turn out to be plumbing once you use them. If you want a strategy built around them, I take on custom MEV bot development at MEV DAO, and you can subscribe for more guides like this one.