Flash loans let you borrow millions of dollars with zero collateral, provided you repay everything within the same blockchain transaction. This guide explains the mechanism, the three legitimate use cases, and how the same technology has powered some of DeFi's largest exploits.
A flash loan lets you borrow any amount of capital available in a lending pool, up to and including tens of millions of dollars, without posting any collateral whatsoever, on the single condition that you repay the full amount plus a small fee before the transaction finishes executing. If you cannot repay, the entire transaction reverts as though it never happened, and the lender loses nothing. This is not possible in any traditional financial system. It is one of the genuinely novel financial primitives that blockchain technology has made possible, and understanding why it works is the key to understanding everything from DeFi arbitrage to some of the largest protocol exploits in crypto history.
The mechanism, stripped to its essentials: you write a smart contract that requests a loan from a protocol like Aave, receives the funds, performs whatever actions you have programmed, repays the loan plus a fee, and returns control to the lending protocol, all within a single blockchain transaction. The protocol checks at the very end of that transaction whether the loan has been repaid in full. If yes, the transaction is confirmed and recorded permanently on-chain. If no, for any reason, the entire transaction is rejected and reverted, including the original loan disbursement, as though none of it ever occurred.
There is no waiting period, no credit check, no collateral requirement, and no possibility of default in the traditional sense, because default simply causes the loan to have never happened at all from the blockchain's perspective. This is the core innovation, and it depends entirely on a property of blockchain transactions that does not exist anywhere in traditional finance.
Traditional financial transactions happen sequentially and irreversibly in practical terms. A bank that wires you $1,000,000 cannot simply undo that wire transfer instantly and costlessly if you fail to return the money five seconds later. The money has left the bank's control and entered a separate system, with real-world legal and operational friction involved in any attempt to reverse it.
Blockchain transactions work fundamentally differently because of a property called atomicity. A single transaction on Ethereum or a similar smart contract platform can contain multiple internal operations, in this case a loan disbursement, a series of actions using the borrowed funds, and a repayment, bundled together as one indivisible unit. The blockchain's execution rules guarantee that either every operation within that transaction succeeds, or none of them do. There is no possibility of the loan disbursement succeeding while the repayment fails, because the entire transaction is evaluated as a whole before any of its effects become permanent.
This is the specific technical property that makes flash loans possible. The lending protocol does not need to trust you, assess your creditworthiness, or hold collateral as security, because the blockchain itself guarantees, through atomicity, that the loan and its repayment either both happen or neither happens. There is no scenario, short of a bug in the smart contract code itself, where the lender ends up with less money than they started with.
The most commonly cited flash loan use case is capturing a price discrepancy for the same asset trading at different prices across two decentralized exchanges, without needing to have the capital to execute the trade sitting in your wallet beforehand.
The sequence: your smart contract requests a flash loan of USDC from Aave, uses that USDC to buy a token on DEX A where it is priced lower, immediately sells that same token on DEX B where it is priced higher, repays the USDC loan plus Aave's fee, and keeps the remaining difference as profit, all within one transaction. If at any point the sequence would not generate enough profit to repay the loan and fee, the transaction simply reverts, and you lose nothing beyond the gas cost of the attempted transaction.
This use case is covered in extensive practical detail, including the real economics of why it is rarely profitable for retail participants given gas costs and MEV bot competition, in our companion guide on flash loan arbitrage.
A less discussed but genuinely useful application is swapping the collateral backing an existing DeFi loan without needing to close that loan position first, a process that would otherwise require multiple separate transactions with timing risk between each step.
Consider a user with an open loan on Aave backed by ETH collateral, who wants to switch that collateral to wBTC instead, perhaps because they have become more bearish on ETH specifically while wanting to maintain their existing borrowed position. Without a flash loan, this requires repaying the existing loan in full first (requiring capital from somewhere else), withdrawing the ETH collateral, selling it for wBTC, depositing the wBTC as new collateral, and re-opening the loan, a sequence with multiple points where market movement between steps could leave the user under-collateralized or unable to complete the swap as intended.
A flash loan collapses this entire sequence into a single atomic transaction: borrow stablecoins via flash loan, use them to repay the existing Aave debt, withdraw the now-unencumbered ETH collateral, swap it for wBTC, deposit the wBTC as new collateral, borrow against it to repay the flash loan, all in one transaction that either completes entirely or reverts entirely, with no intermediate state where the position is exposed to market risk between steps.
When a DeFi loan position's collateral value falls close to the threshold that triggers liquidation, the borrower typically faces being liquidated by an external party, who claims a liquidation bonus, frequently 5 to 15% of the position value, as compensation for closing out the under-collateralized position.
A flash loan allows the borrower to liquidate their own position before an external liquidator does so, avoiding that penalty entirely. The sequence: borrow the debt asset via flash loan, use it to repay your own existing debt position in full, withdraw your collateral now that the position is closed, sell enough of that collateral to repay the flash loan, and keep the remainder, all within one transaction, executed proactively rather than waiting for an external liquidator to claim the bonus that would otherwise go to them.
This use case specifically rewards borrowers who actively monitor their position's health factor and are willing to act before an external liquidation bot does, turning what would otherwise be a penalty into a managed, lower-cost exit from an at-risk position.
The same atomicity that makes flash loans useful for legitimate purposes has also made them the tool of choice for a specific, recurring category of DeFi exploit: oracle manipulation attacks.
Many DeFi protocols rely on a price oracle, frequently derived from the current state of a specific liquidity pool, to determine the value of collateral or to calculate exchange rates for various operations. A flash loan allows an attacker to temporarily borrow an enormous amount of capital, use it to dramatically and artificially move the price within a specific pool that a vulnerable protocol uses as its price reference, execute an action that the protocol incorrectly prices based on this manipulated, temporary price, and then repay the flash loan, all within the same transaction, before the artificially moved price has any opportunity to be arbitraged back to its correct level by anyone else.
This pattern has been the underlying mechanism behind several of the largest DeFi exploits in history. The attacker does not need to actually own the enormous capital required to move a pool's price meaningfully, they only need to borrow it momentarily through a flash loan, which means the barrier to attempting this kind of attack is dramatically lower than it would be if the attacker needed to genuinely hold that much capital themselves. The defense, increasingly standard across well-audited protocols, is using time-weighted average price oracles or external, manipulation-resistant price feeds (such as Chainlink) rather than relying on the instantaneous, single-block price of a liquidity pool that a flash loan can temporarily distort.
This is the specific technical reason that flash loans carry a reputation for danger in DeFi security discussions, despite the legitimate use cases described above being entirely benign. The risk is not inherent to flash loans themselves, but to the protocols that have failed to design their price oracle dependencies to be resistant to the kind of temporary, capital-intensive price manipulation that flash loans uniquely enable.
Executing a flash loan requires writing and deploying a smart contract containing the specific sequence of operations you want to perform within the loan's lifetime, meaning direct flash loan usage has historically been the domain of developers with Solidity or equivalent smart contract programming knowledge, not something accessible through a simple wallet interface in the way a standard token swap is.
This has begun to change with the emergence of front-end tools and no-code platforms that abstract the contract-writing process behind a simplified interface, allowing non-developers to configure common flash loan patterns, particularly arbitrage and collateral swaps, without writing code directly. These tools typically charge an additional service fee on top of the underlying protocol's flash loan fee, and the economics of using them for arbitrage specifically are covered in detail in our flash loan arbitrage guide, where the honest conclusion is that the combined costs frequently make retail flash loan arbitrage uneconomical regardless of whether the execution is done through custom code or a simplified front-end.
For the collateral swap and self-liquidation use cases specifically, several DeFi interfaces, including some built directly into protocols like Aave's own front-end for certain supported actions, have begun offering these as one-click features that use flash loans internally without requiring the end user to understand or interact with the underlying mechanism directly.
Aave charges a flat 0.09% fee on the borrowed amount for any flash loan, regardless of the asset or the duration (which is always a single transaction, so duration is not actually a variable in the traditional sense). Aave's flash loan functionality is the most widely used and most extensively integrated into third-party tooling, given the protocol's deep liquidity across a wide range of supported assets.
Balancer offers flash loans with no fee at all, the borrower pays only the gas cost of the transaction itself, with no additional percentage charge from the protocol. This makes Balancer the cheapest option specifically when its available liquidity for your required asset is sufficient for your intended transaction size, an important caveat since Balancer's total liquidity for any specific asset may be smaller than Aave's for the same token.
Uniswap v3, through its flash swap functionality (a closely related but technically distinct mechanism that allows borrowing directly from a liquidity pool with the same atomic repayment requirement), charges a fee equivalent to the pool's standard trading fee tier, commonly 0.05%, 0.3%, or 1% depending on which fee tier pool you are borrowing from, making it competitive with Aave for assets where Uniswap has the deepest available liquidity.
The practical choice between these platforms depends primarily on which one has sufficient liquidity in your specific required asset for your intended loan size, with the fee differential between Aave and Balancer specifically (0.09% versus 0%) becoming meaningful primarily at larger loan sizes, where even a fraction of a percent represents a non-trivial absolute cost.
Is flash loan arbitrage legal?
Yes, in essentially every jurisdiction that has addressed the question. Flash loan arbitrage is fundamentally the same activity as any other arbitrage, buying an asset where it is priced lower and selling where it is priced higher, executed using a specific blockchain mechanism rather than traditional capital. It does not involve manipulating other users' transactions or exploiting protocol vulnerabilities, which distinguishes it clearly from the oracle manipulation attacks described above.
Can I lose money on a flash loan?
Not from the loan itself, in the sense that you can never owe more than you borrowed and fail to repay, because the entire transaction reverts if repayment is not achieved. You can, however, lose the gas fee for a transaction that fails to execute profitably, meaning the cost of a failed flash loan attempt is limited to the gas spent attempting it, not the loan amount itself.
Do I need to be a programmer to use flash loans?
For custom flash loan logic, yes, you need to write and deploy a smart contract containing your intended sequence of operations. For common, pre-built use cases like collateral swaps on platforms that have integrated this functionality into their standard interface, no programming knowledge is required, since the protocol's front-end handles the underlying contract interaction on your behalf.
Why are flash loans associated with DeFi hacks?
Flash loans have been the enabling mechanism in numerous oracle manipulation exploits, where an attacker borrows a large amount of capital momentarily to artificially distort a price that a vulnerable protocol relies on, executes a profitable action based on that distorted price, and repays the loan, all within one transaction. The flash loan itself is not malicious, it is simply the tool that makes acquiring the large amount of capital needed to manipulate a price economically feasible without the attacker needing to genuinely own that capital.
What is the difference between a flash loan and a flash swap?
A flash loan, in Aave's implementation, lets you borrow any supported asset from the protocol's lending pool with the standard atomic repayment requirement. A flash swap, Uniswap's related mechanism, lets you borrow directly from a specific liquidity pool with the same atomic repayment guarantee, but the borrowed asset and the mechanics are tied specifically to that pool's available liquidity and fee structure, rather than a separate, dedicated lending pool.
Explore flash loan opportunities and execution: OKX โ track and act on arbitrage opportunities flash loans help surface ยท deBridge โ cross-chain access to the deepest liquidity for any flash loan execution