Flash Loans Explained!

Rahul Ravindran


Decentralised finance on Ethereum has created a new monetary paradigm. Ethereum’s smart contract architecture has laid the grounds for a near-limitless open system, giving rise to groundbreaking innovations unlike anything that exists in the traditional finance world.

Among the most frequently discussed innovations in the space today are flash loans. In some ways flash loans are not unlike their more common predecessors found in the regular world: a user borrows funds under the proviso that they pay it back. Unlike a regular loan, though, there’s no limit to the amount the user can borrow, and it can be taken out instantly, as long as it’s paid back in the same transaction — at a flash speed.

This is made possible by smart contracts. They’re programmed to ensure that the loan is returned, otherwise the transaction gets blocked. The revolutionary part is how quickly it all happens, and the borrower only needs to shell out for a transaction fee to pay for the whole process. That means that they can potentially borrow huge sums of money at a marginal cost thanks to the power of the blockchain.

Loans in traditional finance

To understand more about flash loans, let’s explore how loans work in traditional finance. There are two common types of loan most people are used to: unsecured and secured.

An unsecured loan is one where the borrower doesn’t need to provide any collateral. While this can benefit the borrower, usually they are required to pay back interest on top of the loan.

A secured loan is a little different: the lender asks the borrower to provide a form of security in case they can’t pay back the loan. This case usually applies to bigger sums of money.

While conventional loans have been a bedrock of the traditional finance system, they aren’t always easy for people to get hold of. This is part of what could make loans in DeFi so disruptive.

Use cases for flash loans

Smart contracts ensure that flash loans are always paid back in the same transaction. Wondering how this benefits the borrower? Well, the composability of DeFi means that with careful planning, the loan can still be used to the borrower’s advantage and paid back before the transaction completes. That’s to say, there are ways of interacting with multiple smart contracts to use the loan and walk away with a profit. And because there’s no limit to the amount of funds the user can borrow, those profits can be incredibly lucrative.

Perhaps the most common method of using flash loans for profit is through arbitrage. This is a process that takes advantage of an asset’s price difference in two different markets. Imagine that the borrower finds Z tokens on DEX A listed for $1, and the price of Z is $1.10 on DEX B. They could use the loan to buy up the cheap tokens on DEX A, then sell them on DEX B at a profit. Once they’ve paid back the loan at the end of the transaction, they still get to keep the extra sum for themselves.

Another method of profit-making is through wash trading. This involves executing buys and sells of an asset in order to increase the trading volume. The procedure is forbidden in traditional markets. Using wash trading in DeFi, the borrower could take out a flash loan of Y tokens on DEX A, then execute two trades swapping Y for Z and back again on DEX B. This increases the trading volume for Y, creating an artificial level of interest and opportunity for profit.

Flash loan borrowers can also benefit from collateral swapping. This is a process in which a collateral position can be replaced with a borrowed asset even if the borrower is unable to return the funds. If the borrower is providing collateral to DEX A using token Y, but then they start to notice Y’s price dropping, they could take out a flash loan for Z and swap the collateral to avoid a liquidation.


Arbitrage refers to an immediate trade of an asset in different markets to make a profit from tiny differences in the asset’s listed price. Traders tend to move between various crypto exchanges in search of little differences in the prices of various crypto assets.

For instance, imagine BTC/USDT is trading on Binance at $39,131.26, while the same BTC/USDT is trading on Bitfinex at $39,120.00. That’s an $11.26 difference. A trader can buy BTC on Bitfinex and sell on Binance to make a profit of $11.26 per BTC sold. This example uses centralized crypto exchanges, however, the same applies to decentralized exchanges (DEx) like dYdX, UniSwap, PanCakeSwap etc. Flash loans are used to take advantage of a price arbitrage on DExs, this is because of their instant nature and their applicability across the blockchain.

Source: Finematics via Youtube

Here is an example of a person exploiting the price arbitrage on Curve and UniSwap.

Here the DAI/USDC is trading on Curve at $1, while DAI/USDC is trading on UniSwap at $0.99.

A trader can exploit this opportunity using a flash loan by doing the following (as shown above):

  1. Take a flash loan of 100,000 DAI from Aave
  2. Swap the 100,000 DAI for 101,010 USDC on UniSwap
  3. Swap the 101,010 USDC for 101,010 DAI on Curve
  4. Repay the 100,000 DAI borrowed plus 0.09% fee to make a total of 100,900 DAI to Aave
  5. Keep the 110 DAI as profit.

Collateral Swap

This involves a quick swap of the collateral used to back a user’s loan from one asset to another.

This helps DeFi users swap the collateral they initially provided on a DeFi lending platform.

Source: Finematics via Youtube

In this example, a person used their ETH as collateral for a loan taken in DAI on the Compound lending platform and they want to swap the ETH for BAT.

A user can swap the ETH for BAT using a flash loan by doing the following (as shown above):

  1. Take a flash loan in DAI from Aave
  2. Use the DAI to repay the loan on Compound
  3. Retrieve your ETH used as collateral
  4. Swap ETH for BAT on UniSwap
  5. Deposit BAT as collateral to take a loan in DAI on Compound
  6. Repay the loan in DAI plus 0.09% fee to Aave


In DeFi, there are liquidation penalties or fees for loans, it currently ranges around 3% to 15% depending on the platform.

DeFi liquidation occurs when the price of the asset used as collateral falls below a certain pre-determined point. This is usually to prevent a situation whereby the value of the collateral is too low to cover the loan borrowed.

In a situation where the value of the collateral reaches the liquidation point, the smart contract sells the crypto asset to cover the debt. The user loses the asset and is charged the fee.

DeFi users can use flash loans to self-liquidate to repay the loan and recover the asset used as collateral to avoid getting liquidated and paying the fee.

Source: Finematics via Youtube

In this example, the user took a loan in DAI with ETH as collateral from Compound. The price of ETH is decreasing and is approaching the level of liquidation, the a take a flash loan to avoid getting liquidated by the smart contract by doing the following:

  1. Take a loan in DAI from Aave
  2. Use the DAI to repay the loan on Compound
  3. Retrieve your ETH used as collateral
  4. Swap ETH for DAI on UniSwap
  5. Repay the loan in DAI plus 0.09% fee to Aave

These are the most common use case of flash loans and there are more that are yet to be discovered. These use cases should how useful flash loans are in DeFi. However, flash loans are often subject to attack. These are called Flash Loan Attacks.

This occurs when a borrower is able to trick the lender into thinking that the loan has been repaid even when it has not. DeFi systems are beginning to develop methods and technology to protect against these attacks.


Leave a Reply

More great articles

An Introduction to Celo Blockchain

Introducing Celo’s Technology Celo is a blockchain ecosystem focused on increasing cryptocurrency adoption among smartphone users. By using phone numbers…

Read Story

How much blockchain developers REALLY make?

According to Hired, blockchain developers can command salaries between 140,000 USD to 180,000 USD. Sounds amazing, right? But is it…

Read Story

Ultimate Solidity Interview Questions 2022

What are primitive data types in Solidity? Primitive data types in solidity are: - boolean - uint - int -…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]